@@ -29,14 +29,48 @@ index 38bf3d5..9954f3b 100644
29
29
30
30
static PyObject *_cpyextfunc_type(LibObject *lib, struct CPyExtFunc_s *exf)
31
31
diff --git a/c/misc_thread_common.h b/c/misc_thread_common.h
32
- index 66e2835..bc32b1b 100644
32
+ index 66e2835..b48fd85 100644
33
33
--- a/c/misc_thread_common.h
34
34
+++ b/c/misc_thread_common.h
35
- @@ -329,6 +329,7 @@ static PyThreadState *get_current_ts(void)
35
+ @@ -329,40 +329,7 @@ static PyThreadState *get_current_ts(void)
36
36
37
37
static PyGILState_STATE gil_ensure(void)
38
38
{
39
+ - /* Called at the start of a callback. Replacement for
40
+ - PyGILState_Ensure().
41
+ - */
42
+ - PyGILState_STATE result;
43
+ - PyThreadState *ts = PyGILState_GetThisThreadState();
44
+ -
45
+ - if (ts != NULL) {
46
+ - ts->gilstate_counter++;
47
+ - if (ts != get_current_ts()) {
48
+ - /* common case: 'ts' is our non-current thread state and
49
+ - we have to make it current and acquire the GIL */
50
+ - PyEval_RestoreThread(ts);
51
+ - return PyGILState_UNLOCKED;
52
+ - }
53
+ - else {
54
+ - return PyGILState_LOCKED;
55
+ - }
56
+ - }
57
+ - else {
58
+ - /* no thread state here so far. */
59
+ - result = PyGILState_Ensure();
60
+ - assert(result == PyGILState_UNLOCKED);
61
+ -
62
+ - ts = PyGILState_GetThisThreadState();
63
+ - assert(ts != NULL);
64
+ - assert(ts == get_current_ts());
65
+ - assert(ts->gilstate_counter >= 1);
66
+ -
67
+ - /* Use the ThreadCanary mechanism to keep 'ts' alive until the
68
+ - thread really shuts down */
69
+ - thread_canary_register(ts);
70
+ -
71
+ - return result;
72
+ - }
39
73
+ return PyGILState_Ensure();
40
- /* Called at the start of a callback. Replacement for
41
- PyGILState_Ensure().
42
- */
74
+ }
75
+
76
+ static void gil_release(PyGILState_STATE oldstate)
0 commit comments