/* Condition variables for multithreading.
- Copyright (C) 2005-2008 Free Software Foundation, Inc.
+ Copyright (C) 2005-2013 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
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 <http://www.gnu.org/licenses/>. */
/* Written by Yoann Vandoorselaere <yoann@prelude-ids.org>, 2008.
Based on Bruno Haible <bruno@clisp.org> lock.h */
#include "glthread/lock.h"
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GLTHREAD_COND_INLINE
+# define _GLTHREAD_COND_INLINE _GL_INLINE
+#endif
+
/* ========================================================================= */
#if USE_POSIX_THREADS
/* ========================================================================= */
-#if USE_WIN32_THREADS
+#if USE_WINDOWS_THREADS
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
# ifdef __cplusplus
/* -------------------------- 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 */
- HANDLE event; /* an event configured for manual reset */
- unsigned int waiters_count; /* number of threads currently waiting */
- unsigned int release_count; /* number of threads that are currently
- being notified but have not yet
- acknowledged. Always
- release_count <= waiters_count */
- unsigned int wait_generation_count; /* incremented each time a signal
- or broadcast is performed */
+ gl_linked_waitqueue_t waiters; /* waiting threads */
}
gl_cond_t;
# define gl_cond_define(STORAGECLASS, NAME) \
/* ========================================================================= */
-#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS)
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
/* Provide dummy implementation if threads are not supported. */
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);
}
#endif
+_GL_INLINE_HEADER_END
+
#endif /* _GLTHREAD_COND_H */