开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python
/
Python
/
thread_pth.h
python
/
Python
/
thread_pth.h
thread_pth.h 5.15 KB
一键复制 编辑 原始数据 按行查看 历史
feng 提交于 2015年10月01日 10:15 +08:00 . python
/* GNU pth threads interface
http://www.gnu.org/software/pth
2000年05月03日 Andy Dustman <andy@dustman.net>
Adapted from Posix threads interface
12 May 1997 -- david arnold <davida@pobox.com>
*/
#include <stdlib.h>
#include <string.h>
#include <pth.h>
/* A pth mutex isn't sufficient to model the Python lock type
* because pth mutexes can be acquired multiple times by the
* same thread.
*
* The pth_lock struct implements a Python lock as a "locked?" bit
* and a <condition, mutex> pair. In general, if the bit can be acquired
* instantly, it is, else the pair is used to block the thread until the
* bit is cleared.
*/
typedef struct {
char locked; /* 0=unlocked, 1=locked */
/* a <cond, mutex> pair to handle an acquire of a locked lock */
pth_cond_t lock_released;
pth_mutex_t mut;
} pth_lock;
#define CHECK_STATUS(name) if (status == -1) { printf("%d ", status); perror(name); error = 1; }
pth_attr_t PyThread_attr;
/*
* Initialization.
*/
static void PyThread__init_thread(void)
{
pth_init();
PyThread_attr = pth_attr_new();
pth_attr_set(PyThread_attr, PTH_ATTR_STACK_SIZE, 1<<18);
pth_attr_set(PyThread_attr, PTH_ATTR_JOINABLE, FALSE);
}
/*
* Thread support.
*/
long PyThread_start_new_thread(void (*func)(void *), void *arg)
{
pth_t th;
dprintf(("PyThread_start_new_thread called\n"));
if (!initialized)
PyThread_init_thread();
th = pth_spawn(PyThread_attr,
(void* (*)(void *))func,
(void *)arg
);
return th;
}
long PyThread_get_thread_ident(void)
{
volatile pth_t threadid;
if (!initialized)
PyThread_init_thread();
/* Jump through some hoops for Alpha OSF/1 */
threadid = pth_self();
return (long) *(long *) &threadid;
}
static void do_PyThread_exit_thread(int no_cleanup)
{
dprintf(("PyThread_exit_thread called\n"));
if (!initialized) {
if (no_cleanup)
_exit(0);
else
exit(0);
}
}
void PyThread_exit_thread(void)
{
do_PyThread_exit_thread(0);
}
void PyThread__exit_thread(void)
{
do_PyThread_exit_thread(1);
}
#ifndef NO_EXIT_PROG
static void do_PyThread_exit_prog(int status, int no_cleanup)
{
dprintf(("PyThread_exit_prog(%d) called\n", status));
if (!initialized)
if (no_cleanup)
_exit(status);
else
exit(status);
}
void PyThread_exit_prog(int status)
{
do_PyThread_exit_prog(status, 0);
}
void PyThread__exit_prog(int status)
{
do_PyThread_exit_prog(status, 1);
}
#endif /* NO_EXIT_PROG */
/*
* Lock support.
*/
PyThread_type_lock PyThread_allocate_lock(void)
{
pth_lock *lock;
int status, error = 0;
dprintf(("PyThread_allocate_lock called\n"));
if (!initialized)
PyThread_init_thread();
lock = (pth_lock *) malloc(sizeof(pth_lock));
memset((void *)lock, '0円', sizeof(pth_lock));
if (lock) {
lock->locked = 0;
status = pth_mutex_init(&lock->mut);
CHECK_STATUS("pth_mutex_init");
status = pth_cond_init(&lock->lock_released);
CHECK_STATUS("pth_cond_init");
if (error) {
free((void *)lock);
lock = NULL;
}
}
dprintf(("PyThread_allocate_lock() -> %p\n", lock));
return (PyThread_type_lock) lock;
}
void PyThread_free_lock(PyThread_type_lock lock)
{
pth_lock *thelock = (pth_lock *)lock;
dprintf(("PyThread_free_lock(%p) called\n", lock));
free((void *)thelock);
}
int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
{
int success;
pth_lock *thelock = (pth_lock *)lock;
int status, error = 0;
dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
status = pth_mutex_acquire(&thelock->mut, !waitflag, NULL);
CHECK_STATUS("pth_mutex_acquire[1]");
success = thelock->locked == 0;
if (success) thelock->locked = 1;
status = pth_mutex_release( &thelock->mut );
CHECK_STATUS("pth_mutex_release[1]");
if ( !success && waitflag ) {
/* continue trying until we get the lock */
/* mut must be locked by me -- part of the condition
* protocol */
status = pth_mutex_acquire( &thelock->mut, !waitflag, NULL );
CHECK_STATUS("pth_mutex_acquire[2]");
while ( thelock->locked ) {
status = pth_cond_await(&thelock->lock_released,
&thelock->mut, NULL);
CHECK_STATUS("pth_cond_await");
}
thelock->locked = 1;
status = pth_mutex_release( &thelock->mut );
CHECK_STATUS("pth_mutex_release[2]");
success = 1;
}
if (error) success = 0;
dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
return success;
}
void PyThread_release_lock(PyThread_type_lock lock)
{
pth_lock *thelock = (pth_lock *)lock;
int status, error = 0;
dprintf(("PyThread_release_lock(%p) called\n", lock));
status = pth_mutex_acquire( &thelock->mut, 0, NULL );
CHECK_STATUS("pth_mutex_acquire[3]");
thelock->locked = 0;
status = pth_mutex_release( &thelock->mut );
CHECK_STATUS("pth_mutex_release[3]");
/* wake up someone (anyone, if any) waiting on the lock */
status = pth_cond_notify( &thelock->lock_released, 0 );
CHECK_STATUS("pth_cond_notify");
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

github.com clone
暂无标签
未知许可证
查看未知开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yf33/python.git
git@gitee.com:yf33/python.git
yf33
python
python
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /