annotate Python/ceval_gil.h @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 978326f98316
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1 /*
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
2 * Implementation of the Global Interpreter Lock (GIL).
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
3 */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
4
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5 #include <stdlib.h>
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
6 #include <errno.h>
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
7
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
8
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 /* First some general settings */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11 /* microseconds (the Python API uses seconds, though) */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12 #define DEFAULT_INTERVAL 5000
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13 static unsigned long gil_interval = DEFAULT_INTERVAL;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
14 #define INTERVAL (gil_interval >= 1 ? gil_interval : 1)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
15
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
16 /* Enable if you want to force the switching of threads at least every `gil_interval` */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
17 #undef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 #define FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
19
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
20
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
21 /*
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
22 Notes about the implementation:
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
23
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
24 - The GIL is just a boolean variable (gil_locked) whose access is protected
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
25 by a mutex (gil_mutex), and whose changes are signalled by a condition
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
26 variable (gil_cond). gil_mutex is taken for short periods of time,
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
27 and therefore mostly uncontended.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
28
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
29 - In the GIL-holding thread, the main loop (PyEval_EvalFrameEx) must be
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
30 able to release the GIL on demand by another thread. A volatile boolean
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
31 variable (gil_drop_request) is used for that purpose, which is checked
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
32 at every turn of the eval loop. That variable is set after a wait of
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
33 `interval` microseconds on `gil_cond` has timed out.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
34
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35 [Actually, another volatile boolean variable (eval_breaker) is used
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36 which ORs several conditions into one. Volatile booleans are
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
37 sufficient as inter-thread signalling means since Python is run
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 on cache-coherent architectures only.]
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 - A thread wanting to take the GIL will first let pass a given amount of
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
41 time (`interval` microseconds) before setting gil_drop_request. This
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
42 encourages a defined switching period, but doesn't enforce it since
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
43 opcodes can take an arbitrary time to execute.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
44
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 The `interval` value is available for the user to read and modify
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
46 using the Python API `sys.{get,set}switchinterval()`.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
47
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
48 - When a thread releases the GIL and gil_drop_request is set, that thread
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
49 ensures that another GIL-awaiting thread gets scheduled.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
50 It does so by waiting on a condition variable (switch_cond) until
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
51 the value of gil_last_holder is changed to something else than its
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
52 own thread state pointer, indicating that another thread was able to
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
53 take the GIL.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
54
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
55 This is meant to prohibit the latency-adverse behaviour on multi-core
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
56 machines where one thread would speculatively release the GIL, but still
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
57 run and end up being the first to re-acquire it, making the "timeslices"
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
58 much longer than expected.
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
59 (Note: this mechanism is enabled with FORCE_SWITCHING above)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
60 */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
61
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
62 #include "condvar.h"
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
63 #ifndef Py_HAVE_CONDVAR
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
64 #error You need either a POSIX-compatible or a Windows system!
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
65 #endif
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
66
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
67 #define MUTEX_T PyMUTEX_T
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
68 #define MUTEX_INIT(mut) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
69 if (PyMUTEX_INIT(&(mut))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
70 Py_FatalError("PyMUTEX_INIT(" #mut ") failed"); };
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
71 #define MUTEX_FINI(mut) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
72 if (PyMUTEX_FINI(&(mut))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
73 Py_FatalError("PyMUTEX_FINI(" #mut ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
74 #define MUTEX_LOCK(mut) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
75 if (PyMUTEX_LOCK(&(mut))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
76 Py_FatalError("PyMUTEX_LOCK(" #mut ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77 #define MUTEX_UNLOCK(mut) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
78 if (PyMUTEX_UNLOCK(&(mut))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
79 Py_FatalError("PyMUTEX_UNLOCK(" #mut ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
80
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
81 #define COND_T PyCOND_T
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
82 #define COND_INIT(cond) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
83 if (PyCOND_INIT(&(cond))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
84 Py_FatalError("PyCOND_INIT(" #cond ") failed"); };
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
85 #define COND_FINI(cond) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
86 if (PyCOND_FINI(&(cond))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
87 Py_FatalError("PyCOND_FINI(" #cond ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88 #define COND_SIGNAL(cond) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
89 if (PyCOND_SIGNAL(&(cond))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
90 Py_FatalError("PyCOND_SIGNAL(" #cond ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
91 #define COND_WAIT(cond, mut) \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
92 if (PyCOND_WAIT(&(cond), &(mut))) { \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
93 Py_FatalError("PyCOND_WAIT(" #cond ") failed"); };
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
94 #define COND_TIMED_WAIT(cond, mut, microseconds, timeout_result) \
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
95 { \
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
96 int r = PyCOND_TIMEDWAIT(&(cond), &(mut), (microseconds)); \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
97 if (r < 0) \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
98 Py_FatalError("PyCOND_WAIT(" #cond ") failed"); \
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
99 if (r) /* 1 == timeout, 2 == impl. can't say, so assume timeout */ \
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
100 timeout_result = 1; \
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
101 else \
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
102 timeout_result = 0; \
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
103 } \
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
104
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
105
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
106
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
107 /* Whether the GIL is already taken (-1 if uninitialized). This is atomic
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
108 because it can be read without any lock taken in ceval.c. */
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
109 static _Py_atomic_int gil_locked = {-1};
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
110 /* Number of GIL switches since the beginning. */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
111 static unsigned long gil_switch_number = 0;
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
112 /* Last PyThreadState holding / having held the GIL. This helps us know
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
113 whether anyone else was scheduled after we dropped the GIL. */
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
114 static _Py_atomic_address gil_last_holder = {NULL};
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
115
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
116 /* This condition variable allows one or several threads to wait until
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
117 the GIL is released. In addition, the mutex also protects the above
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
118 variables. */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
119 static COND_T gil_cond;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
120 static MUTEX_T gil_mutex;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
122 #ifdef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
123 /* This condition variable helps the GIL-releasing thread wait for
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
124 a GIL-awaiting thread to be scheduled and take the GIL. */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 static COND_T switch_cond;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
126 static MUTEX_T switch_mutex;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
127 #endif
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
129
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
130 static int gil_created(void)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
131 {
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
132 return _Py_atomic_load_explicit(&gil_locked, _Py_memory_order_acquire) >= 0;
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
133 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
135 static void create_gil(void)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
136 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
137 MUTEX_INIT(gil_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
138 #ifdef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
139 MUTEX_INIT(switch_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
140 #endif
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
141 COND_INIT(gil_cond);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
142 #ifdef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
143 COND_INIT(switch_cond);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
144 #endif
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
145 _Py_atomic_store_relaxed(&gil_last_holder, NULL);
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
146 _Py_ANNOTATE_RWLOCK_CREATE(&gil_locked);
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
147 _Py_atomic_store_explicit(&gil_locked, 0, _Py_memory_order_release);
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
148 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
150 static void destroy_gil(void)
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
151 {
77365
6d146e2ae9a9 Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 67603
diff changeset
152 /* some pthread-like implementations tie the mutex to the cond
6d146e2ae9a9 Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 67603
diff changeset
153 * and must have the cond destroyed first.
6d146e2ae9a9 Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 67603
diff changeset
154 */
6d146e2ae9a9 Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 67603
diff changeset
155 COND_FINI(gil_cond);
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
156 MUTEX_FINI(gil_mutex);
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
157 #ifdef FORCE_SWITCHING
77365
6d146e2ae9a9 Signal condition variables with the mutex held. Destroy condition variables
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 67603
diff changeset
158 COND_FINI(switch_cond);
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
159 MUTEX_FINI(switch_mutex);
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
160 #endif
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
161 _Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release);
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
162 _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked);
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
163 }
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
164
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
165 static void recreate_gil(void)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
166 {
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
167 _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked);
64709
557e2537c9ae Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
Antoine Pitrou <solipsis@pitrou.net>
parents: 63911
diff changeset
168 /* XXX should we destroy the old OS resources here? */
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
169 create_gil();
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
170 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
171
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
172 static void drop_gil(PyThreadState *tstate)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
173 {
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
174 if (!_Py_atomic_load_relaxed(&gil_locked))
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
175 Py_FatalError("drop_gil: GIL is not locked");
67603
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
176 /* tstate is allowed to be NULL (early interpreter init) */
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
177 if (tstate != NULL) {
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
178 /* Sub-interpreter support: threads might have been switched
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
179 under our feet using PyThreadState_Swap(). Fix the GIL last
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
180 holder variable so that our heuristics work. */
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
181 _Py_atomic_store_relaxed(&gil_last_holder, tstate);
2930393f0bbb Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64709
diff changeset
182 }
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
183
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
184 MUTEX_LOCK(gil_mutex);
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
185 _Py_ANNOTATE_RWLOCK_RELEASED(&gil_locked, /*is_write=*/1);
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
186 _Py_atomic_store_relaxed(&gil_locked, 0);
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
187 COND_SIGNAL(gil_cond);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
188 MUTEX_UNLOCK(gil_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
189
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
190 #ifdef FORCE_SWITCHING
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
191 if (_Py_atomic_load_relaxed(&gil_drop_request) && tstate != NULL) {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
192 MUTEX_LOCK(switch_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
193 /* Not switched yet => wait */
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
194 if (_Py_atomic_load_relaxed(&gil_last_holder) == tstate) {
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
195 RESET_GIL_DROP_REQUEST();
57191
c717fe993085 Our condition variable emulation under Windows is imperfect, which
Antoine Pitrou <solipsis@pitrou.net>
parents: 57175
diff changeset
196 /* NOTE: if COND_WAIT does not atomically start waiting when
c717fe993085 Our condition variable emulation under Windows is imperfect, which
Antoine Pitrou <solipsis@pitrou.net>
parents: 57175
diff changeset
197 releasing the mutex, another thread can run through, take
c717fe993085 Our condition variable emulation under Windows is imperfect, which
Antoine Pitrou <solipsis@pitrou.net>
parents: 57175
diff changeset
198 the GIL and drop it again, and reset the condition
57203
f9a50cede6a9 Try to strengthen condition-waiting under Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 57191
diff changeset
199 before we even had a chance to wait for it. */
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
200 COND_WAIT(switch_cond, switch_mutex);
77513
978326f98316 Issue #15038: Optimize python Locks on Windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 77365
diff changeset
201 }
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
202 MUTEX_UNLOCK(switch_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
203 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
204 #endif
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
205 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
206
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
207 static void take_gil(PyThreadState *tstate)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
208 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
209 int err;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
210 if (tstate == NULL)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
211 Py_FatalError("take_gil: NULL tstate");
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
212
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
213 err = errno;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
214 MUTEX_LOCK(gil_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
215
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
216 if (!_Py_atomic_load_relaxed(&gil_locked))
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
217 goto _ready;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
218
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
219 while (_Py_atomic_load_relaxed(&gil_locked)) {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
220 int timed_out = 0;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
221 unsigned long saved_switchnum;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
222
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
223 saved_switchnum = gil_switch_number;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
224 COND_TIMED_WAIT(gil_cond, gil_mutex, INTERVAL, timed_out);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
225 /* If we timed out and no switch occurred in the meantime, it is time
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
226 to ask the GIL-holding thread to drop it. */
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
227 if (timed_out &&
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
228 _Py_atomic_load_relaxed(&gil_locked) &&
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
229 gil_switch_number == saved_switchnum) {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
230 SET_GIL_DROP_REQUEST();
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
231 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
232 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
233 _ready:
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
234 #ifdef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
235 /* This mutex must be taken before modifying gil_last_holder (see drop_gil()). */
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
236 MUTEX_LOCK(switch_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
237 #endif
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
238 /* We now hold the GIL */
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
239 _Py_atomic_store_relaxed(&gil_locked, 1);
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
240 _Py_ANNOTATE_RWLOCK_ACQUIRED(&gil_locked, /*is_write=*/1);
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
241
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
242 if (tstate != _Py_atomic_load_relaxed(&gil_last_holder)) {
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
243 _Py_atomic_store_relaxed(&gil_last_holder, tstate);
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
244 ++gil_switch_number;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
245 }
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
246
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
247 #ifdef FORCE_SWITCHING
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
248 COND_SIGNAL(switch_cond);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
249 MUTEX_UNLOCK(switch_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
250 #endif
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 57203
diff changeset
251 if (_Py_atomic_load_relaxed(&gil_drop_request)) {
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
252 RESET_GIL_DROP_REQUEST();
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
253 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
254 if (tstate->async_exc != NULL) {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
255 _PyEval_SignalAsyncExc();
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
256 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
257
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
258 MUTEX_UNLOCK(gil_mutex);
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
259 errno = err;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
260 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
261
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
262 void _PyEval_SetSwitchInterval(unsigned long microseconds)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
263 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
264 gil_interval = microseconds;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
265 }
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
266
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
267 unsigned long _PyEval_GetSwitchInterval()
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
268 {
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
269 return gil_interval;
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
270 }