X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fglthread%2Fcond.h;h=239c40a49cee34a2d01bbc644706523c3796e190;hb=e9b552cf52b6200633c335b19a2f703f72f8683a;hp=e8ed12ced7c6e8f659a692db90c0231ebcbdac30;hpb=f507f9b0607c290db1efc87893943161e48bd01c;p=gnulib.git diff --git a/lib/glthread/cond.h b/lib/glthread/cond.h index e8ed12ced..239c40a49 100644 --- a/lib/glthread/cond.h +++ b/lib/glthread/cond.h @@ -51,6 +51,8 @@ #include #include +#include +#include #include "glthread/lock.h" @@ -61,7 +63,6 @@ /* Use the POSIX threads library. */ # include -# include # ifdef __cplusplus extern "C" { @@ -122,9 +123,9 @@ extern int glthread_in_use (void); typedef pthread_cond_t gl_cond_t; # define gl_cond_define(STORAGECLASS, NAME) \ - STORAGECLASS pthread_cond_t NAME; + STORAGECLASS gl_cond_t NAME; # define gl_cond_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pthread_cond_t NAME = gl_cond_initializer; + STORAGECLASS gl_cond_t NAME = gl_cond_initializer; # define gl_cond_initializer \ PTHREAD_COND_INITIALIZER # define glthread_cond_init(COND) \ @@ -140,6 +141,10 @@ typedef pthread_cond_t gl_cond_t; # define glthread_cond_destroy(COND) \ (pthread_in_use () ? pthread_cond_destroy (COND) : 0) +# ifdef __cplusplus +} +# endif + #endif /* ========================================================================= */ @@ -149,7 +154,6 @@ typedef pthread_cond_t gl_cond_t; /* Use the GNU Pth threads library. */ # include -# include # ifdef __cplusplus extern "C" { @@ -178,9 +182,9 @@ extern "C" { typedef pth_cond_t gl_cond_t; # define gl_cond_define(STORAGECLASS, NAME) \ - STORAGECLASS pth_cond_t NAME; + STORAGECLASS gl_cond_t NAME; # define gl_cond_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS pth_cond_t NAME = gl_cond_initializer; + STORAGECLASS gl_cond_t NAME = gl_cond_initializer; # define gl_cond_initializer \ PTH_COND_INIT # define glthread_cond_init(COND) \ @@ -196,6 +200,10 @@ typedef pth_cond_t gl_cond_t; # define glthread_cond_destroy(COND) 0 extern int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime); +# ifdef __cplusplus +} +# endif + #endif /* ========================================================================= */ @@ -206,7 +214,6 @@ extern int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, gl_lock_t *lo # include # include -# include # ifdef __cplusplus extern "C" { @@ -233,13 +240,11 @@ extern "C" { /* -------------------------- gl_cond_t datatype -------------------------- */ -#define ETIMEDOUT ETIME - -typedef pthread_cond_t gl_cond_t; +typedef cond_t gl_cond_t; # define gl_cond_define(STORAGECLASS, NAME) \ - STORAGECLASS cond_t NAME; + STORAGECLASS gl_cond_t NAME; # define gl_cond_define_initialized(STORAGECLASS, NAME) \ - STORAGECLASS cond_t NAME = gl_cond_initializer; + STORAGECLASS gl_cond_t NAME = gl_cond_initializer; # define gl_cond_initializer \ DEFAULTCV # define glthread_cond_init(COND) \ @@ -247,13 +252,78 @@ typedef pthread_cond_t gl_cond_t; # define glthread_cond_wait(COND, LOCK) \ (pthread_in_use () ? cond_wait (COND, LOCK) : 0) # define glthread_cond_timedwait(COND, LOCK, ABSTIME) \ - (pthread_in_use () ? cond_timedwait (COND, LOCK, ABSTIME) : 0) + (pthread_in_use () ? glthread_cond_timedwait_multithreaded (COND, LOCK, ABSTIME) : 0) # define glthread_cond_signal(COND) \ (pthread_in_use () ? cond_signal (COND) : 0) # define glthread_cond_broadcast(COND) \ (pthread_in_use () ? cond_broadcast (COND) : 0) # define glthread_cond_destroy(COND) \ (pthread_in_use () ? cond_destroy (COND) : 0) +extern int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WIN32_THREADS + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +/* -------------------------- gl_cond_t datatype -------------------------- */ + +struct gl_waitqueue_link +{ + struct gl_waitqueue_link *wql_next; + struct gl_waitqueue_link *wql_prev; +}; +typedef struct + { + struct gl_waitqueue_link wq_list; /* circular list of waiting threads */ + } + gl_linked_waitqueue_t; +typedef struct + { + gl_spinlock_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; /* protects the remaining fields */ + gl_linked_waitqueue_t waiters; /* waiting threads */ + } + gl_cond_t; +# define gl_cond_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_cond_t NAME; +# define gl_cond_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_cond_t NAME = gl_cond_initializer; +# define gl_cond_initializer \ + { { 0, -1 } } +# define glthread_cond_init(COND) \ + glthread_cond_init_func (COND) +# define glthread_cond_wait(COND, LOCK) \ + glthread_cond_wait_func (COND, LOCK) +# define glthread_cond_timedwait(COND, LOCK, ABSTIME) \ + glthread_cond_timedwait_func (COND, LOCK, ABSTIME) +# define glthread_cond_signal(COND) \ + glthread_cond_signal_func (COND) +# define glthread_cond_broadcast(COND) \ + glthread_cond_broadcast_func (COND) +# define glthread_cond_destroy(COND) \ + glthread_cond_destroy_func (COND) +extern int glthread_cond_init_func (gl_cond_t *cond); +extern int glthread_cond_wait_func (gl_cond_t *cond, gl_lock_t *lock); +extern int glthread_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime); +extern int glthread_cond_signal_func (gl_cond_t *cond); +extern int glthread_cond_broadcast_func (gl_cond_t *cond); +extern int glthread_cond_destroy_func (gl_cond_t *cond); + +# ifdef __cplusplus +} +# endif #endif @@ -279,6 +349,10 @@ typedef int gl_cond_t; /* Macros with built-in error handling. */ +#ifdef __cplusplus +extern "C" { +#endif + #define gl_cond_init(COND) \ do \ { \ @@ -327,4 +401,8 @@ gl_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *absti } \ while (0) +#ifdef __cplusplus +} +#endif + #endif /* _GLTHREAD_COND_H */