00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00034 #ifndef _PTHREAD_MGATE_
00035 #define _PTHREAD_MGATE_
00036
00037
00038 #include <pthread.h>
00039 #include <unistd.h>
00040
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00046
00050 typedef struct
00051 {
00055 pthread_mutexattr_t mutex_attr;
00056
00060 pthread_condattr_t cond_attr;
00061
00065 int pshared;
00066
00067 } pthread_mgateattr_t;
00068
00069
00073 struct mgate_data_t
00074 {
00078 int order;
00079
00083 int gate;
00084
00088 int wait;
00089
00093 short token;
00094
00098 pthread_cond_t cond;
00099 };
00100
00101
00105 typedef struct
00106 {
00110 pthread_mutex_t lock;
00111
00115 struct mgate_data_t * data;
00116
00120 int num_gates;
00121
00125 int next_order;
00126
00127 #ifdef CTF_STATS
00128
00131 int total_pass_count;
00132
00136 int total_wait_count;
00137
00141 float total_wait;
00142 #endif
00143
00144 } pthread_mgate_t;
00145
00146
00156 extern int pthread_mgate_init(pthread_mgate_t * mgate,
00157 const pthread_mgateattr_t * attr, const int num_gates);
00158
00166 extern int pthread_mgate_destroy(pthread_mgate_t * mgate);
00167
00177 extern int pthread_mgate_check(pthread_mgate_t * mgate, const int gate_index,
00178 const int check_index);
00179
00189 extern int pthread_mgate_update(pthread_mgate_t * mgate,
00190 const int gate_index, const int update_index);
00191
00201 extern int pthread_mgate_pass(pthread_mgate_t * mgate,
00202 const int gate_index, int * order_number);
00203
00211 extern int pthread_mgate_reset(pthread_mgate_t * mgate);
00212
00220 extern int pthread_mgateattr_init(pthread_mgateattr_t * attr);
00221
00229 extern int pthread_mgateattr_destroy(pthread_mgateattr_t * attr);
00230
00231 #if (_POSIX_THREAD_PROCESS_SHARED == 1)
00232
00240 extern int pthread_mgateattr_getpshared(const pthread_mgateattr_t * attr,
00241 int * pshared);
00242
00251 extern int pthread_mgateattr_setpshared(pthread_mgateattr_t * attr,
00252 const int pshared);
00253 #endif
00254
00255 #ifdef __cplusplus
00256 }
00257 #endif
00258
00259 #endif