diff options
Diffstat (limited to 'thread_win32.ci')
-rw-r--r-- | thread_win32.ci | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/thread_win32.ci b/thread_win32.ci index 4a681b36c3..aa1664a58a 100644 --- a/thread_win32.ci +++ b/thread_win32.ci @@ -67,17 +67,13 @@ w32_reset_event(HANDLE handle) } static int -w32_wait_event(HANDLE event, DWORD timeout, rb_thread_t *th) +w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th) { - HANDLE events[2]; - int count = 0; + HANDLE *targets = events; DWORD ret; - if (event) { - events[count++] = event; - thread_debug(" * handle: %p (count: %d)\n", event, count); - } - + thread_debug(" w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n", + events, count, timeout, th); if (th) { HANDLE intr = th->native_thread_data.interrupt_event; w32_reset_event(intr); @@ -85,12 +81,15 @@ w32_wait_event(HANDLE event, DWORD timeout, rb_thread_t *th) w32_set_event(intr); } - events[count++] = intr; + targets = ALLOCA_N(HANDLE, count + 1); + memcpy(targets, events, sizeof(HANDLE) * count); + + targets[count++] = intr; thread_debug(" * handle: %p (count: %d, intr)\n", intr, count); } thread_debug(" WaitForMultipleObjects start (count: %d)\n", count); - ret = WaitForMultipleObjects(count, events, FALSE, timeout); + ret = WaitForMultipleObjects(count, targets, FALSE, timeout); thread_debug(" WaitForMultipleObjects end (ret: %d)\n", ret); if (ret == WAIT_OBJECT_0 + count - 1 && th) { @@ -101,12 +100,24 @@ w32_wait_event(HANDLE event, DWORD timeout, rb_thread_t *th) DWORD dmy; for (i = 0; i < count; i++) { thread_debug(" * error handle %d - %s\n", i, - GetHandleInformation(events[i], &dmy) ? "OK" : "NG"); + GetHandleInformation(targets[i], &dmy) ? "OK" : "NG"); } } return ret; } +static void ubf_handle(rb_thread_t *th); +#define ubf_select ubf_handle + +int +rb_w32_wait_events(HANDLE *events, int num, DWORD timeout) +{ + int ret; + + BLOCKING_REGION(ret = w32_wait_events(events, num, timeout, GET_THREAD()), ubf_handle); + return ret; +} + static void w32_close_handle(HANDLE handle) { @@ -129,8 +140,20 @@ w32_create_thread(DWORD stack_size, void *func, void *val) return (HANDLE)_beginthreadex(0, stack_size, func, val, CREATE_SUSPENDED, 0); } -static void ubf_handle(rb_thread_t *th); -#define ubf_select ubf_handle +int +rb_w32_sleep(unsigned long msec) +{ + return w32_wait_events(0, 0, msec, GET_THREAD()); +} + +int WINAPI +rb_w32_Sleep(unsigned long msec) +{ + int ret; + + BLOCKING_REGION(ret = rb_w32_sleep(msec), ubf_handle); + return ret; +} static void native_sleep(rb_thread_t *th, struct timeval *tv) @@ -150,7 +173,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv) th->status = THREAD_STOPPED; th->unblock_function = ubf_handle; thread_debug("native_sleep start (%d)\n", (int)msec); - ret = w32_wait_event(0, msec, th); + ret = w32_wait_events(0, 0, msec, th); thread_debug("native_sleep done (%d)\n", ret); th->unblock_function = 0; th->status = status; @@ -165,7 +188,7 @@ native_mutex_lock(rb_thread_lock_t *lock) DWORD result; while (1) { thread_debug("native_mutex_lock: %p\n", *lock); - result = w32_wait_event(*lock, INFINITE, 0); + result = w32_wait_events(&*lock, 1, INFINITE, 0); switch (result) { case WAIT_OBJECT_0: /* get mutex object */ @@ -212,7 +235,7 @@ native_mutex_trylock(rb_thread_lock_t *lock) #if USE_WIN32MUTEX int result; thread_debug("native_mutex_trylock: %p\n", *lock); - result = w32_wait_event(*lock, 1, 0); + result = w32_wait_events(&*lock, 1, 1, 0); thread_debug("native_mutex_trylock result: %d\n", result); switch (result) { case WAIT_OBJECT_0: @@ -306,7 +329,7 @@ native_thread_create(rb_thread_t *th) static void native_thread_join(HANDLE th) { - w32_wait_event(th, 0, 0); + w32_wait_events(&th, 1, 0, 0); } static void |