summaryrefslogtreecommitdiff
path: root/src/systhread.h
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2013-08-31 14:29:05 +0300
committerEli Zaretskii <eliz@gnu.org>2013-08-31 14:29:05 +0300
commite57df8f77901a3964d21c3d57fb6769cf4511dc2 (patch)
tree1a748293f62f70a786b9f6c51662e1c132650528 /src/systhread.h
parentdbe17fefccbff010bbbf6c4d0dccc7b2f3a5e201 (diff)
downloademacs-e57df8f77901a3964d21c3d57fb6769cf4511dc2.tar.gz
emacs-e57df8f77901a3964d21c3d57fb6769cf4511dc2.tar.bz2
emacs-e57df8f77901a3964d21c3d57fb6769cf4511dc2.zip
Improve MS-Windows implementation of threads.
src/systhread.c (sys_cond_init): Set the 'initialized' member to true only if initialization is successful. Initialize wait_count and wait_count_lock. (sys_cond_wait, sys_cond_signal, sys_cond_broadcast): If 'initialized' is false, do nothing. (sys_cond_wait): Fix the implementation to avoid the "missed wakeup" bug: count the waiting threads, and reset the broadcast event once the last thread was released. (sys_cond_signal, sys_cond_broadcast): Use SetEvent instead of PulseEvent. Don't signal the event if no threads are waiting. (sys_cond_destroy): Only close non-NULL handles. (sys_thread_create): Return zero if unsuccessful, 1 if successful. src/systhread.h (w32thread_cond_t): New member 'initialized'. Rename waiters_count and waiters_count_lock to wait_count and wait_count_lock, respectively.
Diffstat (limited to 'src/systhread.h')
-rw-r--r--src/systhread.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/systhread.h b/src/systhread.h
index 52735449a5e..b38fd8ffd45 100644
--- a/src/systhread.h
+++ b/src/systhread.h
@@ -56,9 +56,13 @@ typedef struct {
enum { CONDV_SIGNAL = 0, CONDV_BROADCAST = 1, CONDV_MAX = 2 };
typedef struct {
- unsigned waiters_count;
- w32thread_critsect waiters_count_lock;
+ /* Count of threads that are waiting for this condition variable. */
+ unsigned wait_count;
+ /* Critical section to protect changes to the count above. */
+ w32thread_critsect wait_count_lock;
+ /* Handles of events used for signal and broadcast. */
void *events[CONDV_MAX];
+ bool initialized;
} w32thread_cond_t;
typedef w32thread_critsect sys_mutex_t;