diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2006-10-24 20:28:16 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2006-10-24 20:28:16 +0000 |
commit | 54db0825da704d121264647798fdd829a3ade6e2 (patch) | |
tree | 6b8a35f79a855041cdf8c3b57156a566516d149d /libvirt_wrap.h | |
parent | 6606a75667802eaf7d956fb6a61ffaeaece9385d (diff) | |
download | libvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.tar.gz libvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.tar.xz libvirt-python-v6-54db0825da704d121264647798fdd829a3ade6e2.zip |
Make python bindings threaded, by dropping/acquiring Python GIL where needed
Diffstat (limited to 'libvirt_wrap.h')
-rw-r--r-- | libvirt_wrap.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libvirt_wrap.h b/libvirt_wrap.h index e745215..906245a 100644 --- a/libvirt_wrap.h +++ b/libvirt_wrap.h @@ -48,3 +48,53 @@ PyObject * libvirt_charPtrConstWrap(const char *str); PyObject * libvirt_virConnectPtrWrap(virConnectPtr node); PyObject * libvirt_virDomainPtrWrap(virDomainPtr node); + +/* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl): + * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END; + * can be used as a single statement, as in + * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ... + * + * When GCC is compiling C code in non-ANSI mode, it will use the + * compiler __extension__ to wrap the statements wihin `({' and '})' braces. + * When compiling on platforms where configure has defined + * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'. + * For any other platforms (SunOS4 is known to have this issue), wrap the + * statements with `if (1)' and `else (void) 0'. + */ +#if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END)) +# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) +# define LIBVIRT_STMT_START (void) __extension__ ( +# define LIBVIRT_STMT_END ) +# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ +# if defined (HAVE_DOWHILE_MACROS) +# define LIBVIRT_STMT_START do +# define LIBVIRT_STMT_END while (0) +# else /* !HAVE_DOWHILE_MACROS */ +# define LIBVIRT_STMT_START if (1) +# define LIBVIRT_STMT_END else (void) 0 +# endif /* !HAVE_DOWHILE_MACROS */ +# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */ +#endif + +#define LIBVIRT_BEGIN_ALLOW_THREADS \ + LIBVIRT_STMT_START { \ + PyThreadState *_save = NULL; \ + if (PyEval_ThreadsInitialized()) \ + _save = PyEval_SaveThread(); + +#define LIBVIRT_END_ALLOW_THREADS \ + if (PyEval_ThreadsInitialized()) \ + PyEval_RestoreThread(_save); \ + } LIBVIRT_STMT_END + +#define LIBVIRT_ENSURE_THREAD_STATE \ + LIBVIRT_STMT_START { \ + PyGILState_STATE _save; \ + if (PyEval_ThreadsInitialized()) \ + _save = PyGILState_Ensure(); + +#define LIBVIRT_RELEASE_THREAD_STATE \ + if (PyEval_ThreadsInitialized()) \ + PyGILState_Release(_save); \ + } LIBVIRT_STMT_END + |