acl  3.5.3.0
acl_pthread.h
浏览该文件的文档.
1 #ifndef __ACL_PTHREAD_INCLUDE_H__
2 #define __ACL_PTHREAD_INCLUDE_H__
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "../stdlib/acl_define.h"
9 
10 #define ACL_MUTEX_MAXWAIT (~(unsigned int)0)
11 #ifdef ACL_HAS_PTHREAD
12 
13 #ifdef ACL_UNIX
14 # ifndef _GNU_SOURCE
15 # define _GNU_SOURCE
16 # endif
17 #endif
18 # include <pthread.h>
19 
20 typedef pthread_t acl_pthread_t;
21 typedef pthread_attr_t acl_pthread_attr_t;
22 typedef pthread_mutex_t acl_pthread_mutex_t;
23 typedef pthread_cond_t acl_pthread_cond_t;
24 typedef pthread_mutexattr_t acl_pthread_mutexattr_t;
25 typedef pthread_condattr_t acl_pthread_condattr_t;
26 typedef pthread_key_t acl_pthread_key_t;
27 typedef pthread_once_t acl_pthread_once_t;
28 
29 #define acl_pthread_attr_init pthread_attr_init
30 #define acl_pthread_attr_setstacksize pthread_attr_setstacksize
31 #define acl_pthread_attr_setdetachstate pthread_attr_setdetachstate
32 #define acl_pthread_attr_destroy pthread_attr_destroy
33 #define acl_pthread_self pthread_self
34 #define acl_pthread_create pthread_create
35 #define acl_pthread_detach pthread_detach
36 #define acl_pthread_once pthread_once
37 #define acl_pthread_join pthread_join
38 #define acl_pthread_mutex_init pthread_mutex_init
39 #define acl_pthread_mutex_destroy pthread_mutex_destroy
40 #define acl_pthread_mutex_lock pthread_mutex_lock
41 #define acl_pthread_mutex_unlock pthread_mutex_unlock
42 #define acl_pthread_mutex_trylock pthread_mutex_trylock
43 #define acl_pthread_cond_init pthread_cond_init
44 #define acl_pthread_cond_destroy pthread_cond_destroy
45 #define acl_pthread_cond_signal pthread_cond_signal
46 #define acl_pthread_cond_broadcast pthread_cond_broadcast
47 #define acl_pthread_cond_timedwait pthread_cond_timedwait
48 #define acl_pthread_cond_wait pthread_cond_wait
49 #define acl_pthread_key_create pthread_key_create
50 #define acl_pthread_getspecific pthread_getspecific
51 #define acl_pthread_setspecific pthread_setspecific
52 
53 #define ACL_PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
54 #define ACL_PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
55 #define ACL_TLS_OUT_OF_INDEXES 0xffffffff
56 #define ACL_PTHREAD_KEYS_MAX PTHREAD_KEYS_MAX
57 #ifdef ACL_SUNOS5
58 # define ACL_PTHREAD_ONCE_INIT { PTHREAD_ONCE_INIT }
59 #else
60 # define ACL_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
61 #endif
62 
63 #else
64 
65 #include <time.h>
66 
67 #include "acl_sem.h"
68 
69 #define ACL_PTHREAD_CREATE_DETACHED 1
70 #define ACL_PTHREAD_CREATE_JOINABLE 0
71 #define ACL_TLS_OUT_OF_INDEXES 0xffffffff
72 #define ACL_PTHREAD_KEYS_MAX 1024
73 #define ACL_PTHREAD_ONCE_INIT 0
74 
81 typedef int acl_pthread_key_t;
82 typedef int acl_pthread_once_t;
83 
84 struct acl_pthread_t {
85  unsigned long id;
86  HANDLE handle;
87  void *(*start_routine)(void *);
88  void *routine_arg;
89  char detached;
90 };
91 
93  SECURITY_ATTRIBUTES attr;
94  size_t stacksize;
95  char detached;
96 };
97 
99  HANDLE id;
100  char dynamic;
101 };
102 
104  SECURITY_ATTRIBUTES attr;
105 };
106 
109  int waiting;
110  int nsignal;
111  ACL_SEM *wait_sem;
112  ACL_SEM *wait_done;
113  char dynamic;
114 };
115 
117  char unused_name[1];
118 };
119 
120 # if _MSC_VER < 1900
121 struct timespec {
122  time_t tv_sec; /* Seconds. */
123  long int tv_nsec; /* Nanoseconds. */
124 };
125 #endif
126 
127 /* in acl_pthread.c */
128 ACL_API void acl_pthread_end(void);
129 ACL_API int acl_pthread_once(acl_pthread_once_t *once_control,
130  void (*init_routine)(void));
131 ACL_API int acl_pthread_key_create(acl_pthread_key_t *key_ptr,
132  void (*destructor)(void*));
133 ACL_API void *acl_pthread_getspecific(acl_pthread_key_t key);
134 ACL_API int acl_pthread_setspecific(acl_pthread_key_t key, void *value);
135 ACL_API int acl_pthread_attr_init(acl_pthread_attr_t *attr);
137  size_t stacksize);
139  int detached);
140 ACL_API int acl_pthread_attr_destroy(acl_pthread_attr_t *thr_attr);
141 ACL_API unsigned long acl_pthread_self(void);
142 ACL_API int acl_pthread_create(acl_pthread_t *thread,
143  acl_pthread_attr_t *attr, void * (*start_routine)(void *),
144  void *arg);
145 ACL_API int acl_pthread_detach(acl_pthread_t thread);
146 ACL_API int acl_pthread_join(acl_pthread_t thread, void **thread_return);
147 
148 /* in acl_pthread_mutex.c */
150  const acl_pthread_mutexattr_t *mattr);
152 ACL_API int acl_pthread_mutex_lock(acl_pthread_mutex_t *mutex);
154 
155 #define acl_pthread_mutex_trylock acl_pthread_mutex_lock
156 
157 /* in acl_pthread_cond.c */
158 ACL_API int acl_pthread_cond_init(acl_pthread_cond_t *cond,
159  acl_pthread_condattr_t *cond_attr);
161 #ifndef acl_pthread_cond_create
162 #define acl_pthread_cond_create acl_thread_cond_create
163 #endif
164 
169  acl_pthread_mutex_t *mutex, const struct timespec *timeout);
170 ACL_API int acl_pthread_cond_wait(acl_pthread_cond_t *cond,
171  acl_pthread_mutex_t *mutex);
172 
173 #endif /* !ACL_HAS_PTHREAD */
174 
175 /* general functions */
176 
177 /* in acl_pthread_mutex.c */
178 ACL_API int acl_thread_mutex_lock(acl_pthread_mutex_t *mutex);
179 ACL_API int acl_thread_mutex_unlock(acl_pthread_mutex_t *mutex);
180 ACL_API int acl_thread_mutex_nested(acl_pthread_mutex_t *mutex);
181 
182 /* in acl_pthread.c */
183 ACL_API int acl_pthread_atexit_add(void *arg, void (*free_callback)(void*));
184 ACL_API int acl_pthread_atexit_remove(void *arg, void (*free_callback)(void*));
185 
186 ACL_API int acl_pthread_tls_set_max(int max);
187 ACL_API int acl_pthread_tls_get_max(void);
188 ACL_API void *acl_pthread_tls_get(acl_pthread_key_t *key_ptr);
189 ACL_API int acl_pthread_tls_set(acl_pthread_key_t key, void *ptr,
190  void (*free_fn)(void *));
191 ACL_API int acl_pthread_tls_del(acl_pthread_key_t key);
192 ACL_API void acl_pthread_tls_once_get(acl_pthread_once_t *control_once);
193 ACL_API void acl_pthread_tls_once_set(acl_pthread_once_t control_once);
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif
ACL_API void acl_pthread_end(void)
ACL_API int acl_pthread_cond_broadcast(acl_pthread_cond_t *cond)
ACL_API int acl_pthread_attr_destroy(acl_pthread_attr_t *thr_attr)
HANDLE handle
Definition: acl_pthread.h:86
struct acl_pthread_condattr_t acl_pthread_condattr_t
Definition: acl_pthread.h:80
unsigned long id
Definition: acl_pthread.h:85
ACL_API int acl_pthread_setspecific(acl_pthread_key_t key, void *value)
ACL_API int acl_thread_mutex_nested(acl_pthread_mutex_t *mutex)
SECURITY_ATTRIBUTES attr
Definition: acl_pthread.h:93
acl_pthread_mutex_t * lock
Definition: acl_pthread.h:108
ACL_API int acl_pthread_mutex_init(acl_pthread_mutex_t *mutex, const acl_pthread_mutexattr_t *mattr)
ACL_API int acl_pthread_attr_setdetachstate(acl_pthread_attr_t *attr, int detached)
ACL_API int acl_pthread_tls_del(acl_pthread_key_t key)
ACL_API int acl_pthread_detach(acl_pthread_t thread)
ACL_API int acl_pthread_once(acl_pthread_once_t *once_control, void(*init_routine)(void))
int acl_pthread_once_t
Definition: acl_pthread.h:82
ACL_API int acl_pthread_cond_init(acl_pthread_cond_t *cond, acl_pthread_condattr_t *cond_attr)
ACL_API int acl_pthread_create(acl_pthread_t *thread, acl_pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
time_t tv_sec
Definition: acl_pthread.h:122
ACL_API int acl_pthread_cond_signal(acl_pthread_cond_t *cond)
struct acl_pthread_mutexattr_t acl_pthread_mutexattr_t
Definition: acl_pthread.h:79
SECURITY_ATTRIBUTES attr
Definition: acl_pthread.h:104
struct acl_pthread_mutex_t acl_pthread_mutex_t
Definition: acl_pthread.h:77
ACL_API int acl_pthread_atexit_add(void *arg, void(*free_callback)(void *))
ACL_SEM * wait_done
Definition: acl_pthread.h:112
ACL_API int acl_pthread_mutex_unlock(acl_pthread_mutex_t *mutex)
ACL_API int acl_thread_mutex_unlock(acl_pthread_mutex_t *mutex)
ACL_API int acl_pthread_attr_setstacksize(acl_pthread_attr_t *attr, size_t stacksize)
ACL_API void acl_pthread_tls_once_set(acl_pthread_once_t control_once)
ACL_API int acl_pthread_mutex_destroy(acl_pthread_mutex_t *mutex)
ACL_API int acl_pthread_key_create(acl_pthread_key_t *key_ptr, void(*destructor)(void *))
ACL_API void acl_pthread_tls_key_set(acl_pthread_key_t key)
struct acl_pthread_attr_t acl_pthread_attr_t
Definition: acl_pthread.h:76
ACL_API int acl_pthread_tls_set(acl_pthread_key_t key, void *ptr, void(*free_fn)(void *))
ACL_API int acl_thread_mutex_lock(acl_pthread_mutex_t *mutex)
ACL_API int acl_pthread_tls_get_max(void)
ACL_API int acl_pthread_join(acl_pthread_t thread, void **thread_return)
ACL_API int acl_pthread_cond_destroy(acl_pthread_cond_t *cond)
ACL_SEM * wait_sem
Definition: acl_pthread.h:111
ACL_API void * acl_pthread_tls_get(acl_pthread_key_t *key_ptr)
ACL_API int acl_pthread_atexit_remove(void *arg, void(*free_callback)(void *))
ACL_API int acl_pthread_attr_init(acl_pthread_attr_t *attr)
int acl_pthread_key_t
Definition: acl_pthread.h:81
ACL_API acl_pthread_key_t acl_pthread_tls_key_get(void)
ACL_API void * acl_pthread_getspecific(acl_pthread_key_t key)
ACL_API int acl_pthread_tls_set_max(int max)
struct acl_pthread_cond_t acl_pthread_cond_t
Definition: acl_pthread.h:78
ACL_API int acl_pthread_mutex_lock(acl_pthread_mutex_t *mutex)
ACL_API int acl_pthread_cond_wait(acl_pthread_cond_t *cond, acl_pthread_mutex_t *mutex)
ACL_API void acl_pthread_tls_once_get(acl_pthread_once_t *control_once)
struct acl_pthread_t acl_pthread_t
Definition: acl_pthread.h:75
ACL_API unsigned long acl_pthread_self(void)
ACL_API acl_pthread_cond_t * acl_thread_cond_create(void)
ACL_API int acl_pthread_cond_timedwait(acl_pthread_cond_t *cond, acl_pthread_mutex_t *mutex, const struct timespec *timeout)
void * routine_arg
Definition: acl_pthread.h:88
long int tv_nsec
Definition: acl_pthread.h:123