summaryrefslogtreecommitdiff
path: root/thread_win32.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-07 06:17:59 (GMT)
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-07 06:17:59 (GMT)
commit94e4d61bdaad74e0f31bb6d69521784303a0cb5e (patch)
tree00458e6bd6f47cadd32bac4381b1cdbdacf21aec /thread_win32.c
parent471fb33b1a140973a3e3f6168f16b67bee95b4cd (diff)
fix win32 native_cond_timedwait() makes SIGSEGV.
* thread_win32.h (rb_thread_cond_struct): add prev field instead of last. (ie cond_event_entry is now using double linked list instead of single) * thread_win32.c (cond_event_entry): add prev field. * thread_win32.c (__cond_timedwait): remove entry properly if timeout was happen. * thread_win32.c (native_cond_signal): change for double linked list. * thread_win32.c (native_cond_broadcast): ditto. * thread_win32.c (native_cond_initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_win32.c')
-rw-r--r--thread_win32.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/thread_win32.c b/thread_win32.c
index 6c7e0d2..360013d 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -393,6 +393,7 @@ native_mutex_destroy(rb_thread_lock_t *lock)
struct cond_event_entry {
struct cond_event_entry* next;
+ struct cond_event_entry* prev;
HANDLE event;
};
@@ -401,9 +402,16 @@ native_cond_signal(rb_thread_cond_t *cond)
{
/* cond is guarded by mutex */
struct cond_event_entry *e = cond->next;
+ struct cond_event_entry *head = (struct cond_event_entry*)cond;
+
+ if (e != head) {
+ struct cond_event_entry *next = e->next;
+ struct cond_event_entry *prev = e->prev;
+
+ prev->next = next;
+ next->prev = prev;
+ e->next = e->prev = e;
- if (e) {
- cond->next = e->next;
SetEvent(e->event);
}
else {
@@ -416,11 +424,19 @@ native_cond_broadcast(rb_thread_cond_t *cond)
{
/* cond is guarded by mutex */
struct cond_event_entry *e = cond->next;
- cond->next = 0;
+ struct cond_event_entry *head = (struct cond_event_entry*)cond;
+
+ while (e != head) {
+ struct cond_event_entry *next = e->next;
+ struct cond_event_entry *prev = e->prev;
- while (e) {
SetEvent(e->event);
- e = e->next;
+
+ prev->next = next;
+ next->prev = prev;
+ e->next = e->prev = e;
+
+ e = next;
}
}
@@ -430,19 +446,16 @@ __cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, unsigned long
{
DWORD r;
struct cond_event_entry entry;
+ struct cond_event_entry *head = (struct cond_event_entry*)cond;
- entry.next = 0;
entry.event = CreateEvent(0, FALSE, FALSE, 0);
+ entry.mutex = mutex;
/* cond is guarded by mutex */
- if (cond->next) {
- cond->last->next = &entry;
- cond->last = &entry;
- }
- else {
- cond->next = &entry;
- cond->last = &entry;
- }
+ entry.next = head;
+ entry.prev = head->prev;
+ head->prev->next = &entry;
+ head->prev = &entry;
native_mutex_unlock(mutex);
{
@@ -453,6 +466,9 @@ __cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, unsigned long
}
native_mutex_lock(mutex);
+ entry.prev->next = entry.next;
+ entry.next->prev = entry.prev;
+
w32_close_handle(entry.event);
return (r == WAIT_OBJECT_0) ? 0 : ETIMEDOUT;
}
@@ -537,8 +553,8 @@ native_cond_timeout(rb_thread_cond_t *cond, struct timespec timeout_rel)
static void
native_cond_initialize(rb_thread_cond_t *cond, int flags)
{
- cond->next = 0;
- cond->last = 0;
+ cond->next = (struct cond_event_entry *)cond;
+ cond->prev = (struct cond_event_entry *)cond;
}
static void