acl  3.5.3.0
fiber_sem.h
浏览该文件的文档.
1 #ifndef FIBER_SEM_INCLUDE_H
2 #define FIBER_SEM_INCLUDE_H
3 
4 #include "fiber_define.h"
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 /* fiber semaphore, thread unsafety, one semaphore can only be used in one
11  * thread, if used in different threads, result is unpredictable */
12 
14 
15 /**
16  * create one fiber semaphore, and binding it with the current thread
17  * @param num {int} the initial value of the semaphore, must >= 0
18  * @return {ACL_FIBER_SEM *}
19  */
21 
22 /**
23  * free fiber semaphore
24  * @param {ACL_FIBER_SEM *}
25  */
27 
28 /**
29  * get the thread binding the specificed fiber sem
30  * @param sem {ACL_FIBER_SEM*} created by acl_fiber_sem_create
31  * @return {unsigned long} thread ID of the thread binding the semaphore
32  */
33 #if !defined(_WIN32) && !defined(_WIN64)
35 #endif
36 
37 /**
38  * set the thread ID the semaphore belongs to, changing the owner of the fiber
39  * semaphore, when this function was called, the value of the semaphore must
40  * be zero, otherwise fatal will happen.
41  * @param sem {ACL_FIBER_SEM*} created by acl_fiber_sem_create
42  * @param {unsigned long} the thread ID to be specificed with the semaphore
43  */
44 FIBER_API void acl_fiber_sem_set_tid(ACL_FIBER_SEM* sem, unsigned long tid);
45 
46 /**
47  * wait for semaphore until > 0, semaphore will be -1 when returned
48  * @param sem {ACL_FIBER_SEM *} created by acl_fiber_sem_create
49  * @return {int} the semaphore value returned, if the caller's thread isn't
50  * same as the semaphore owner's thread, -1 will be returned
51  */
53 
54 /**
55  * try to wait semaphore until > 0, if semaphore is 0, -1 returned immediately,
56  * otherwise semaphore will be decreased 1 and the semaphore's value is returned
57  * @param sem {ACL_FIBER_SEM *} created by acl_fiber_sem_create
58  * @return {int} value(>=0) returned when waiting ok, otherwise -1 will be
59  * returned if the caller's thread isn't same as the semaphore thread or the
60  * semaphore's value is 0
61  */
63 
64 /**
65  * add 1 to the semaphore, if there are other fibers waiting for semaphore,
66  * one waiter will be wakeuped
67  * @param sem {ACL_FIBER_SEM *} created by acl_fiber_sem_create
68  * @return {int} the current semaphore value returned, -1 returned if the
69  * current thread ID is not same as the semaphore's owner ID
70  */
72 
73 /**
74  * get the specificed semaphore's value
75  * @param sem {ACL_FIBER_SEM*} created by acl_fiber_sem_create
76  * @retur {int} current semaphore's value returned
77  */
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
#define FIBER_API
Definition: fiber_define.h:94
FIBER_API void acl_fiber_sem_set_tid(ACL_FIBER_SEM *sem, unsigned long tid)
FIBER_API int acl_fiber_sem_num(ACL_FIBER_SEM *sem)
FIBER_API unsigned long acl_fiber_sem_get_tid(ACL_FIBER_SEM *sem)
FIBER_API ACL_FIBER_SEM * acl_fiber_sem_create(int num)
FIBER_API int acl_fiber_sem_trywait(ACL_FIBER_SEM *sem)
struct ACL_FIBER_SEM ACL_FIBER_SEM
Definition: fiber_sem.h:13
FIBER_API int acl_fiber_sem_wait(ACL_FIBER_SEM *sem)
FIBER_API int acl_fiber_sem_post(ACL_FIBER_SEM *sem)
FIBER_API void acl_fiber_sem_free(ACL_FIBER_SEM *sem)