diff options
author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2014-10-24 10:35:10 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2014-10-24 10:35:10 +0200 |
commit | 19e3db276722a14204bf0b7f8253bccff376485d (patch) | |
tree | ee3119e743e01fcb4331cc96385df5f3d93bf323 /src/uca-camera.c | |
parent | 7cbc8b3a10e3cfd67b3bc4102c6b8fb95dc06f29 (diff) | |
parent | 0ff04d9b7764b9fcca58eed7cd8788f67fa143b9 (diff) | |
download | uca-19e3db276722a14204bf0b7f8253bccff376485d.tar.gz uca-19e3db276722a14204bf0b7f8253bccff376485d.tar.bz2 uca-19e3db276722a14204bf0b7f8253bccff376485d.tar.xz uca-19e3db276722a14204bf0b7f8253bccff376485d.zip |
Merge pull request #60 from ufo-kit/release-gil
Release GIL
Diffstat (limited to 'src/uca-camera.c')
-rw-r--r-- | src/uca-camera.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/uca-camera.c b/src/uca-camera.c index ef5f671..bd9c437 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -23,9 +23,14 @@ * UcaCamera is the base camera from which a real hardware camera derives from. */ +#include "config.h" + +#ifdef WITH_PYTHON_MULTITHREADING +#include <Python.h> +#endif + #include <glib.h> #include <string.h> -#include "config.h" #include "compat.h" #include "uca-camera.h" #include "uca-ring-buffer.h" @@ -579,6 +584,12 @@ uca_camera_init (UcaCamera *camera) uca_camera_set_property_unit (camera_properties[PROP_ROI_WIDTH_MULTIPLIER], UCA_UNIT_COUNT); uca_camera_set_property_unit (camera_properties[PROP_ROI_HEIGHT_MULTIPLIER], UCA_UNIT_COUNT); uca_camera_set_property_unit (camera_properties[PROP_RECORDED_FRAMES], UCA_UNIT_COUNT); + +#ifdef WITH_PYTHON_MULTITHREADING + if (!PyEval_ThreadsInitialized ()) { + PyEval_InitThreads (); + } +#endif } static gpointer @@ -937,7 +948,21 @@ uca_camera_grab (UcaCamera *camera, gpointer data, GError **error) } else { g_static_mutex_lock (&access_lock); + +#ifdef WITH_PYTHON_MULTITHREADING + if (Py_IsInitialized ()) { + PyGILState_STATE state = PyGILState_Ensure (); + Py_BEGIN_ALLOW_THREADS + + result = (*klass->grab) (camera, data, error); + + Py_END_ALLOW_THREADS + PyGILState_Release (state); + } +#else result = (*klass->grab) (camera, data, error); +#endif + g_static_mutex_unlock (&access_lock); } |