1 Star 0 Fork 0

kasxuzhihui/epoll

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
thread.h 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
kasxuzhihui 提交于 2020-11-10 17:08 . 结构调整
#ifndef __THREAD_H__
#define __THREAD_H__
#ifdef __cplusplus
extern "C" {
#endif
#define OPER_OK 0
#define THREAD_MUTEX_INIT_ERROR -1
#define MUTEX_DESTROY_ERROR -2
#define THREAD_MUTEX_LOCK_ERROR -3
#define THREAD_MUTEX_UNLOCK_ERROR -4
#define THREAD_COND_INIT_ERROR -5
#define COND_DESTROY_ERROR -6
#define COND_SIGNAL_ERROR -7
#define COND_WAIT_ERROR -8
/* Define to prevent recursive inclusion
-------------------------------------*/
#include <pthread.h>
#include<sys/types.h>
#include <time.h>
typedef struct _mutex
{
pthread_mutex_t mutex;
}mutex_t;
typedef struct _cond
{
pthread_cond_t cond;
}cond_t;
typedef pthread_t tid_t;
typedef pthread_attr_t attr_t;
typedef void* (* thread_fun_t)(void*);
typedef struct _thread
{
tid_t tid;
cond_t *cv;
int32_t state;
int32_t stack_size;
attr_t attr;
thread_fun_t fun;
}thread_t;
/* mutex */
extern int32_t mutex_init(mutex_t *m);
extern int32_t mutex_destroy(mutex_t *m);
extern int32_t mutex_lock(mutex_t *m);
extern int32_t mutex_unlock(mutex_t *m);
/* cond */
extern int32_t cond_init(cond_t *c);
extern int32_t cond_destroy(cond_t *c);
extern int32_t cond_signal(cond_t *c);
extern int32_t cond_wait(cond_t *c,mutex_t *m);
//extern int32_t cond_timed_wait(cond_t *c,mutex_t *m,struct timespec* time);
/* thread */
/* 线程的创建,其属性的设置等都封装在里面 */
extern int32_t thread_create(thread_t *t);
//extern int32_t thread_init(thread_t *t);
#define thread_join(t, p) pthread_join(t, p)
#define thread_self() pthread_self()
#define thread_sigmask pthread_sigmask
#ifdef __cplusplus
}
#endif
#endif
/* END OF FILE
---------------------------------------------------------------*/
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kasxuzhihui/epoll.git
git@gitee.com:kasxuzhihui/epoll.git
kasxuzhihui
epoll
epoll
master

搜索帮助