mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
Style guide & consistency changes. No semantic changes.
This commit is contained in:
parent
4c1f5ecfe3
commit
19717fa33a
2 changed files with 41 additions and 29 deletions
|
@ -388,9 +388,10 @@ static int autoTLSkey = 0;
|
||||||
/* Internal initialization/finalization functions called by
|
/* Internal initialization/finalization functions called by
|
||||||
Py_Initialize/Py_Finalize
|
Py_Initialize/Py_Finalize
|
||||||
*/
|
*/
|
||||||
void _PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
|
void
|
||||||
|
_PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
|
||||||
{
|
{
|
||||||
assert(i && t); /* must init with a valid states */
|
assert(i && t); /* must init with valid states */
|
||||||
autoTLSkey = PyThread_create_key();
|
autoTLSkey = PyThread_create_key();
|
||||||
autoInterpreterState = i;
|
autoInterpreterState = i;
|
||||||
/* Now stash the thread state for this thread in TLS */
|
/* Now stash the thread state for this thread in TLS */
|
||||||
|
@ -399,7 +400,8 @@ void _PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
|
||||||
t->gilstate_counter = 1;
|
t->gilstate_counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _PyGILState_Fini(void)
|
void
|
||||||
|
_PyGILState_Fini(void)
|
||||||
{
|
{
|
||||||
PyThread_delete_key(autoTLSkey);
|
PyThread_delete_key(autoTLSkey);
|
||||||
autoTLSkey = 0;
|
autoTLSkey = 0;
|
||||||
|
@ -407,14 +409,16 @@ void _PyGILState_Fini(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The public functions */
|
/* The public functions */
|
||||||
PyThreadState *PyGILState_GetThisThreadState(void)
|
PyThreadState *
|
||||||
|
PyGILState_GetThisThreadState(void)
|
||||||
{
|
{
|
||||||
if (autoInterpreterState == NULL || autoTLSkey == 0)
|
if (autoInterpreterState == NULL || autoTLSkey == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
return (PyThreadState *)PyThread_get_key_value(autoTLSkey);
|
return (PyThreadState *)PyThread_get_key_value(autoTLSkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyGILState_STATE PyGILState_Ensure(void)
|
PyGILState_STATE
|
||||||
|
PyGILState_Ensure(void)
|
||||||
{
|
{
|
||||||
int current;
|
int current;
|
||||||
PyThreadState *tcur;
|
PyThreadState *tcur;
|
||||||
|
@ -432,20 +436,22 @@ PyGILState_STATE PyGILState_Ensure(void)
|
||||||
Py_FatalError("Couldn't create thread-state for new thread");
|
Py_FatalError("Couldn't create thread-state for new thread");
|
||||||
PyThread_set_key_value(autoTLSkey, (void *)tcur);
|
PyThread_set_key_value(autoTLSkey, (void *)tcur);
|
||||||
current = 0; /* new thread state is never current */
|
current = 0; /* new thread state is never current */
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
current = PyThreadState_IsCurrent(tcur);
|
current = PyThreadState_IsCurrent(tcur);
|
||||||
if (!current)
|
if (current == 0)
|
||||||
PyEval_RestoreThread(tcur);
|
PyEval_RestoreThread(tcur);
|
||||||
/* Update our counter in the thread-state - no need for locks:
|
/* Update our counter in the thread-state - no need for locks:
|
||||||
- tcur will remain valid as we hold the GIL.
|
- tcur will remain valid as we hold the GIL.
|
||||||
- the counter is safe as we are the only thread "allowed"
|
- the counter is safe as we are the only thread "allowed"
|
||||||
to modify this value
|
to modify this value
|
||||||
*/
|
*/
|
||||||
tcur->gilstate_counter++;
|
++tcur->gilstate_counter;
|
||||||
return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;
|
return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyGILState_Release(PyGILState_STATE oldstate)
|
void
|
||||||
|
PyGILState_Release(PyGILState_STATE oldstate)
|
||||||
{
|
{
|
||||||
PyThreadState *tcur = PyThread_get_key_value(autoTLSkey);
|
PyThreadState *tcur = PyThread_get_key_value(autoTLSkey);
|
||||||
if (tcur == NULL)
|
if (tcur == NULL)
|
||||||
|
@ -459,7 +465,7 @@ void PyGILState_Release(PyGILState_STATE oldstate)
|
||||||
if (! PyThreadState_IsCurrent(tcur))
|
if (! PyThreadState_IsCurrent(tcur))
|
||||||
Py_FatalError("This thread state must be current when releasing");
|
Py_FatalError("This thread state must be current when releasing");
|
||||||
assert(PyThreadState_IsCurrent(tcur));
|
assert(PyThreadState_IsCurrent(tcur));
|
||||||
tcur->gilstate_counter -= 1;
|
--tcur->gilstate_counter;
|
||||||
assert(tcur->gilstate_counter >= 0); /* illegal counter value */
|
assert(tcur->gilstate_counter >= 0); /* illegal counter value */
|
||||||
|
|
||||||
/* If we are about to destroy this thread-state, we must
|
/* If we are about to destroy this thread-state, we must
|
||||||
|
|
|
@ -157,7 +157,8 @@ static struct key *keyhead = NULL;
|
||||||
static int nkeys = 0;
|
static int nkeys = 0;
|
||||||
static PyThread_type_lock keymutex = NULL;
|
static PyThread_type_lock keymutex = NULL;
|
||||||
|
|
||||||
static struct key *find_key(int key, void *value)
|
static struct key *
|
||||||
|
find_key(int key, void *value)
|
||||||
{
|
{
|
||||||
struct key *p;
|
struct key *p;
|
||||||
long id = PyThread_get_thread_ident();
|
long id = PyThread_get_thread_ident();
|
||||||
|
@ -180,14 +181,16 @@ static struct key *find_key(int key, void *value)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PyThread_create_key(void)
|
int
|
||||||
|
PyThread_create_key(void)
|
||||||
{
|
{
|
||||||
if (keymutex == NULL)
|
if (keymutex == NULL)
|
||||||
keymutex = PyThread_allocate_lock();
|
keymutex = PyThread_allocate_lock();
|
||||||
return ++nkeys;
|
return ++nkeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyThread_delete_key(int key)
|
void
|
||||||
|
PyThread_delete_key(int key)
|
||||||
{
|
{
|
||||||
struct key *p, **q;
|
struct key *p, **q;
|
||||||
PyThread_acquire_lock(keymutex, 1);
|
PyThread_acquire_lock(keymutex, 1);
|
||||||
|
@ -204,7 +207,8 @@ void PyThread_delete_key(int key)
|
||||||
PyThread_release_lock(keymutex);
|
PyThread_release_lock(keymutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PyThread_set_key_value(int key, void *value)
|
int
|
||||||
|
PyThread_set_key_value(int key, void *value)
|
||||||
{
|
{
|
||||||
struct key *p = find_key(key, value);
|
struct key *p = find_key(key, value);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
|
@ -213,7 +217,8 @@ int PyThread_set_key_value(int key, void *value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *PyThread_get_key_value(int key)
|
void *
|
||||||
|
PyThread_get_key_value(int key)
|
||||||
{
|
{
|
||||||
struct key *p = find_key(key, NULL);
|
struct key *p = find_key(key, NULL);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
|
@ -222,7 +227,8 @@ void *PyThread_get_key_value(int key)
|
||||||
return p->value;
|
return p->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyThread_delete_key_value(int key)
|
void
|
||||||
|
PyThread_delete_key_value(int key)
|
||||||
{
|
{
|
||||||
long id = PyThread_get_thread_ident();
|
long id = PyThread_get_thread_ident();
|
||||||
struct key *p, **q;
|
struct key *p, **q;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue