本文整理汇总了C++中PyThread_acquire_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThread_acquire_lock函数的具体用法?C++ PyThread_acquire_lock怎么用?C++ PyThread_acquire_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyThread_acquire_lock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_bpo20891
static int test_bpo20891(void)
{
/* bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
call PyEval_InitThreads() for us in this case. */
PyThread_type_lock lock = PyThread_allocate_lock();
if (!lock) {
fprintf(stderr, "PyThread_allocate_lock failed!");
return 1;
}
_testembed_Py_Initialize();
unsigned long thrd = PyThread_start_new_thread(bpo20891_thread, &lock);
if (thrd == PYTHREAD_INVALID_THREAD_ID) {
fprintf(stderr, "PyThread_start_new_thread failed!");
return 1;
}
PyThread_acquire_lock(lock, WAIT_LOCK);
Py_BEGIN_ALLOW_THREADS
/* wait until the thread exit */
PyThread_acquire_lock(lock, WAIT_LOCK);
Py_END_ALLOW_THREADS
PyThread_free_lock(lock);
return 0;
}
开发者ID:1st1,项目名称:cpython,代码行数:29,代码来源:_testembed.c
示例2: faulthandler_dump_traceback_later
static PyObject*
faulthandler_dump_traceback_later(PyObject *self,
PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"timeout", "repeat", "file", "exit", NULL};
double timeout;
PY_TIMEOUT_T timeout_ms;
int repeat = 0;
PyObject *file = NULL;
int fd;
int exit = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"d|iOi:dump_tracebacks_later", kwlist,
&timeout, &repeat, &file, &exit))
return NULL;
timeout *= 1e6;
if (timeout >= (double) PY_TIMEOUT_MAX) {
PyErr_SetString(PyExc_OverflowError, "timeout value is too large");
return NULL;
}
timeout_ms = (PY_TIMEOUT_T)timeout;
if (timeout_ms <= 0) {
PyErr_SetString(PyExc_ValueError, "timeout must be greater than 0");
return NULL;
}
file = faulthandler_get_fileno(file, &fd);
if (file == NULL)
return NULL;
/* Cancel previous thread, if running */
faulthandler_cancel_dump_tracebacks_later();
Py_XDECREF(thread.file);
Py_INCREF(file);
thread.file = file;
thread.fd = fd;
thread.timeout_ms = timeout_ms;
thread.repeat = repeat;
thread.interp = PyThreadState_Get()->interp;
thread.exit = exit;
/* Arm these locks to serve as events when released */
PyThread_acquire_lock(thread.join_event, 1);
PyThread_acquire_lock(thread.cancel_event, 1);
thread.running = 1;
if (PyThread_start_new_thread(faulthandler_thread, NULL) == -1) {
thread.running = 0;
PyThread_release_lock(thread.join_event);
PyThread_release_lock(thread.cancel_event);
Py_CLEAR(thread.file);
PyErr_SetString(PyExc_RuntimeError,
"unable to start watchdog thread");
return NULL;
}
Py_RETURN_NONE;
}
开发者ID:pombredanne,项目名称:cpython,代码行数:60,代码来源:faulthandler.c
示例3: MPyEmbed_CBPostFrame
void MPyEmbed_CBPostFrame(void) {
int i;
if (!PythonAvailable) {
return;
}
PyThread_acquire_lock(threaddatalock, WAIT_LOCK);
for (i = 0; i < THREADS; i++) {
if (VALID(threaddata[i])) {
PyObject *cb = threaddata[i].postframe;
PyThreadState *ts = threaddata[i].mainstate;
PyObject *rv;
PyThread_release_lock(threaddatalock);
ts->thread_id = PyThread_get_thread_ident();
PyEval_AcquireThread(ts);
if (cb != NULL && PyCallable_Check(cb)) {
rv = PyObject_CallObject(cb, NULL);
Py_XDECREF(rv);
if (rv == NULL) {
PyErr_Print();
}
}
PyEval_ReleaseThread(ts);
PyThread_acquire_lock(threaddatalock, WAIT_LOCK);
}
}
PyThread_release_lock(threaddatalock);
}
开发者ID:Plombo,项目名称:dega,代码行数:28,代码来源:embed.c
示例4: evaluator_thread
static void
evaluator_thread(void *arg)
{
threadinfo *info = (threadinfo *)arg;
PyFFEnergyTermObject *term;
int i;
while (1) {
#if THREAD_DEBUG
printf("Thread %d waiting for lock...\n", info->input.thread_id);
#endif
PyThread_acquire_lock(info->lock, 1);
#if THREAD_DEBUG
printf("Thread %d running\n", info->input.thread_id);
#endif
if (info->exit) {
info->stop = 1;
break;
}
for (i = 0; i < info->evaluator->nterms+1; i++)
info->energy.energy_terms[i] = 0.;
info->energy.energy = 0.;
info->energy.virial_available = 1;
info->energy.error = 0;
if (info->with_gradients && info->energy.gradients != NULL) {
double *data = (double *)((PyArrayObject *)info->energy.gradients)->data;
for (i = 0; i < 3*info->input.natoms; i++)
data[i] = 0.;
}
PyThread_acquire_lock(info->evaluator->global_lock, 1);
info->done = 0;
PyThread_release_lock(info->evaluator->global_lock);
for (i = 0; i < info->evaluator->ntermobjects; i++) {
term = ((PyFFEnergyTermObject **)info->evaluator->terms->data)[i];
if (term->threaded) {
(*term->eval_func)(term, info->evaluator, &info->input, &info->energy);
#if THREAD_DEBUG
{
int j;
printf("Thread %d: %s: ", info->input.thread_id,
term->evaluator_name);
for (j = term->index; j < term->index+term->nterms; j++)
printf("%lf ", info->energy.energy_terms[j]);
printf("\n");
}
#endif
}
}
PyThread_acquire_lock(info->evaluator->global_lock, 1);
info->done = 1;
PyThread_release_lock(info->evaluator->global_lock);
}
}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:52,代码来源:MMTK_pose.c
示例5: test_thread_state
static PyObject *
test_thread_state(PyObject *self, PyObject *args)
{
PyObject *fn;
int success = 1;
if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn))
return NULL;
if (!PyCallable_Check(fn)) {
PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
fn->ob_type->tp_name);
return NULL;
}
/* Ensure Python is set up for threading */
PyEval_InitThreads();
thread_done = PyThread_allocate_lock();
if (thread_done == NULL)
return PyErr_NoMemory();
PyThread_acquire_lock(thread_done, 1);
/* Start a new thread with our callback. */
PyThread_start_new_thread(_make_call_from_thread, fn);
/* Make the callback with the thread lock held by this thread */
success &= _make_call(fn);
/* Do it all again, but this time with the thread-lock released */
Py_BEGIN_ALLOW_THREADS
success &= _make_call(fn);
PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
Py_END_ALLOW_THREADS
/* And once more with and without a thread
XXX - should use a lock and work out exactly what we are trying
to test <wink>
*/
Py_BEGIN_ALLOW_THREADS
PyThread_start_new_thread(_make_call_from_thread, fn);
success &= _make_call(fn);
PyThread_acquire_lock(thread_done, 1); /* wait for thread to finish */
Py_END_ALLOW_THREADS
/* Release lock we acquired above. This is required on HP-UX. */
PyThread_release_lock(thread_done);
PyThread_free_lock(thread_done);
if (!success)
return NULL;
Py_RETURN_NONE;
}
开发者ID:ianloic,项目名称:unladen-swallow,代码行数:50,代码来源:_testcapimodule.c
示例6: rlock_acquire_restore
static PyObject *
rlock_acquire_restore(rlockobject *self, PyObject *arg)
{
long owner;
unsigned long count;
int r = 1;
if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner))
return NULL;
if (!PyThread_acquire_lock(self->rlock_lock, 0)) {
Py_BEGIN_ALLOW_THREADS
r = PyThread_acquire_lock(self->rlock_lock, 1);
Py_END_ALLOW_THREADS
}
开发者ID:AndyPanda95,项目名称:python-for-android,代码行数:15,代码来源:_threadmodule.c
示例7: Connection__thr_lockop
static PyObject *
Connection__thr_lockop(pycbc_Connection *self, PyObject *arg)
{
int rv;
int is_unlock = 0;
rv = PyArg_ParseTuple(arg, "i:is_unlock", &is_unlock);
if (!rv) {
return NULL;
}
if (!self->lockmode) {
PYCBC_EXC_WRAP(PYCBC_EXC_THREADING, 0, "lockmode is LOCKMODE_NONE");
return NULL;
}
if (is_unlock) {
PyThread_release_lock(self->lock);
} else {
if (!PyThread_acquire_lock(self->lock, WAIT_LOCK)) {
PYCBC_EXC_WRAP(PYCBC_EXC_THREADING, 0, "Couldn't lock");
return NULL;
}
}
Py_RETURN_NONE;
}
开发者ID:manfre,项目名称:couchbase-python-client,代码行数:27,代码来源:connection.c
示例8: beos_cleanup_dyn
/* atexit() handler that'll call unload_add_on() for every item in the
* dictionary.
*/
static void beos_cleanup_dyn( void )
{
if( beos_dyn_images ) {
int idx;
int list_size;
PyObject *id_list;
#ifdef WITH_THREAD
PyThread_acquire_lock( beos_dyn_lock, 1 );
#endif
id_list = PyDict_Values( beos_dyn_images );
list_size = PyList_Size( id_list );
for( idx = 0; idx < list_size; idx++ ) {
PyObject *the_item;
the_item = PyList_GetItem( id_list, idx );
beos_nuke_dyn( the_item );
}
PyDict_Clear( beos_dyn_images );
#ifdef WITH_THREAD
PyThread_free_lock( beos_dyn_lock );
#endif
}
}
开发者ID:asottile,项目名称:ancient-pythons,代码行数:31,代码来源:dynload_beos.c
示例9: beos_add_dyn
/*
* Add an image_id to the dictionary; the module name of the loaded image
* is the key. Note that if the key is already in the dict, we unload
* that image; this should allow reload() to work on dynamically loaded
* modules (super-keen!).
*/
static void beos_add_dyn( char *name, image_id id )
{
int retval;
PyObject *py_id;
if( beos_dyn_images == NULL ) {
beos_init_dyn();
}
#ifdef WITH_THREAD
retval = PyThread_acquire_lock( beos_dyn_lock, 1 );
#endif
/* If there's already an object with this key in the dictionary,
* we're doing a reload(), so let's nuke it.
*/
py_id = PyDict_GetItemString( beos_dyn_images, name );
if( py_id ) {
beos_nuke_dyn( py_id );
retval = PyDict_DelItemString( beos_dyn_images, name );
}
py_id = PyInt_FromLong( (long)id );
if( py_id ) {
retval = PyDict_SetItemString( beos_dyn_images, name, py_id );
}
#ifdef WITH_THREAD
PyThread_release_lock( beos_dyn_lock );
#endif
}
开发者ID:asottile,项目名称:ancient-pythons,代码行数:37,代码来源:dynload_beos.c
示例10: barrier
void
barrier(barrierinfo *binfo, int thread_id, int nthreads)
{
int done = 0;
if (nthreads > 1) {
PyThread_acquire_lock(binfo->lock, 1);
if (binfo->n == nthreads)
binfo->n = 1;
else
binfo->n++;
PyThread_release_lock(binfo->lock);
while (!done) {
PyThread_acquire_lock(binfo->lock, 1);
done = (binfo->n == nthreads);
PyThread_release_lock(binfo->lock);
}
}
}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:18,代码来源:MMTK_pose.c
示例11: lock_dealloc
static void
lock_dealloc(lockobject *self)
{
/* Unlock the lock so it's safe to free it */
PyThread_acquire_lock(self->lock_lock, 0);
PyThread_release_lock(self->lock_lock);
PyThread_free_lock(self->lock_lock);
PyObject_Del(self);
}
开发者ID:gnuhub,项目名称:python-2.5-annotated,代码行数:10,代码来源:threadmodule.c
示例12: _PyInterpreterState_IDIncref
void
_PyInterpreterState_IDIncref(PyInterpreterState *interp)
{
if (interp->id_mutex == NULL) {
return;
}
PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK);
interp->id_refcount += 1;
PyThread_release_lock(interp->id_mutex);
}
开发者ID:tiran,项目名称:cpython,代码行数:10,代码来源:pystate.c
示例13: cancel_dump_tracebacks_later
static void
cancel_dump_tracebacks_later(void)
{
/* Notify cancellation */
PyThread_release_lock(thread.cancel_event);
/* Wait for thread to join */
PyThread_acquire_lock(thread.running, 1);
PyThread_release_lock(thread.running);
/* The main thread should always hold the cancel_event lock */
PyThread_acquire_lock(thread.cancel_event, 1);
Py_CLEAR(thread.file);
if (thread.header) {
free(thread.header);
thread.header = NULL;
}
}
开发者ID:mikegraham,项目名称:cpython,代码行数:19,代码来源:faulthandler.c
示例14: locked
static Box* locked(Box* _self) {
RELEASE_ASSERT(_self->cls == thread_lock_cls, "");
BoxedThreadLock* self = static_cast<BoxedThreadLock*>(_self);
if (PyThread_acquire_lock(self->lock_lock, 0)) {
PyThread_release_lock(self->lock_lock);
return False;
}
return True;
}
开发者ID:Lunafei,项目名称:pyston,代码行数:10,代码来源:thread.cpp
示例15: CReader_Buffer_lock
static inline void CReader_Buffer_lock(CReader_Buffer *buffer)
{
# ifdef DEBUG_THREAD
fprintf(stderr, "Buffer lock %p [", buffer); fflush(stderr);
# endif
assert(!buffer->state);
PyThread_acquire_lock(buffer->lock, 1);
# ifdef DEBUG_THREAD
fprintf(stderr, " --> %i\n", ++buffer->bufferlockings); fflush(stderr);
# endif
}
开发者ID:redhog,项目名称:Grimoire,代码行数:11,代码来源:CReader.c
示例16: lock_locked_lock
but it needn't be locked by the same thread that unlocks it.");
static PyObject *
lock_locked_lock(lockobject *self)
{
if (PyThread_acquire_lock(self->lock_lock, 0)) {
PyThread_release_lock(self->lock_lock);
return PyBool_FromLong(0L);
}
return PyBool_FromLong(1L);
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:11,代码来源:_threadmodule.c
示例17: threadLockDestructor
static void threadLockDestructor(Box* _self) {
RELEASE_ASSERT(_self->cls == thread_lock_cls, "");
BoxedThreadLock* self = static_cast<BoxedThreadLock*>(_self);
if (self->lock_lock != NULL) {
/* Unlock the lock so it's safe to free it */
PyThread_acquire_lock(self->lock_lock, 0);
PyThread_release_lock(self->lock_lock);
PyThread_free_lock(self->lock_lock);
}
}
开发者ID:Lunafei,项目名称:pyston,代码行数:12,代码来源:thread.cpp
示例18: PyOS_Readline
char *
PyOS_Readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
{
char *rv;
if (_PyOS_ReadlineTState == PyThreadState_GET()) {
PyErr_SetString(PyExc_RuntimeError,
"can't re-enter readline");
return NULL;
}
if (PyOS_ReadlineFunctionPointer == NULL) {
#ifdef __VMS
PyOS_ReadlineFunctionPointer = vms__StdioReadline;
#else
PyOS_ReadlineFunctionPointer = PyOS_StdioReadline;
#endif
}
#ifdef WITH_THREAD
if (_PyOS_ReadlineLock == NULL) {
_PyOS_ReadlineLock = PyThread_allocate_lock();
}
#endif
_PyOS_ReadlineTState = PyThreadState_GET();
Py_BEGIN_ALLOW_THREADS
#ifdef WITH_THREAD
PyThread_acquire_lock(_PyOS_ReadlineLock, 1);
#endif
/* This is needed to handle the unlikely case that the
* interpreter is in interactive mode *and* stdin/out are not
* a tty. This can happen, for example if python is run like
* this: python -i < test1.py
*/
if (!isatty (fileno (sys_stdin)) || !isatty (fileno (sys_stdout)))
rv = PyOS_StdioReadline (sys_stdin, sys_stdout, prompt);
else
rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout,
prompt);
Py_END_ALLOW_THREADS
#ifdef WITH_THREAD
PyThread_release_lock(_PyOS_ReadlineLock);
#endif
_PyOS_ReadlineTState = NULL;
return rv;
}
开发者ID:ChinaQuants,项目名称:pyston,代码行数:52,代码来源:myreadline.c
示例19: release
static Box* release(Box* _self) {
RELEASE_ASSERT(_self->cls == thread_lock_cls, "");
BoxedThreadLock* self = static_cast<BoxedThreadLock*>(_self);
if (PyThread_acquire_lock(self->lock_lock, 0)) {
PyThread_release_lock(self->lock_lock);
raiseExcHelper(ThreadError, "release unlocked lock");
return None;
}
PyThread_release_lock(self->lock_lock);
return None;
}
开发者ID:Lunafei,项目名称:pyston,代码行数:13,代码来源:thread.cpp
示例20: faulthandler_cancel_dump_tracebacks_later
static void
faulthandler_cancel_dump_tracebacks_later(void)
{
if (thread.running) {
/* Notify cancellation */
PyThread_release_lock(thread.cancel_event);
}
/* Wait for thread to join */
PyThread_acquire_lock(thread.join_event, 1);
PyThread_release_lock(thread.join_event);
thread.running = 0;
Py_CLEAR(thread.file);
}
开发者ID:pombredanne,项目名称:cpython,代码行数:13,代码来源:faulthandler.c
注:本文中的PyThread_acquire_lock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论