00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00035 #ifndef _PTHREAD_FIFO_MUTEX_
00036 #define _PTHREAD_FIFO_MUTEX_
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_FIFO_MUTEX_NONBLOCKING,
00057
00061 PTHREAD_FIFO_MUTEX_BLOCKING,
00062
00066 PTHREAD_FIFO_MUTEX_DEFAULT = PTHREAD_FIFO_MUTEX_BLOCKING
00067 };
00068
00072 #define PTHREAD_FIFO_MUTEX_NONBLOCKING PTHREAD_FIFO_MUTEX_NONBLOCKING
00073
00077 #define PTHREAD_FIFO_MUTEX_BLOCKING PTHREAD_FIFO_MUTEX_BLOCKING
00078
00082 #define PTHREAD_FIFO_MUTEX_DEFAULT PTHREAD_FIFO_MUTEX_DEFAULT
00083
00084
00088 typedef struct
00089 {
00093 pthread_mutexattr_t mutex_attr;
00094
00098 pthread_condattr_t cond_attr;
00099
00103 int pshared;
00104
00108 int block;
00109
00110 } pthread_fifo_mutexattr_t;
00111
00112
00116 struct fifo_data_t
00117 {
00121 pthread_t tid;
00122
00126 pthread_cond_t cond;
00127 };
00128
00129
00133 typedef struct
00134 {
00138 pthread_mutex_t lock;
00139
00143 pthread_cond_t cond;
00144
00148 struct fifo_data_t * queue;
00149
00153 int front;
00154
00158 int back;
00159
00163 int length;
00164
00168 int max_length;
00169
00173 int queue_full_wait;
00174
00178 short locked;
00179
00183 int block;
00184
00185 #ifdef CTF_STATS
00186
00189 int total_pass_count;
00190
00194 int total_wait_count;
00195
00199 float total_wait;
00200
00201
00205 float total_locked;
00206 #endif
00207
00208 } pthread_fifo_mutex_t;
00209
00210
00220 extern int pthread_fifo_mutex_init(pthread_fifo_mutex_t * mutex,
00221 const pthread_fifo_mutexattr_t * attr, const int length);
00222
00230 extern int pthread_fifo_mutex_destroy(pthread_fifo_mutex_t * mutex);
00231
00239 extern int pthread_fifo_mutex_lock(pthread_fifo_mutex_t * mutex);
00240
00248 extern int pthread_fifo_mutex_trylock(pthread_fifo_mutex_t * mutex);
00249
00258 extern int pthread_fifo_mutex_timedlock(pthread_fifo_mutex_t * mutex,
00259 const struct timespec * abstime);
00260
00268 extern int pthread_fifo_mutex_unlock(pthread_fifo_mutex_t * mutex);
00269
00270 #if (_POSIX_THREAD_PRIO_PROTECT == 1)
00271
00279 extern int pthread_fifo_mutex_getprioceiling(const pthread_fifo_mutex_t * mutex,
00280 int * prioceiling);
00281
00292 extern int pthread_fifo_mutex_setprioceiling(pthread_fifo_mutex_t * mutex,
00293 const int prioceiling, int * old_ceiling);
00294 #endif
00295
00303 extern int pthread_fifo_mutexattr_init(pthread_fifo_mutexattr_t * attr);
00304
00312 extern int pthread_fifo_mutexattr_destroy(pthread_fifo_mutexattr_t * attr);
00313
00322 extern int pthread_fifo_mutexattr_getblock(const pthread_fifo_mutexattr_t * attr,
00323 int * block);
00324
00333 extern int pthread_fifo_mutexattr_setblock(pthread_fifo_mutexattr_t * attr,
00334 const int block);
00335
00336 #if (_POSIX_THREAD_PROCESS_SHARED == 1)
00337
00345 extern int pthread_fifo_mutexattr_getpshared(const pthread_fifo_mutexattr_t * attr,
00346 int * pshared);
00347
00356 extern int pthread_fifo_mutexattr_setpshared(pthread_fifo_mutexattr_t * attr,
00357 const int pshared);
00358 #endif
00359
00360 #if (_POSIX_THREAD_PRIO_PROTECT == 1)
00361
00369 extern int pthread_fifo_mutexattr_getprioceiling(const pthread_fifo_mutexattr_t * attr,
00370 int * prioceiling);
00371
00380 extern int pthread_fifo_mutexattr_setprioceiling(pthread_fifo_mutexattr_t * attr,
00381 const int prioceiling);
00382
00383 #if (_POSIX_THREAD_PRIO_INHERIT == 1)
00384
00392 extern int pthread_fifo_mutexattr_getprotocol(const pthread_fifo_mutexattr_t * attr,
00393 int * protocol);
00394
00403 extern int pthread_fifo_mutexattr_setprotocol(pthread_fifo_mutexattr_t * attr,
00404 const int protocol);
00405 #endif
00406 #endif
00407
00408 #ifdef __cplusplus
00409 }
00410 #endif
00411
00412 #endif