00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00035 #ifndef _PTHREAD_PRAQ_H_
00036 #define _PTHREAD_PRAQ_H_
00037
00038
00039 #include <pthread.h>
00040 #include <unistd.h>
00041
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00047
00051 enum
00052 {
00056 PTHREAD_PRAQ_NONBLOCKING,
00057
00061 PTHREAD_PRAQ_BLOCKING
00062
00063 };
00064
00068 #define PTHREAD_PRAQ_NONBLOCKING PTHREAD_PRAQ_NONBLOCKING
00069
00073 #define PTHREAD_PRAQ_BLOCKING PTHREAD_PRAQ_BLOCKING
00074
00078 typedef struct
00079 {
00083 pthread_mutexattr_t mutex_attr;
00084
00088 pthread_condattr_t cond_attr;
00089
00093 int pshared;
00094
00098 int block;
00099
00100 } pthread_praqattr_t;
00101
00102
00106 struct praq_data_t
00107 {
00111 void * data;
00112
00116 int order_id;
00117 };
00118
00119
00123 typedef struct
00124 {
00128 pthread_mutex_t lock;
00129
00133 pthread_cond_t not_full_cond;
00134
00138 pthread_cond_t not_empty_cond;
00139
00143 struct praq_data_t * queue;
00144
00148 int front;
00149
00153 int length;
00154
00158 int max_length;
00159
00163 int queue_full_wait;
00164
00168 int queue_empty_wait;
00169
00173 int order_id;
00174
00178 int block;
00179
00180 #ifdef CTF_STATS
00181
00184 int total_count;
00185
00189 int total_acquire_wait_count;
00190
00194 int total_propose_wait_count;
00195
00199 float total_acquire_wait;
00200
00204 float total_propose_wait;
00205 #endif
00206
00207 } pthread_praq_t;
00208
00209
00219 extern int pthread_praq_init(pthread_praq_t * praq,
00220 const pthread_praqattr_t * attr, const int length);
00221
00229 extern int pthread_praq_destroy(pthread_praq_t * praq);
00230
00239 extern int pthread_praq_acquire(pthread_praq_t * praq,
00240 void ** data);
00241
00250 extern int pthread_praq_propose(pthread_praq_t * praq, const int order_num);
00251
00261 extern int pthread_praq_release(pthread_praq_t * praq,
00262 const int order_num, void * data);
00263
00271 extern int pthread_praq_reset(pthread_praq_t * praq);
00272
00280 extern int pthread_praqattr_init(pthread_praqattr_t * attr);
00281
00289 extern int pthread_praqattr_destroy(pthread_praqattr_t * attr);
00290
00299 extern int pthread_praqattr_getblock(const pthread_praqattr_t * attr,
00300 int * block);
00301
00310 extern int pthread_praqattr_setblock(pthread_praqattr_t * attr,
00311 const int block);
00312
00313 #if (_POSIX_THREAD_PROCESS_SHARED == 1)
00314
00322 extern int pthread_praqattr_getpshared(const pthread_praqattr_t * attr,
00323 int * pshared);
00324
00333 extern int pthread_praqattr_setpshared(pthread_praqattr_t * attr,
00334 const int pshared);
00335 #endif
00336
00337 #ifdef __cplusplus
00338 }
00339 #endif
00340
00341 #endif