Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* 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
  • Loading branch information...
commit b4c5fad4b1b435f081dd552ad29040a9edb1457f 1 parent 9d4ae4a
@kosaki kosaki authored
Showing with 60 additions and 20 deletions.
  1. +12 −0 ChangeLog
  2. +1 −0  include/ruby/win32.h
  3. +40 −17 thread_win32.c
  4. +7 −3 win32/win32.c
View
12 ChangeLog
@@ -1,3 +1,15 @@
+Fri Apr 29 13:15:15 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * 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.
+
+
Fri Apr 29 10:43:09 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* benchmark/bm_vm4_pipe.rb: Add two new benchmark for GVL
View
1  include/ruby/win32.h
@@ -303,6 +303,7 @@ extern int rb_w32_stati64(const char *, struct stati64 *);
extern int rb_w32_ustati64(const char *, struct stati64 *);
extern int rb_w32_access(const char *, int);
extern int rb_w32_uaccess(const char *, int);
+extern int rb_w32_subtract(struct timeval *rest, const struct timeval *wait);
#ifdef __BORLANDC__
extern int rb_w32_fstati64(int, struct stati64 *);
View
57 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
View
10 win32/win32.c
@@ -2528,8 +2528,12 @@ do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
return r;
}
-static inline int
-subtract(struct timeval *rest, const struct timeval *wait)
+/*
+ * rest -= wait
+ * return 0 if rest is smaller than wait.
+ */
+int
+rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
{
if (rest->tv_sec < wait->tv_sec) {
return 0;
@@ -2668,7 +2672,7 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
struct timeval now;
gettimeofday(&now, NULL);
rest = limit;
- if (!subtract(&rest, &now)) break;
+ if (!rb_w32_time_subtract(&rest, &now)) break;
if (compare(&rest, &wait) < 0) dowait = &rest;
}
Sleep(dowait->tv_sec * 1000 + dowait->tv_usec / 1000);
Please sign in to comment.
Something went wrong with that request. Please try again.