diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2003-04-22 23:13:27 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2003-04-22 23:13:27 (GMT) |
commit | a69d409f05612b354beb7efa3d4219e5728cb9ef (patch) | |
tree | b52d532e86c4c9baa2a7100762cee3370152ebb6 /Modules/_bsddb.c | |
parent | 2b4b5a54d6138e1d8be56b83574a16146306e630 (diff) | |
download | cpython-a69d409f05612b354beb7efa3d4219e5728cb9ef.zip cpython-a69d409f05612b354beb7efa3d4219e5728cb9ef.tar.gz cpython-a69d409f05612b354beb7efa3d4219e5728cb9ef.tar.bz2 |
Update to the new PyGILState APIs to simplify and correct thread-state
management. Old code still #ifdef'd out - I may remove this in a sec,
but for now, let's get it in and things passing the tests again!
Diffstat (limited to 'Modules/_bsddb.c')
-rw-r--r-- | Modules/_bsddb.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index 9438d97..2f4cfa5 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -95,7 +95,19 @@ static char *rcs_id = "$Id$"; #define MYDB_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS; #define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS; +/* For 2.3, use the PyGILState_ calls */ +#if (PY_VERSION_HEX >= 0x02030000) +#define MYDB_USE_GILSTATE +#endif + /* and these are for calling C --> Python */ +#if defined(MYDB_USE_GILSTATE) +#define MYDB_BEGIN_BLOCK_THREADS \ + PyGILState_STATE __savestate = PyGILState_Ensure(); +#define MYDB_END_BLOCK_THREADS \ + PyGILState_Release(__savestate); +#else /* MYDB_USE_GILSTATE */ +/* Pre GILState API - do it the long old way */ static PyInterpreterState* _db_interpreterState = NULL; #define MYDB_BEGIN_BLOCK_THREADS { \ PyThreadState* prevState; \ @@ -110,9 +122,10 @@ static PyInterpreterState* _db_interpreterState = NULL; PyEval_ReleaseLock(); \ PyThreadState_Delete(newState); \ } +#endif /* MYDB_USE_GILSTATE */ #else - +/* Compiled without threads - avoid all this cruft */ #define MYDB_BEGIN_ALLOW_THREADS #define MYDB_END_ALLOW_THREADS #define MYDB_BEGIN_BLOCK_THREADS @@ -4249,7 +4262,7 @@ DL_EXPORT(void) init_bsddb(void) DBLock_Type.ob_type = &PyType_Type; -#ifdef WITH_THREAD +#if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE) /* Save the current interpreter, so callbacks can do the right thing. */ _db_interpreterState = PyThreadState_Get()->interp; #endif |