本文整理汇总了C++中PyThread_get_key_value函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThread_get_key_value函数的具体用法?C++ PyThread_get_key_value怎么用?C++ PyThread_get_key_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyThread_get_key_value函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyGILState_GetThisThreadState
/* The public functions */
PyThreadState *
PyGILState_GetThisThreadState(void)
{
if (autoInterpreterState == NULL)
return NULL;
return (PyThreadState *)PyThread_get_key_value(autoTLSkey);
}
示例2: PyGILState_Ensure
PyGILState_STATE
PyGILState_Ensure(void)
{
int current;
PyThreadState *tcur;
/* Note that we do not auto-init Python here - apart from
potential races with 2 threads auto-initializing, pep-311
spells out other issues. Embedders are expected to have
called Py_Initialize() and usually PyEval_InitThreads().
*/
assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);
if (tcur == NULL) {
/* Create a new thread state for this thread */
tcur = PyThreadState_New(autoInterpreterState);
if (tcur == NULL)
Py_FatalError("Couldn't create thread-state for new thread");
/* This is our thread state! We'll need to delete it in the
matching call to PyGILState_Release(). */
tcur->gilstate_counter = 0;
current = 0; /* new thread state is never current */
}
else
current = PyThreadState_IsCurrent(tcur);
if (current == 0)
PyEval_RestoreThread(tcur);
/* Update our counter in the thread-state - no need for locks:
- tcur will remain valid as we hold the GIL.
- the counter is safe as we are the only thread "allowed"
to modify this value
*/
++tcur->gilstate_counter;
return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;
}
示例3: thread
/* When a thread state is created for a thread by some mechanism other than
PyGILState_Ensure, it's important that the GILState machinery knows about
it so it doesn't try to create another thread state for the thread (this is
a better fix for SF bug #1010677 than the first one attempted).
*/
static void
_PyGILState_NoteThreadState(PyThreadState* tstate)
{
/* If autoTLSkey isn't initialized, this must be the very first
threadstate created in Py_Initialize(). Don't do anything for now
(we'll be back here when _PyGILState_Init is called). */
if (!autoInterpreterState)
return;
/* Stick the thread state for this thread in thread local storage.
The only situation where you can legitimately have more than one
thread state for an OS level thread is when there are multiple
interpreters.
You shouldn't really be using the PyGILState_ APIs anyway (see issues
#10915 and #15751).
The first thread state created for that given OS level thread will
"win", which seems reasonable behaviour.
*/
if (PyThread_get_key_value(autoTLSkey) == NULL) {
if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
Py_FatalError("Couldn't create autoTLSkey mapping");
}
/* PyGILState_Release must not try to delete this thread state. */
tstate->gilstate_counter = 1;
}
示例4: pyg_get_current_main_loop
static inline GMainLoop *
pyg_get_current_main_loop (void)
{
if (pyg_current_main_loop_key == -1)
return NULL;
return PyThread_get_key_value(pyg_current_main_loop_key);
}
示例5: _PyGILState_Init
/* Internal initialization/finalization functions called by
Py_Initialize/Py_Finalize
*/
void
_PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
{
assert(i && t); /* must init with valid states */
autoTLSkey = PyThread_create_key();
autoInterpreterState = i;
assert(PyThread_get_key_value(autoTLSkey) == NULL);
assert(t->gilstate_counter == 0);
_PyGILState_NoteThreadState(t);
}
示例6: PyThreadState_Delete
void
PyThreadState_Delete(PyThreadState *tstate)
{
if (tstate == _PyThreadState_Current)
Py_FatalError("PyThreadState_Delete: tstate is still current");
tstate_delete_common(tstate);
#ifdef WITH_THREAD
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
#endif /* WITH_THREAD */
}
示例7: PyThreadState_DeleteCurrent
void
PyThreadState_DeleteCurrent()
{
PyThreadState *tstate = _PyThreadState_Current;
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
_PyThreadState_Current = NULL;
tstate_delete_common(tstate);
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
PyEval_ReleaseLock();
}
示例8: _PyGILState_Init
/* Internal initialization/finalization functions called by
Py_Initialize/Py_Finalize
*/
void
_PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
{
assert(i && t); /* must init with valid states */
autoTLSkey = PyThread_create_key();
if (autoTLSkey == -1)
Py_FatalError("Could not allocate TLS entry");
autoInterpreterState = i;
assert(PyThread_get_key_value(autoTLSkey) == NULL);
assert(t->gilstate_counter == 0);
_PyGILState_NoteThreadState(t);
}
示例9: PyThreadState_DeleteCurrent
void
PyThreadState_DeleteCurrent()
{
PyThreadState *tstate = (PyThreadState*)_Py_atomic_load_relaxed(
&_PyThreadState_Current);
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
_Py_atomic_store_relaxed(&_PyThreadState_Current, NULL);
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
tstate_delete_common(tstate);
PyEval_ReleaseLock();
}
示例10: pyg_restore_current_main_loop
static inline void
pyg_restore_current_main_loop (GMainLoop *main_loop)
{
GMainLoop *prev;
g_return_if_fail (pyg_current_main_loop_key != -1);
prev = PyThread_get_key_value(pyg_current_main_loop_key);
if (prev != NULL)
g_main_loop_unref(prev);
PyThread_delete_key_value(pyg_current_main_loop_key);
if (main_loop != NULL)
PyThread_set_key_value(pyg_current_main_loop_key, main_loop);
}
示例11: pyg_save_current_main_loop
static inline GMainLoop *
pyg_save_current_main_loop (GMainLoop *main_loop)
{
GMainLoop *retval;
g_return_val_if_fail(main_loop != NULL, NULL);
if (pyg_current_main_loop_key == -1)
pyg_current_main_loop_key = PyThread_create_key();
retval = PyThread_get_key_value(pyg_current_main_loop_key);
PyThread_delete_key_value(pyg_current_main_loop_key);
PyThread_set_key_value(pyg_current_main_loop_key,
g_main_loop_ref(main_loop));
return retval;
}
示例12: PyGILState_Release
void
PyGILState_Release(PyGILState_STATE oldstate)
{
PyThreadState *tcur = (PyThreadState *)PyThread_get_key_value(
autoTLSkey);
if (tcur == NULL)
Py_FatalError("auto-releasing thread-state, "
"but no thread-state for this thread");
/* We must hold the GIL and have our thread state current */
/* XXX - remove the check - the assert should be fine,
but while this is very new (April 2003), the extra check
by release-only users can't hurt.
*/
if (! PyThreadState_IsCurrent(tcur))
Py_FatalError("This thread state must be current when releasing");
assert(PyThreadState_IsCurrent(tcur));
--tcur->gilstate_counter;
assert(tcur->gilstate_counter >= 0); /* illegal counter value */
/* If we're going to destroy this thread-state, we must
* clear it while the GIL is held, as destructors may run.
*/
if (tcur->gilstate_counter == 0) {
/* can't have been locked when we created it */
assert(oldstate == PyGILState_UNLOCKED);
PyThreadState_Clear(tcur);
/* Delete the thread-state. Note this releases the GIL too!
* It's vital that the GIL be held here, to avoid shutdown
* races; see bugs 225673 and 1061968 (that nasty bug has a
* habit of coming back).
*/
PyThreadState_DeleteCurrent();
}
/* Release the lock if necessary */
else if (oldstate == PyGILState_UNLOCKED)
PyEval_SaveThread();
}