aboutsummaryrefslogtreecommitdiffstats
path: root/thread_win32.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-29 04:18:29 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-29 04:18:29 +0000
commitb4c5fad4b1b435f081dd552ad29040a9edb1457f (patch)
treed594c9bb0ca0953baa3283eb789759c7d8db21c3 /thread_win32.c
parent9d4ae4ab0c5b17e48939457bc9d4cf45ac412d26 (diff)
downloadruby-b4c5fad4b1b435f081dd552ad29040a9edb1457f.tar.gz
* thread_win32.c (native_cond_timedwait): New. r31373 caused
win32 build failure. * thread_win32.c (__cond_timedwait, abs_timespec_to_timeout_ms): New helper functions. * win32/win32.c (rb_w32_time_subtract): rename from subtract and remove static. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_win32.c')
-rw-r--r--thread_win32.c57
1 files changed, 40 insertions, 17 deletions
diff --git a/thread_win32.c b/thread_win32.c
index 62ba5bbab5..6d1ba32357 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -21,19 +21,6 @@
static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
-static int native_mutex_lock(rb_thread_lock_t *);
-static int native_mutex_unlock(rb_thread_lock_t *);
-static int native_mutex_trylock(rb_thread_lock_t *);
-static void native_mutex_initialize(rb_thread_lock_t *);
-static void native_mutex_destroy(rb_thread_lock_t *);
-
-static void native_cond_signal(rb_thread_cond_t *cond);
-static void native_cond_broadcast(rb_thread_cond_t *cond);
-static void native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex);
-static void native_cond_initialize(rb_thread_cond_t *cond);
-static void native_cond_destroy(rb_thread_cond_t *cond);
-static int w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th);
-
static void
w32_error(const char *func)
{
@@ -433,8 +420,9 @@ native_cond_broadcast(rb_thread_cond_t *cond)
}
}
-static void
-native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex)
+
+static int
+__cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, unsigned long msec)
{
DWORD r;
struct cond_event_entry entry;
@@ -454,14 +442,49 @@ native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex)
native_mutex_unlock(mutex);
{
- r = WaitForSingleObject(entry.event, INFINITE);
- if (r != WAIT_OBJECT_0) {
+ r = WaitForSingleObject(entry.event, msec);
+ if ((r != WAIT_OBJECT_0) && (r != WAIT_TIMEOUT)) {
rb_bug("native_cond_wait: WaitForSingleObject returns %lu", r);
}
}
native_mutex_lock(mutex);
w32_close_handle(entry.event);
+ return (r == WAIT_OBJECT_0) ? 0 : ETIMEDOUT;
+}
+
+static int
+native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex)
+{
+ return __cond_timedwait(cond, mutex, INFINITE);
+}
+
+static unsigned long
+abs_timespec_to_timeout_ms(struct timespec *ts)
+{
+ struct timeval tv;
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ tv.tv_sec = ts->tv_sec;
+ tv.tv_usec = ts->tv_nsec;
+
+ if (!rb_w32_time_subtract(&tv, &now))
+ return 0;
+
+ return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
+}
+
+static int
+native_cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, struct timespec *ts)
+{
+ unsigned long timeout_ms;
+
+ timeout_ms = abs_timespec_to_timeout_ms(ts);
+ if (!timeout_ms)
+ return ETIMEDOUT;
+
+ return __cond_timedwait(cond, mutex, timeout_ms);
}
static void