Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
684cd0e6
Commit
684cd0e6
authored
Mar 23, 2013
by
Kristján Valur Jónsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17522: Add the PyGILState_Check() API.
parent
d4296fc1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
0 deletions
+28
-0
Doc/c-api/init.rst
Doc/c-api/init.rst
+12
-0
Include/pystate.h
Include/pystate.h
+5
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/pystate.c
Python/pystate.c
+9
-0
No files found.
Doc/c-api/init.rst
View file @
684cd0e6
...
...
@@ -654,6 +654,18 @@ with sub-interpreters:
made on the main thread. This is mainly a helper/diagnostic function.
.. c:function:: int PyGILState_Check()
Return 1 if the current thread is holding the GIL and 0 otherwise.
This function can be called from any thread at any time.
Only if it has had its Python thread state initialized and currently is
holding the GIL will it return 1.
This is mainly a helper/diagnostic function. It can be useful
for example in callback contexts or memory allocation functions when
knowing that the GIL is locked can allow the caller to perform sensitive
actions or otherwise behave differently.
The following macros are normally used without a trailing semicolon; look for
example usage in the Python source distribution.
...
...
Include/pystate.h
View file @
684cd0e6
...
...
@@ -212,6 +212,11 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
*/
PyAPI_FUNC
(
PyThreadState
*
)
PyGILState_GetThisThreadState
(
void
);
/* Helper/diagnostic function - return 1 if the current thread
* currently holds the GIL, 0 otherwise
*/
PyAPI_FUNC
(
int
)
PyGILState_Check
(
void
);
#endif
/* #ifdef WITH_THREAD */
/* The implementation of sys._current_frames() Returns a dict mapping
...
...
Misc/NEWS
View file @
684cd0e6
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
Core and Builtins
-----------------
- Issue #17522: Add the PyGILState_Check() API.
- Issue #16475: Support object instancing, recursion and interned strings
in marshal
...
...
Python/pystate.c
View file @
684cd0e6
...
...
@@ -697,6 +697,15 @@ PyGILState_GetThisThreadState(void)
return
(
PyThreadState
*
)
PyThread_get_key_value
(
autoTLSkey
);
}
int
PyGILState_Check
(
void
)
{
/* can't use PyThreadState_Get() since it will assert that it has the GIL */
PyThreadState
*
tstate
=
(
PyThreadState
*
)
_Py_atomic_load_relaxed
(
&
_PyThreadState_Current
);
return
tstate
&&
(
tstate
==
PyGILState_GetThisThreadState
());
}
PyGILState_STATE
PyGILState_Ensure
(
void
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment