summaryrefslogtreecommitdiffstats
path: root/thread_win32.ci
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 09:33:53 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 09:33:53 +0000
commite181050eb123eed44d8c640c032ee12ce9930f52 (patch)
tree17b2da3d61e6c55ff9a85cd8117e91bbc2dd9ccc /thread_win32.ci
parent01ad79370f248e84d5943f6a9918abe839943fe6 (diff)
downloadruby-e181050eb123eed44d8c640c032ee12ce9930f52.tar.gz
ruby-e181050eb123eed44d8c640c032ee12ce9930f52.tar.xz
ruby-e181050eb123eed44d8c640c032ee12ce9930f52.zip
* thread.c (rb_thread_polling): check interrupts here.
* thread_win32.ci (w32_wait_events): rename from w32_wait_event(), and now receive multiple event handles. * win32/win32.c (wait_events, rb_w32_main_context): removed. * thread_win32.ci (rb_w32_wait_events): new function. * thread_win32.ci, win32/win32.c (rb_w32_sleep, rb_w32_Sleep): move from win32/win32.c to thread_win32.ci, and use w32_wait_events(). git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_win32.ci')
-rw-r--r--thread_win32.ci57
1 files changed, 40 insertions, 17 deletions
diff --git a/thread_win32.ci b/thread_win32.ci
index 4a681b36c..aa1664a58 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