正在显示
1 个修改的文件
包含
101 行增加
和
0 行删除
src/server/spserver/spthread.hpp
0 → 100644
1 | + | ||
2 | +#ifndef __spthread_hpp__ | ||
3 | +#define __spthread_hpp__ | ||
4 | + | ||
5 | +#ifndef WIN32 | ||
6 | + | ||
7 | +/// pthread | ||
8 | + | ||
9 | +#include <pthread.h> | ||
10 | +#include <unistd.h> | ||
11 | + | ||
12 | +typedef void * sp_thread_result_t; | ||
13 | +typedef pthread_mutex_t sp_thread_mutex_t; | ||
14 | +typedef pthread_cond_t sp_thread_cond_t; | ||
15 | +typedef pthread_t sp_thread_t; | ||
16 | +typedef pthread_attr_t sp_thread_attr_t; | ||
17 | + | ||
18 | +#define sp_thread_mutex_init pthread_mutex_init | ||
19 | +#define sp_thread_mutex_destroy pthread_mutex_destroy | ||
20 | +#define sp_thread_mutex_lock pthread_mutex_lock | ||
21 | +#define sp_thread_mutex_unlock pthread_mutex_unlock | ||
22 | + | ||
23 | +#define sp_thread_cond_init pthread_cond_init | ||
24 | +#define sp_thread_cond_destroy pthread_cond_destroy | ||
25 | +#define sp_thread_cond_wait pthread_cond_wait | ||
26 | +#define sp_thread_cond_signal pthread_cond_signal | ||
27 | + | ||
28 | +#define sp_thread_attr_init pthread_attr_init | ||
29 | +#define sp_thread_attr_destroy pthread_attr_destroy | ||
30 | +#define sp_thread_attr_setdetachstate pthread_attr_setdetachstate | ||
31 | +#define SP_THREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED | ||
32 | +#define sp_thread_attr_setstacksize pthread_attr_setstacksize | ||
33 | + | ||
34 | +#define sp_thread_self pthread_self | ||
35 | +#define sp_thread_create pthread_create | ||
36 | + | ||
37 | +#define SP_THREAD_CALL | ||
38 | +typedef sp_thread_result_t ( * sp_thread_func_t )( void * args ); | ||
39 | + | ||
40 | +#ifndef sp_sleep | ||
41 | +#define sp_sleep(x) sleep(x) | ||
42 | +#endif | ||
43 | + | ||
44 | +#else /////////////////////////////////////////////////////////////////////// | ||
45 | + | ||
46 | +// win32 thread | ||
47 | + | ||
48 | +#include <winsock2.h> | ||
49 | +#include <process.h> | ||
50 | + | ||
51 | +#ifdef __cplusplus | ||
52 | +extern "C" { | ||
53 | +#endif | ||
54 | + | ||
55 | +typedef unsigned sp_thread_t; | ||
56 | + | ||
57 | +typedef unsigned sp_thread_result_t; | ||
58 | +#define SP_THREAD_CALL __stdcall | ||
59 | +typedef sp_thread_result_t ( __stdcall * sp_thread_func_t )( void * args ); | ||
60 | + | ||
61 | +typedef HANDLE sp_thread_mutex_t; | ||
62 | +typedef HANDLE sp_thread_cond_t; | ||
63 | + | ||
64 | +//typedef DWORD sp_thread_attr_t; | ||
65 | +typedef struct tagsp_thread_attr { | ||
66 | + int stacksize; | ||
67 | + int detachstate; | ||
68 | +} sp_thread_attr_t; | ||
69 | + | ||
70 | +#define SP_THREAD_CREATE_DETACHED 1 | ||
71 | + | ||
72 | +#ifndef sp_sleep | ||
73 | +#define sp_sleep(x) Sleep(1000*x) | ||
74 | +#endif | ||
75 | + | ||
76 | +int sp_thread_mutex_init( sp_thread_mutex_t * mutex, void * attr ); | ||
77 | +int sp_thread_mutex_destroy( sp_thread_mutex_t * mutex ); | ||
78 | +int sp_thread_mutex_lock( sp_thread_mutex_t * mutex ); | ||
79 | +int sp_thread_mutex_unlock( sp_thread_mutex_t * mutex ); | ||
80 | + | ||
81 | +int sp_thread_cond_init( sp_thread_cond_t * cond, void * attr ); | ||
82 | +int sp_thread_cond_destroy( sp_thread_cond_t * cond ); | ||
83 | +int sp_thread_cond_wait( sp_thread_cond_t * cond, sp_thread_mutex_t * mutex ); | ||
84 | +int sp_thread_cond_signal( sp_thread_cond_t * cond ); | ||
85 | + | ||
86 | +int sp_thread_attr_init( sp_thread_attr_t * attr ); | ||
87 | +int sp_thread_attr_destroy( sp_thread_attr_t * attr ); | ||
88 | +int sp_thread_attr_setdetachstate( sp_thread_attr_t * attr, int detachstate ); | ||
89 | +int sp_thread_attr_setstacksize( sp_thread_attr_t * attr, size_t stacksize ); | ||
90 | + | ||
91 | +int sp_thread_create( sp_thread_t * thread, sp_thread_attr_t * attr, | ||
92 | + sp_thread_func_t myfunc, void * args ); | ||
93 | +sp_thread_t sp_thread_self(); | ||
94 | + | ||
95 | +#ifdef __cplusplus | ||
96 | +} | ||
97 | +#endif | ||
98 | + | ||
99 | +#endif | ||
100 | + | ||
101 | +#endif |
请
注册
或
登录
后发表评论