| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /************************************************************************
- * AUTHOR: NiuJiuRu
- * FILENAME: swthrd.h
- * DESCRIPTION: 线程操作
- * NOTE:
- * HISTORY:
- * 1, [2010-09-07] created by NiuJiuRu
- ***********************************************************************/
- #ifndef __SWTHRD_H__
- #define __SWTHRD_H__
- // thread's default satck size
- #define THREAD_DEFAULT_STACK_SIZE 65536
- // thread's default priority
- #define THREAD_DEFAULT_PRIORITY 50
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- /* 线程的(用户)回调函数, 会被反复调用("返回值 < 0"时表示退出线程; "返回值 >= 0"表示延时一段时间(ms)后继续运行) */
- typedef int (*PThrdProc)(unsigned long wParam, unsigned long lParam);
- /* 创建线程, 成功后默认处于暂停状态 */
- void *sw_thrd_create(const char *name, int priority, int stack_size, PThrdProc proc,
- unsigned long wParam, unsigned long lParam);
- /* 销毁线程, 在"wait time <= timout(ms)"前尝试安全的关闭线程, "wait time > timout"后则强制关闭 */
- void sw_thrd_destroy(void *hThrd, int timeout);
- /* 暂停运行线程 */
- void sw_thrd_pause(void *hThrd);
- /* 继续运行线程 */
- void sw_thrd_resume(void *hThrd);
- /* 延时(毫秒) */
- void sw_thrd_delay(int ms);
- /* 检查线程是否还存在 */
- bool sw_thrd_isAlive(void *hThrd);
- /* 检查线程是否正在运行: true = 是, false = 否 */
- bool sw_thrd_isRunning(void *hThrd);
- /* 检查线程是否正在执行(用户)回调函数还没有返回: true = 是, false = 否 */
- bool sw_thrd_isBusy(void *hThrd);
- /* 设置线程名称 */
- bool sw_thrd_setName(void *hThrd, const char *name);
- /* 取得线程名称 */
- char *sw_thrd_getName(void *hThrd, char *name);
- /* 设置线程优先级 */
- bool sw_thrd_setPriority(void *hThrd, int priority);
- /* 取得线程优先级 */
- int sw_thrd_getPriority(void *hThrd);
- /* 设置线程执行的(用户)回调函数 */
- bool sw_thrd_setProc(void *hThrd, PThrdProc proc, unsigned long wParam, unsigned long lParam);
- /* 取得线程执行的(用户)回调函数 */
- void sw_thrd_getProc(void *hThrd, PThrdProc *proc, unsigned long *wParam, unsigned long *lParam);
- #ifdef __cplusplus
- }
- #endif
- #endif /* __SWTHRD_H__ */
|