X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fglthread%2Fcond.h;h=bf709a2916082b4d7d2d93d4bed7951576ebdaa8;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=e6707b85ea06e8839244afb6a29d2e9c8b5d158e;hpb=d4300b64e12f5ed6eb0634a7de21e9479b18bfbe;p=gnulib.git diff --git a/lib/glthread/cond.h b/lib/glthread/cond.h index e6707b85e..bf709a291 100644 --- a/lib/glthread/cond.h +++ b/lib/glthread/cond.h @@ -1,5 +1,5 @@ /* Condition variables for multithreading. - Copyright (C) 2005-2008 Free Software Foundation, Inc. + Copyright (C) 2005-2014 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -12,8 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program; if not, see . */ /* Written by Yoann Vandoorselaere , 2008. Based on Bruno Haible lock.h */ @@ -55,6 +54,14 @@ #include #include "glthread/lock.h" +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif + +_GL_INLINE_HEADER_BEGIN +#ifndef _GLTHREAD_COND_INLINE +# define _GLTHREAD_COND_INLINE _GL_INLINE +#endif /* ========================================================================= */ @@ -269,7 +276,68 @@ extern int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, gl_lock_t *lo /* ========================================================================= */ -#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS) +#if USE_WINDOWS_THREADS + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# 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 + +/* ========================================================================= */ + +#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS) /* Provide dummy implementation if threads are not supported. */ @@ -309,7 +377,7 @@ extern "C" { while (0) #define gl_cond_timedwait(COND, LOCK, ABSTIME) \ gl_cond_timedwait_func (&COND, &LOCK, ABSTIME) -static inline bool +_GLTHREAD_COND_INLINE bool gl_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *abstime) { int err = glthread_cond_timedwait (cond, lock, abstime); @@ -345,4 +413,6 @@ gl_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec *absti } #endif +_GL_INLINE_HEADER_END + #endif /* _GLTHREAD_COND_H */