Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a69d409

Browse files
committed
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!
1 parent 2b4b5a5 commit a69d409

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Modules/_bsddb.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,19 @@ static char *rcs_id = "$Id$";
9595
#define MYDB_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS;
9696
#define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS;
9797

98+
/* For 2.3, use the PyGILState_ calls */
99+
#if (PY_VERSION_HEX >= 0x02030000)
100+
#define MYDB_USE_GILSTATE
101+
#endif
102+
98103
/* and these are for calling C --> Python */
104+
#if defined(MYDB_USE_GILSTATE)
105+
#define MYDB_BEGIN_BLOCK_THREADS \
106+
PyGILState_STATE __savestate = PyGILState_Ensure();
107+
#define MYDB_END_BLOCK_THREADS \
108+
PyGILState_Release(__savestate);
109+
#else /* MYDB_USE_GILSTATE */
110+
/* Pre GILState API - do it the long old way */
99111
static PyInterpreterState* _db_interpreterState = NULL;
100112
#define MYDB_BEGIN_BLOCK_THREADS { \
101113
PyThreadState* prevState; \
@@ -110,9 +122,10 @@ static PyInterpreterState* _db_interpreterState = NULL;
110122
PyEval_ReleaseLock(); \
111123
PyThreadState_Delete(newState); \
112124
}
125+
#endif /* MYDB_USE_GILSTATE */
113126

114127
#else
115-
128+
/* Compiled without threads - avoid all this cruft */
116129
#define MYDB_BEGIN_ALLOW_THREADS
117130
#define MYDB_END_ALLOW_THREADS
118131
#define MYDB_BEGIN_BLOCK_THREADS
@@ -4249,7 +4262,7 @@ DL_EXPORT(void) init_bsddb(void)
42494262
DBLock_Type.ob_type = &PyType_Type;
42504263

42514264

4252-
#ifdef WITH_THREAD
4265+
#if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)
42534266
/* Save the current interpreter, so callbacks can do the right thing. */
42544267
_db_interpreterState = PyThreadState_Get()->interp;
42554268
#endif

0 commit comments

Comments
 (0)