enable multithreading
authorPatrick Ohly <patrick.ohly@intel.com>
Fri, 19 Sep 2014 08:45:57 +0000 (10:45 +0200)
committerPatrick Ohly <patrick.ohly@intel.com>
Fri, 19 Sep 2014 08:45:57 +0000 (10:45 +0200)
commitc62e2cb4558f1720f07dda085397d16d2c47f9e0
tree5d540e2bfffbe4243a53c449d365a886361af576
parent9d7c10b0d914ab94ac363bd919b265c2e1880663
enable multithreading

Python is single-threaded by default and crashes (when using an
unitialized semaphore) respectively blocks (when the main thread still
holds the Python global interpreter lock when it is outside the
pycrosswalk extension).

To avoid this, pycrosswalk must initialize multithreading and be more
careful about entering/leaving methods using Python.

The thread in which XW_Initialize() gets called becomes the main thread.
It must release the global lock when returning to Crosswalk and restore
it when called again. Otherwise Python code called by other threads cannot
run. The assumption is that Crosswalk will always call the extension from
the same thread.

Without this thread support, pycloudeebus in xwalk-launcher does not work:
the main thread is running the glib event loop in which twisted reacts
to D-Bus calls, while the second thread runs a Crosswalk event loop and
would hold the Python lock if we didn't release it.
src/pycrosswalk.c