ruby-changes:13969
From: nobu <ko1@a...>
Date: Mon, 16 Nov 2009 01:07:22 +0900 (JST)
Subject: [ruby-changes:13969] Ruby:r25776 (mvm): * thread_pthread.c (native_cond_timedwait): use timeval instead of
nobu 2009-11-16 01:06:57 +0900 (Mon, 16 Nov 2009) New Revision: 25776 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25776 Log: * thread_pthread.c (native_cond_timedwait): use timeval instead of timespec. * thread_win32.c (ruby_native_cond_timedwait): added. Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 25770) +++ thread_pthread.c (working copy) @@ -117,7 +117,10 @@ native_cond_wait(pthread_cond_t *cond, p int -native_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *ts) +native_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timeval *tv) { - return pthread_cond_timedwait(cond, mutex, ts); + struct timespec ts; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + return pthread_cond_timedwait(cond, mutex, &ts) == ETIMEDOUT; } @@ -783,5 +786,5 @@ thread_timer(void *dummy) native_mutex_lock(&timer_thread_lock); native_cond_broadcast(&timer_thread_cond); -#define WAIT_FOR_10MS() native_cond_timedwait(&timer_thread_cond, &timer_thread_lock, get_ts(&ts, PER_NANO/100)) +#define WAIT_FOR_10MS() pthread_cond_timedwait(&timer_thread_cond, &timer_thread_lock, get_ts(&ts, PER_NANO/100)) while (system_working > 0) { int err = WAIT_FOR_10MS(); Index: thread_win32.c =================================================================== --- thread_win32.c (revision 25770) +++ thread_win32.c (working copy) @@ -22,13 +22,13 @@ 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_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); +int native_mutex_lock(rb_thread_lock_t *); +int native_mutex_unlock(rb_thread_lock_t *); +int native_mutex_trylock(rb_thread_lock_t *); + +void native_cond_signal(rb_thread_cond_t *cond); +void native_cond_broadcast(rb_thread_cond_t *cond); +void native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex); +void native_cond_initialize(rb_thread_cond_t *cond); +void native_cond_destroy(rb_thread_cond_t *cond); rb_thread_t * @@ -256,6 +256,6 @@ native_sleep(rb_thread_t *th, struct tim } -static int -native_mutex_lock(rb_thread_lock_t *lock) +int +ruby_native_mutex_lock(rb_thread_lock_t *lock) { #if USE_WIN32_MUTEX @@ -293,11 +293,5 @@ native_mutex_lock(rb_thread_lock_t *lock int -ruby_native_thread_lock(rb_thread_lock_t *lock) -{ - return native_mutex_lock(lock); -} - -static int -native_mutex_unlock(rb_thread_lock_t *lock) +ruby_native_thread_unlock(rb_thread_lock_t *lock) { #if USE_WIN32_MUTEX @@ -311,11 +305,5 @@ native_mutex_unlock(rb_thread_lock_t *lo int -ruby_native_thread_unlock(rb_thread_lock_t *lock) -{ - return native_mutex_unlock(lock); -} - -static int -native_mutex_trylock(rb_thread_lock_t *lock) +ruby_native_mutex_trylock(rb_thread_lock_t *lock) { #if USE_WIN32_MUTEX @@ -370,6 +358,6 @@ struct rb_thread_cond_struct { }; -static void -native_cond_signal(rb_thread_cond_t *cond) +void +ruby_native_cond_signal(rb_thread_cond_t *cond) { /* cond is guarded by mutex */ @@ -385,6 +373,6 @@ native_cond_signal(rb_thread_cond_t *con } -static void -native_cond_broadcast(rb_thread_cond_t *cond) +void +ruby_native_cond_broadcast(rb_thread_cond_t *cond) { /* cond is guarded by mutex */ @@ -398,6 +386,6 @@ native_cond_broadcast(rb_thread_cond_t * } -static void -native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex) +static int +native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, ULONG timeout) { DWORD r; @@ -419,6 +407,6 @@ native_cond_wait(rb_thread_cond_t *cond, native_mutex_unlock(mutex); { - r = WaitForSingleObject(entry.event, INFINITE); - if (r != WAIT_OBJECT_0) { + r = WaitForSingleObject(entry.event, timeout); + if (r != WAIT_OBJECT_0 && r != WAIT_TIMEOUT) { rb_bug("native_cond_wait: WaitForSingleObject returns %lu", r); } @@ -427,8 +415,25 @@ native_cond_wait(rb_thread_cond_t *cond, w32_close_handle(entry.event); + return r; } -static void -native_cond_initialize(rb_thread_cond_t *cond) +void +ruby_native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex) +{ + native_cond_wait(cond, mutex, INFINITE); +} + +int +ruby_native_cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, const struct timeval *tv) +{ + ULONG timeout = INFINITE; + if (tv) { + timeout = tv->tv_sec * 1000000 + (tv->tv_nsec + 500) / 1000; + } + return native_cond_wait(cond, mutex, timeout) == WAIT_TIMEOUT; +} + +void +ruby_native_cond_initialize(rb_thread_cond_t *cond) { cond->next = 0; @@ -436,6 +441,6 @@ native_cond_initialize(rb_thread_cond_t } -static void -native_cond_destroy(rb_thread_cond_t *cond) +void +ruby_native_cond_destroy(rb_thread_cond_t *cond) { /* */ Modified files: branches/mvm/ChangeLog branches/mvm/thread_pthread.c branches/mvm/thread_win32.c Index: mvm/thread_win32.c =================================================================== --- mvm/thread_win32.c (revision 25775) +++ mvm/thread_win32.c (revision 25776) @@ -21,15 +21,15 @@ 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 *); +int native_mutex_lock(rb_thread_lock_t *); +int native_mutex_unlock(rb_thread_lock_t *); +int native_mutex_trylock(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); +void native_cond_signal(rb_thread_cond_t *cond); +void native_cond_broadcast(rb_thread_cond_t *cond); +void native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex); +void native_cond_initialize(rb_thread_cond_t *cond); +void native_cond_destroy(rb_thread_cond_t *cond); rb_thread_t * ruby_thread_from_native(void) @@ -255,8 +255,8 @@ GVL_UNLOCK_END(); } -static int -native_mutex_lock(rb_thread_lock_t *lock) +int +ruby_native_mutex_lock(rb_thread_lock_t *lock) { #if USE_WIN32_MUTEX DWORD result; @@ -292,14 +292,8 @@ } int -ruby_native_thread_lock(rb_thread_lock_t *lock) +ruby_native_thread_unlock(rb_thread_lock_t *lock) { - return native_mutex_lock(lock); -} - -static int -native_mutex_unlock(rb_thread_lock_t *lock) -{ #if USE_WIN32_MUTEX thread_debug("release mutex: %p\n", *lock); return ReleaseMutex(*lock); @@ -310,14 +304,8 @@ } int -ruby_native_thread_unlock(rb_thread_lock_t *lock) +ruby_native_mutex_trylock(rb_thread_lock_t *lock) { - return native_mutex_unlock(lock); -} - -static int -native_mutex_trylock(rb_thread_lock_t *lock) -{ #if USE_WIN32_MUTEX int result; thread_debug("native_mutex_trylock: %p\n", *lock); @@ -369,8 +357,8 @@ struct cond_event_entry *last; }; -static void -native_cond_signal(rb_thread_cond_t *cond) +void +ruby_native_cond_signal(rb_thread_cond_t *cond) { /* cond is guarded by mutex */ struct cond_event_entry *e = cond->next; @@ -384,8 +372,8 @@ } } -static void -native_cond_broadcast(rb_thread_cond_t *cond) +void +ruby_native_cond_broadcast(rb_thread_cond_t *cond) { /* cond is guarded by mutex */ struct cond_event_entry *e = cond->next; @@ -397,8 +385,8 @@ } } -static void -native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex) +static int +native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, ULONG timeout) { DWORD r; struct cond_event_entry entry; @@ -418,25 +406,42 @@ native_mutex_unlock(mutex); { - r = WaitForSingleObject(entry.event, INFINITE); - if (r != WAIT_OBJECT_0) { + r = WaitForSingleObject(entry.event, timeout); + 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; } -static void -native_cond_initialize(rb_thread_cond_t *cond) +void +ruby_native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex) { + native_cond_wait(cond, mutex, INFINITE); +} + +int +ruby_native_cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, const struct timeval *tv) +{ + ULONG timeout = INFINITE; + if (tv) { + timeout = tv->tv_sec * 1000000 + (tv->tv_nsec + 500) / 1000; + } + return native_cond_wait(cond, mutex, timeout) == WAIT_TIMEOUT; +} + +void +ruby_native_cond_initialize(rb_thread_cond_t *cond) +{ cond->next = 0; cond->last = 0; } -static void -native_cond_destroy(rb_thread_cond_t *cond) +void +ruby_native_cond_destroy(rb_thread_cond_t *cond) { /* */ } Index: mvm/ChangeLog =================================================================== --- mvm/ChangeLog (revision 25775) +++ mvm/ChangeLog (revision 25776) @@ -1,3 +1,10 @@ +Mon Nov 16 01:06:50 2009 Nobuyoshi Nakada <nobu@r...> + + * thread_pthread.c (native_cond_timedwait): use timeval instead of + timespec. + + * thread_win32.c (ruby_native_cond_timedwait): added. + Mon Nov 16 01:04:25 2009 Nobuyoshi Nakada <nobu@r...> * include/ruby/public_object.h (ruby_public_object_vmkey): moved Index: mvm/thread_pthread.c =================================================================== --- mvm/thread_pthread.c (revision 25775) +++ mvm/thread_pthread.c (revision 25776) @@ -116,9 +116,12 @@ } int -native_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *ts) +native_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timeval *tv) { - return pthread_cond_timedwait(cond, mutex, ts); + struct timespec ts; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + return pthread_cond_timedwait(cond, mutex, &ts) == ETIMEDOUT; } @@ -782,7 +785,7 @@ native_mutex_lock(&timer_thread_lock); native_cond_broadcast(&timer_thread_cond); -#define WAIT_FOR_10MS() native_cond_timedwait(&timer_thread_cond, &timer_thread_lock, get_ts(&ts, PER_NANO/100)) +#define WAIT_FOR_10MS() pthread_cond_timedwait(&timer_thread_cond, &timer_thread_lock, get_ts(&ts, PER_NANO/100)) while (system_working > 0) { int err = WAIT_FOR_10MS(); if (err == ETIMEDOUT); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/