rendezvous.h

Go to the documentation of this file.
00001 
00018 #ifndef _RENDEZVOUS_H
00019 #define _RENDEZVOUS_H
00020 
00021 #include <pthread.h>
00022 
00026 typedef struct Rendezvous_Obj {
00027     int             count;
00028     pthread_mutex_t mutex;
00029     pthread_cond_t  cond;
00030 } Rendezvous_Obj;
00031 
00035 typedef Rendezvous_Obj *Rendezvous_Handle;
00036 
00040 #define RENDEZVOUS_SUCCESS 0
00041 
00045 #define RENDEZVOUS_FAILURE -1
00046 
00053 static inline void Rendezvous_open(Rendezvous_Handle hRv, int count)
00054 {
00055     pthread_mutex_init(&hRv->mutex, NULL);
00056     pthread_cond_init(&hRv->cond, NULL);
00057 
00058     hRv->count = count;
00059 }
00060 
00069 static inline void Rendezvous_meet(Rendezvous_Handle hRv)
00070 {
00071     pthread_mutex_lock(&hRv->mutex);
00072     hRv->count--;
00073 
00074     if (hRv->count > 0) {
00075         pthread_cond_wait(&hRv->cond, &hRv->mutex);
00076     } 
00077     else {
00078         pthread_cond_broadcast(&hRv->cond);
00079     }
00080 
00081     pthread_mutex_unlock(&hRv->mutex);
00082 }
00083 
00089 static inline void Rendezvous_force(Rendezvous_Handle hRv)
00090 {
00091     pthread_mutex_lock(&hRv->mutex);
00092     pthread_cond_broadcast(&hRv->cond);
00093     pthread_mutex_unlock(&hRv->mutex);
00094 }
00095 
00100 static inline void Rendezvous_close(Rendezvous_Handle hRv)
00101 {
00102     pthread_mutex_destroy(&hRv->mutex);
00103     pthread_cond_destroy(&hRv->cond);
00104 }
00105 
00106 #endif // _RENDEZVOUS_H

Copyright 2006, Texas Instruments Incorporated