当前位置: 首页>>代码示例>>C++>>正文


C++ PyThread_release_lock函数代码示例

本文整理汇总了C++中PyThread_release_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ PyThread_release_lock函数的具体用法?C++ PyThread_release_lock怎么用?C++ PyThread_release_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyThread_release_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例2: 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

示例3: faulthandler_thread

static void
faulthandler_thread(void *unused)
{
    PyLockStatus st;
    const char* errmsg;
    PyThreadState *current;
    int ok;

    do {
        st = PyThread_acquire_lock_timed(thread.cancel_event,
                                         thread.timeout_ms, 0);
        if (st == PY_LOCK_ACQUIRED) {
            /* Cancelled by user */
            break;
        }
        /* Timeout => dump traceback */
        assert(st == PY_LOCK_FAILURE);

        /* get the thread holding the GIL, NULL if no thread hold the GIL */
        current = _Py_atomic_load_relaxed(&_PyThreadState_Current);

        errmsg = _Py_DumpTracebackThreads(thread.fd, thread.interp, current);
        ok = (errmsg == NULL);

        if (thread.exit)
            _exit(1);
    } while (ok && thread.repeat);

    /* The only way out */
    PyThread_release_lock(thread.cancel_event);
    PyThread_release_lock(thread.join_event);
}
开发者ID:pombredanne,项目名称:cpython,代码行数:32,代码来源:faulthandler.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: 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

示例6: 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

示例7: lock_PyThread_release_lock

static PyObject *
lock_PyThread_release_lock(lockobject *self)
{
	/* Sanity check: the lock must be locked */
	if (PyThread_acquire_lock(self->lock_lock, 0)) {
		PyThread_release_lock(self->lock_lock);
		PyErr_SetString(ThreadError, "release unlocked lock");
		return NULL;
	}

	PyThread_release_lock(self->lock_lock);
	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:14,代码来源:_threadmodule.c

示例8: PyThread_acquire_lock

PyObject *MPyEmbed_GetPostFrame(void) {
	struct MPyEmbed_ThreadData *td;
	PyObject *postframe;

	PyThread_acquire_lock(threaddatalock, WAIT_LOCK);

	td = get_current_data();
	if (!td) {
		PyThread_release_lock(threaddatalock);
		return 0;
	}
	postframe = td->postframe;
	PyThread_release_lock(threaddatalock);
	Py_XINCREF(postframe);
	return postframe;
}
开发者ID:Plombo,项目名称:dega,代码行数:16,代码来源:embed.c

示例9: 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

示例10: 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

示例11: MPyEmbed_SetPostFrame

int MPyEmbed_SetPostFrame(PyObject *postframe) {
	struct MPyEmbed_ThreadData *td;
	PyObject *old_postframe;

	PyThread_acquire_lock(threaddatalock, WAIT_LOCK);

	td = get_current_data();
	if (!td) {
		PyThread_release_lock(threaddatalock);
		return 0;
	}
	old_postframe = td->postframe;
	td->postframe = postframe;
	Py_XINCREF(postframe);
	PyThread_release_lock(threaddatalock);
	Py_XDECREF(old_postframe);
	return 1;
}
开发者ID:Plombo,项目名称:dega,代码行数:18,代码来源:embed.c

示例12: 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

示例13: 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

示例14: _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

示例15: 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


注:本文中的PyThread_release_lock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。