• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyThread_get_thread_ident函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: signal_handler

static void
signal_handler(int sig_num)
{
#ifdef WITH_THREAD
#ifdef WITH_PTH
	if (PyThread_get_thread_ident() != main_thread) {
		pth_raise(*(pth_t *) main_thread, sig_num);
		return;
	}
#endif
	/* See NOTES section above */
	if (getpid() == main_pid) {
#endif
		is_tripped++;
		Handlers[sig_num].tripped = 1;
		Py_AddPendingCall(checksignals_witharg, NULL);
#ifdef WITH_THREAD
	}
#endif
#ifdef SIGCHLD
	if (sig_num == SIGCHLD) {
		/* To avoid infinite recursion, this signal remains
		   reset until explicit re-instated.
		   Don't clear the 'func' field as it is our pointer
		   to the Python handler... */
		return;
	}
#endif
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(sig_num, 1);
#endif
	PyOS_setsig(sig_num, signal_handler);
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:33,代码来源:signalmodule.c


示例2: PyThread_ReInitTLS

/* Forget everything not associated with the current thread id.
 * This function is called from PyOS_AfterFork().  It is necessary
 * because other thread ids which were in use at the time of the fork
 * may be reused for new threads created in the forked process.
 */
void
PyThread_ReInitTLS(void)
{
    long id = PyThread_get_thread_ident();
    struct key *p, **q;

    if (!keymutex)
        return;

    /* As with interpreter_lock in PyEval_ReInitThreads()
       we just create a new lock without freeing the old one */
    keymutex = PyThread_allocate_lock();

    /* Delete all keys which do not match the current thread id */
    q = &keyhead;
    while ((p = *q) != NULL) {
        if (p->id != id) {
            *q = p->next;
            free((void *)p);
            /* NB This does *not* free p->value! */
        }
        else
            q = &p->next;
    }
}
开发者ID:Darriall,项目名称:pypy,代码行数:30,代码来源:pythread.c


示例3: PyErr_CheckSignals

/* Declared in pyerrors.h */
int
PyErr_CheckSignals(void)
{
	int i;
	PyObject *f;

	if (!is_tripped)
		return 0;
#ifdef WITH_THREAD
	if (PyThread_get_thread_ident() != main_thread)
		return 0;
#endif
	if (!(f = (PyObject *)PyEval_GetFrame()))
		f = Py_None;
	
	for (i = 1; i < NSIG; i++) {
		if (Handlers[i].tripped) {
			PyObject *result = NULL;
			PyObject *arglist = Py_BuildValue("(iO)", i, f);
			Handlers[i].tripped = 0;

			if (arglist) {
				result = PyEval_CallObject(Handlers[i].func,
							   arglist);
				Py_DECREF(arglist);
			}
			if (!result)
				return -1;

			Py_DECREF(result);
		}
	}
	is_tripped = 0;
	return 0;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:36,代码来源:signalmodule.c


示例4: new_threadstate

static PyThreadState *
new_threadstate(PyInterpreterState *interp, int init)
{
    PyThreadState *tstate = (PyThreadState *)PyMem_RawMalloc(sizeof(PyThreadState));

    if (_PyThreadState_GetFrame == NULL)
        _PyThreadState_GetFrame = threadstate_getframe;

    if (tstate != NULL) {
        tstate->interp = interp;

        tstate->frame = NULL;
        tstate->recursion_depth = 0;
        tstate->overflowed = 0;
        tstate->recursion_critical = 0;
        tstate->tracing = 0;
        tstate->use_tracing = 0;
        tstate->tick_counter = 0;
        tstate->gilstate_counter = 0;
        tstate->async_exc = NULL;
#ifdef WITH_THREAD
        tstate->thread_id = PyThread_get_thread_ident();
#else
        tstate->thread_id = 0;
#endif

        tstate->dict = NULL;

        tstate->curexc_type = NULL;
        tstate->curexc_value = NULL;
        tstate->curexc_traceback = NULL;

        tstate->exc_type = NULL;
        tstate->exc_value = NULL;
        tstate->exc_traceback = NULL;

        tstate->c_profilefunc = NULL;
        tstate->c_tracefunc = NULL;
        tstate->c_profileobj = NULL;
        tstate->c_traceobj = NULL;

        tstate->trash_delete_nesting = 0;
        tstate->trash_delete_later = NULL;
        tstate->on_delete = NULL;
        tstate->on_delete_data = NULL;

        if (init)
            _PyThreadState_Init(tstate);

        HEAD_LOCK();
        tstate->prev = NULL;
        tstate->next = interp->tstate_head;
        if (tstate->next)
            tstate->next->prev = tstate;
        interp->tstate_head = tstate;
        HEAD_UNLOCK();
    }

    return tstate;
}
开发者ID:aholkner,项目名称:cpython,代码行数:60,代码来源:pystate.c


示例5: RLock_release

static PyObject *
RLock_release(RLock *self, PyObject *args)
{
    long tid = PyThread_get_thread_ident();

    if (self->count == 0 || self->owner != tid) {
        PyErr_SetString(PyExc_RuntimeError,
                        "cannot release un-acquired lock");
        return NULL;
    }

    if (self->count > 1) {
        --self->count;
        Py_RETURN_NONE;
    }

    assert(self->count == 1);
    if (release_lock(&self->sem) != 0)
        return NULL;

    self->count = 0;
    self->owner = 0;

    Py_RETURN_NONE;
}
开发者ID:mureinik,项目名称:cthreading,代码行数:25,代码来源:_cthreading.c


示例6: RLock_acquire

static PyObject *
RLock_acquire(RLock *self, PyObject *args, PyObject *kwds)
{
    double timeout = -1;
    long tid;
    acquire_result res;

    if (parse_acquire_args(args, kwds, &timeout))
        return NULL;

    tid = PyThread_get_thread_ident();
    if (self->count > 0 && self->owner == tid) {
        unsigned long count = self->count + 1;
        if (count <= self->count) {
            PyErr_SetString(PyExc_OverflowError,
                            "Internal lock count overflowed");
            return NULL;
        }

        self->count = count;
        Py_RETURN_TRUE;
    }

    res = acquire_lock(&self->sem, timeout);
    if (res == ACQUIRE_ERROR)
        return NULL;

    if (res == ACQUIRE_OK) {
        assert(self->count == 0);
        self->owner = tid;
        self->count = 1;
    }

    return PyBool_FromLong(res == ACQUIRE_OK);
}
开发者ID:mureinik,项目名称:cthreading,代码行数:35,代码来源:_cthreading.c


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


示例8: update

 void update() {
     // This makes sense as an exception, but who knows how the user program would react
     // (it might swallow it and do something different)
     RELEASE_ASSERT(thread_id == PyThread_get_thread_ident(),
                    "frame objects can only be accessed from the same thread");
     PythonFrameIterator new_it = it.getCurrentVersion();
     RELEASE_ASSERT(new_it.exists() && new_it.getFrameInfo()->frame_obj == this, "frame has exited");
     it = std::move(new_it);
 }
开发者ID:sjn1978,项目名称:pyston,代码行数:9,代码来源:frame.cpp


示例9: PyOS_AfterFork

void
PyOS_AfterFork(void)
{
#ifdef WITH_THREAD
	PyEval_ReInitThreads();
	main_thread = PyThread_get_thread_ident();
	main_pid = getpid();
#endif
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:9,代码来源:signalmodule.c


示例10: MPyEmbed_Repl

int MPyEmbed_Repl(void) {
	if (!PythonAvailable) {
		return 0;
	}
	mainstate->thread_id = PyThread_get_thread_ident();
	PyEval_AcquireThread(mainstate);
	PyRun_AnyFile(stdin, "<stdin>");
	PyEval_ReleaseThread(mainstate);
	return 1;
}
开发者ID:Plombo,项目名称:dega,代码行数:10,代码来源:embed.c


示例11: PyThread_get_thread_ident

/*
 * Return the thread data for the current thread or NULL if it wasn't
 * recognised.
 */
static threadDef *currentThreadDef(void)
{
    threadDef *thread;
    long ident = PyThread_get_thread_ident();

    for (thread = threads; thread != NULL; thread = thread->next)
        if (thread->thr_ident == ident)
            break;

    return thread;
}
开发者ID:Kanma,项目名称:sip,代码行数:15,代码来源:threads.c


示例12: thread_get_ident

static PyObject *
thread_get_ident(PyObject *self)
{
	long ident;
	ident = PyThread_get_thread_ident();
	if (ident == -1) {
		PyErr_SetString(ThreadError, "no current thread ident");
		return NULL;
	}
	return PyLong_FromLong(ident);
}
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:11,代码来源:_threadmodule.c


示例13: PyThreadState_New

PyThreadState *
PyThreadState_New(PyInterpreterState *interp)
{
	PyThreadState *tstate = (PyThreadState *)malloc(sizeof(PyThreadState));

	if (_PyThreadState_GetFrame == NULL)
		_PyThreadState_GetFrame = threadstate_getframe;

	if (tstate != NULL) {
		tstate->interp = interp;

		tstate->frame = NULL;
		tstate->recursion_depth = 0;
		tstate->tracing = 0;
		tstate->use_tracing = 0;
		tstate->tick_counter = 0;
		tstate->gilstate_counter = 0;
		tstate->async_exc = NULL;
#ifdef WITH_THREAD
		tstate->thread_id = PyThread_get_thread_ident();
#else
		tstate->thread_id = 0;
#endif

		tstate->dict = NULL;

		tstate->curexc_type = NULL;
		tstate->curexc_value = NULL;
		tstate->curexc_traceback = NULL;

		tstate->exc_type = NULL;
		tstate->exc_value = NULL;
		tstate->exc_traceback = NULL;

		tstate->c_profilefunc = NULL;
		tstate->c_tracefunc = NULL;
		tstate->c_profileobj = NULL;
		tstate->c_traceobj = NULL;
#ifdef STACKLESS
		STACKLESS_PYSTATE_NEW;
#endif

#ifdef WITH_THREAD
		_PyGILState_NoteThreadState(tstate);
#endif

		HEAD_LOCK();
		tstate->next = interp->tstate_head;
		interp->tstate_head = tstate;
		HEAD_UNLOCK();
	}

	return tstate;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:54,代码来源:pystate.c


示例14: PyErr_CheckSignals

/* Declared in pyerrors.h */
int
PyErr_CheckSignals(void)
{
	int i;
	PyObject *f;

	if (!is_tripped)
		return 0;

#ifdef WITH_THREAD
	if (PyThread_get_thread_ident() != main_thread)
		return 0;
#endif

	/*
	 * The is_stripped variable is meant to speed up the calls to
	 * PyErr_CheckSignals (both directly or via pending calls) when no
	 * signal has arrived. This variable is set to 1 when a signal arrives
	 * and it is set to 0 here, when we know some signals arrived. This way
	 * we can run the registered handlers with no signals blocked.
	 *
	 * NOTE: with this approach we can have a situation where is_tripped is
	 *       1 but we have no more signals to handle (Handlers[i].tripped
	 *       is 0 for every signal i). This won't do us any harm (except
	 *       we're gonna spent some cycles for nothing). This happens when
	 *       we receive a signal i after we zero is_tripped and before we
	 *       check Handlers[i].tripped.
	 */
	is_tripped = 0;

	if (!(f = (PyObject *)PyEval_GetFrame()))
		f = Py_None;

	for (i = 1; i < NSIG; i++) {
		if (Handlers[i].tripped) {
			PyObject *result = NULL;
			PyObject *arglist = Py_BuildValue("(iO)", i, f);
			Handlers[i].tripped = 0;

			if (arglist) {
				result = PyEval_CallObject(Handlers[i].func,
							   arglist);
				Py_DECREF(arglist);
			}
			if (!result)
				return -1;

			Py_DECREF(result);
		}
	}

	return 0;
}
开发者ID:moon2l,项目名称:Python-2.5.6,代码行数:54,代码来源:signalmodule.c


示例15: PyThread_get_thread_ident

void ProtectionData::lock() {
	long myThreadIdent = PyThread_get_thread_ident();
	while(true) {
		PyScopedLock lock(mutex);
		if(lockCounter > 0 && lockThreadIdent != myThreadIdent) {
			usleep(10);
			continue;
		}
		lockCounter++;
		lockThreadIdent = myThreadIdent;
		return;
	}
}
开发者ID:chunqishi,项目名称:music-player,代码行数:13,代码来源:ffmpeg_utils.cpp


示例16: thread_get_ident

static PyObject *
thread_get_ident(PyObject *self, PyObject *args)
{
	long ident;
	if (!PyArg_NoArgs(args))
		return NULL;
	ident = PyThread_get_thread_ident();
	if (ident == -1) {
		PyErr_SetString(ThreadError, "no current thread ident");
		return NULL;
	}
	return PyInt_FromLong(ident);
}
开发者ID:weimingtom,项目名称:SimpleScriptSystem,代码行数:13,代码来源:threadmodule.c


示例17: PyOS_InterruptOccurred

int
PyOS_InterruptOccurred(void)
{
	if (Handlers[SIGINT].tripped) {
#ifdef WITH_THREAD
		if (PyThread_get_thread_ident() != main_thread)
			return 0;
#endif
		Handlers[SIGINT].tripped = 0;
		return 1;
	}
	return 0;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:13,代码来源:signalmodule.c


示例18: MPyEmbed_Run

int MPyEmbed_Run(char *file) {
	FILE *fp;
	if (!PythonAvailable) {
		return 0;
	}
	fp = fopen(file, "r");
	if (!fp) {
		perror("fopen");
		return 0;
	}
	mainstate->thread_id = PyThread_get_thread_ident();
	PyEval_AcquireThread(mainstate);
	PyRun_SimpleFile(fp, file);
	PyEval_ReleaseThread(mainstate);
	fclose(fp);
	return 1;
}
开发者ID:Plombo,项目名称:dega,代码行数:17,代码来源:embed.c


示例19: signal_signal

static PyObject *
signal_signal(PyObject *self, PyObject *args)
{
	PyObject *obj;
	int sig_num;
	PyObject *old_handler;
	void (*func)(int);
	if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj))
		return NULL;
#ifdef WITH_THREAD
	if (PyThread_get_thread_ident() != main_thread) {
		PyErr_SetString(PyExc_ValueError,
				"signal only works in main thread");
		return NULL;
	}
#endif
	if (sig_num < 1 || sig_num >= NSIG) {
		PyErr_SetString(PyExc_ValueError,
				"signal number out of range");
		return NULL;
	}
	if (obj == IgnoreHandler)
		func = SIG_IGN;
	else if (obj == DefaultHandler)
		func = SIG_DFL;
	else if (!PyCallable_Check(obj)) {
		PyErr_SetString(PyExc_TypeError,
"signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object");
		return NULL;
	}
	else
		func = signal_handler;
#ifdef HAVE_SIGINTERRUPT
	siginterrupt(sig_num, 1);
#endif
	if (PyOS_setsig(sig_num, func) == SIG_ERR) {
		PyErr_SetFromErrno(PyExc_RuntimeError);
		return NULL;
	}
	old_handler = Handlers[sig_num].func;
	Handlers[sig_num].tripped = 0;
	Py_INCREF(obj);
	Handlers[sig_num].func = obj;
	return old_handler;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:45,代码来源:signalmodule.c


示例20: Lock_acquire

static PyObject *
Lock_acquire(Lock *self, PyObject *args, PyObject *kwds)
{
    double timeout = -1;
    acquire_result res;

    if (parse_acquire_args(args, kwds, &timeout))
        return NULL;

    res = acquire_lock(&self->sem, timeout);
    if (res == ACQUIRE_ERROR)
        return NULL;

    if (res == ACQUIRE_OK)
        self->owner = PyThread_get_thread_ident();

    return PyBool_FromLong(res == ACQUIRE_OK);
}
开发者ID:mureinik,项目名称:cthreading,代码行数:18,代码来源:_cthreading.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyThread_release_lock函数代码示例发布时间:2022-05-30
下一篇:
C++ PyThread_get_key_value函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap