summaryrefslogtreecommitdiffstats
path: root/Include/cpython/pystate.h
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2023-11-08 22:39:29 (GMT)
committerGitHub <noreply@github.com>2023-11-08 22:39:29 (GMT)
commit31c90d5838e8d6e4c47d98500a34810ccb33a6d4 (patch)
tree5be595b11ca17cf1f1bd5875a69a04b927f10dff /Include/cpython/pystate.h
parent0b718e6407da65b838576a2459d630824ca62155 (diff)
downloadcpython-31c90d5838e8d6e4c47d98500a34810ccb33a6d4.zip
cpython-31c90d5838e8d6e4c47d98500a34810ccb33a6d4.tar.gz
cpython-31c90d5838e8d6e4c47d98500a34810ccb33a6d4.tar.bz2
gh-111569: Implement Python critical section API (gh-111571)
Critical sections are helpers to replace the global interpreter lock with finer grained locking. They provide similar guarantees to the GIL and avoid the deadlock risk that plain locking involves. Critical sections are implicitly ended whenever the GIL would be released. They are resumed when the GIL would be acquired. Nested critical sections behave as if the sections were interleaved.
Diffstat (limited to 'Include/cpython/pystate.h')
-rw-r--r--Include/cpython/pystate.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index ec99f90..4fad4c6 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -149,6 +149,13 @@ struct _ts {
struct _py_trashcan trash;
+ /* Tagged pointer to top-most critical section, or zero if there is no
+ * active critical section. Critical sections are only used in
+ * `--disable-gil` builds (i.e., when Py_NOGIL is defined to 1). In the
+ * default build, this field is always zero.
+ */
+ uintptr_t critical_section;
+
/* Called when a thread state is deleted normally, but not when it
* is destroyed after fork().
* Pain: to prevent rare but fatal shutdown errors (issue 18808),