From bd058912da6ffef92a50fe759b1bae210ec82ea4 Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 23 Jul 2013 09:53:14 +0000 Subject: * thread_native.h: added. Move native thread related lines from vm_core.h. And declare several functions "rb_nativethread_lock_*", manipulate locking. * common.mk: add thread_native.h. * thread.c: add functions "rb_nativethread_lock_*". * thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t to rb_nativethread_lock_t to make it clear that this lock is for native thraeds, not for ruby threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ common.mk | 2 +- thread.c | 22 +++++++++++++++++----- thread_native.h | 21 +++++++++++++++++++++ thread_pthread.c | 2 +- thread_pthread.h | 2 +- thread_win32.c | 20 ++++++++++---------- thread_win32.h | 2 +- vm_core.h | 15 +++------------ 9 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 thread_native.h diff --git a/ChangeLog b/ChangeLog index e6ec8f6493..2d73bdeb8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Jul 23 18:44:15 2013 Koichi Sasada + + * thread_native.h: added. + Move native thread related lines from vm_core.h. + And declare several functions "rb_nativethread_lock_*", + manipulate locking. + + * common.mk: add thread_native.h. + + * thread.c: add functions "rb_nativethread_lock_*". + + * thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t + to rb_nativethread_lock_t to make it clear that this lock is for + native thraeds, not for ruby threads. + Tue Jul 23 16:14:57 2013 Koichi Sasada * gc.c (gc_before_sweep): fix spacing. diff --git a/common.mk b/common.mk index 819f77458f..98f2587ec5 100644 --- a/common.mk +++ b/common.mk @@ -612,7 +612,7 @@ ENCODING_H_INCLUDES= {$(VPATH)}encoding.h {$(VPATH)}oniguruma.h PROBES_H_INCLUDES = {$(VPATH)}probes.h VM_CORE_H_INCLUDES = {$(VPATH)}vm_core.h {$(VPATH)}thread_$(THREAD_MODEL).h \ {$(VPATH)}node.h {$(VPATH)}method.h {$(VPATH)}ruby_atomic.h \ - {$(VPATH)}vm_debug.h {$(VPATH)}id.h + {$(VPATH)}vm_debug.h {$(VPATH)}id.h {$(VPATH)}thread_native.h ### diff --git a/thread.c b/thread.c index eaf408fa6d..c6c22d9310 100644 --- a/thread.c +++ b/thread.c @@ -241,7 +241,7 @@ static void timer_thread_function(void *); #if THREAD_DEBUG static int debug_mutex_initialized = 1; -static rb_thread_lock_t debug_mutex; +static rb_nativethread_lock_t debug_mutex; void rb_thread_debug( @@ -277,17 +277,29 @@ rb_vm_gvl_destroy(rb_vm_t *vm) } void -rb_thread_lock_unlock(rb_thread_lock_t *lock) +rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock) { - native_mutex_unlock(lock); + native_mutex_initialize(lock); } void -rb_thread_lock_destroy(rb_thread_lock_t *lock) +rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock) { native_mutex_destroy(lock); } +void +rb_nativethread_lock_lock(rb_nativethread_lock_t *lock) +{ + native_mutex_lock(lock); +} + +void +rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock) +{ + native_mutex_unlock(lock); +} + static int set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg, struct rb_unblock_callback *old, int fail_if_interrupted) @@ -375,7 +387,7 @@ terminate_i(st_data_t key, st_data_t val, rb_thread_t *main_thread) typedef struct rb_mutex_struct { - rb_thread_lock_t lock; + rb_nativethread_lock_t lock; rb_thread_cond_t cond; struct rb_thread_struct volatile *th; int cond_waiting; diff --git a/thread_native.h b/thread_native.h new file mode 100644 index 0000000000..2870b895c6 --- /dev/null +++ b/thread_native.h @@ -0,0 +1,21 @@ +#ifndef RUBY_THREAD_NATIVE_H +#define RUBY_THREAD_NATIVE_H + +#if defined(_WIN32) +#include "thread_win32.h" +#elif defined(HAVE_PTHREAD_H) +#include "thread_pthread.h" +#else +#error "unsupported thread type" +#endif + +RUBY_SYMBOL_EXPORT_BEGIN + +void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock); +void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock); + +RUBY_SYMBOL_EXPORT_END + +#endif diff --git a/thread_pthread.c b/thread_pthread.c index f995757929..378dede9ea 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -418,7 +418,7 @@ native_cond_timeout(rb_thread_cond_t *cond, struct timespec timeout_rel) #ifdef USE_SIGNAL_THREAD_LIST static void add_signal_thread_list(rb_thread_t *th); static void remove_signal_thread_list(rb_thread_t *th); -static rb_thread_lock_t signal_thread_list_lock; +static rb_nativethread_lock_t signal_thread_list_lock; #endif static pthread_key_t ruby_native_thread_key; diff --git a/thread_pthread.h b/thread_pthread.h index b3e7c36cf0..a02c3674ab 100644 --- a/thread_pthread.h +++ b/thread_pthread.h @@ -16,7 +16,7 @@ #include #endif typedef pthread_t rb_thread_id_t; -typedef pthread_mutex_t rb_thread_lock_t; +typedef pthread_mutex_t rb_nativethread_lock_t; typedef struct rb_thread_cond_struct { pthread_cond_t cond; diff --git a/thread_win32.c b/thread_win32.c index 86f3e3c41e..b484fece8e 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -24,8 +24,8 @@ static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES; static int w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th); -static int native_mutex_lock(rb_thread_lock_t *lock); -static int native_mutex_unlock(rb_thread_lock_t *lock); +static int native_mutex_lock(rb_nativethread_lock_t *lock); +static int native_mutex_unlock(rb_nativethread_lock_t *lock); static void w32_error(const char *func) @@ -331,7 +331,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv) } static int -native_mutex_lock(rb_thread_lock_t *lock) +native_mutex_lock(rb_nativethread_lock_t *lock) { #if USE_WIN32_MUTEX w32_mutex_lock(lock->mutex); @@ -342,7 +342,7 @@ native_mutex_lock(rb_thread_lock_t *lock) } static int -native_mutex_unlock(rb_thread_lock_t *lock) +native_mutex_unlock(rb_nativethread_lock_t *lock) { #if USE_WIN32_MUTEX thread_debug("release mutex: %p\n", lock->mutex); @@ -354,7 +354,7 @@ native_mutex_unlock(rb_thread_lock_t *lock) } static int -native_mutex_trylock(rb_thread_lock_t *lock) +native_mutex_trylock(rb_nativethread_lock_t *lock) { #if USE_WIN32_MUTEX int result; @@ -374,7 +374,7 @@ native_mutex_trylock(rb_thread_lock_t *lock) } static void -native_mutex_initialize(rb_thread_lock_t *lock) +native_mutex_initialize(rb_nativethread_lock_t *lock) { #if USE_WIN32_MUTEX lock->mutex = w32_mutex_create(); @@ -385,7 +385,7 @@ native_mutex_initialize(rb_thread_lock_t *lock) } static void -native_mutex_destroy(rb_thread_lock_t *lock) +native_mutex_destroy(rb_nativethread_lock_t *lock) { #if USE_WIN32_MUTEX w32_close_handle(lock->mutex); @@ -442,7 +442,7 @@ native_cond_broadcast(rb_thread_cond_t *cond) static int -native_cond_timedwait_ms(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, unsigned long msec) +native_cond_timedwait_ms(rb_thread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec) { DWORD r; struct cond_event_entry entry; @@ -473,7 +473,7 @@ native_cond_timedwait_ms(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, unsign } static int -native_cond_wait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex) +native_cond_wait(rb_thread_cond_t *cond, rb_nativethread_lock_t *mutex) { return native_cond_timedwait_ms(cond, mutex, INFINITE); } @@ -495,7 +495,7 @@ abs_timespec_to_timeout_ms(struct timespec *ts) } static int -native_cond_timedwait(rb_thread_cond_t *cond, rb_thread_lock_t *mutex, struct timespec *ts) +native_cond_timedwait(rb_thread_cond_t *cond, rb_nativethread_lock_t *mutex, struct timespec *ts) { unsigned long timeout_ms; diff --git a/thread_win32.h b/thread_win32.h index 9c1c4674ef..63e0713bdc 100644 --- a/thread_win32.h +++ b/thread_win32.h @@ -26,7 +26,7 @@ typedef HANDLE rb_thread_id_t; typedef union rb_thread_lock_union { HANDLE mutex; CRITICAL_SECTION crit; -} rb_thread_lock_t; +} rb_nativethread_lock_t; typedef struct rb_thread_cond_struct { struct cond_event_entry *next; diff --git a/vm_core.h b/vm_core.h index a02205a624..0227339231 100644 --- a/vm_core.h +++ b/vm_core.h @@ -24,13 +24,7 @@ #include "method.h" #include "ruby_atomic.h" -#if defined(_WIN32) -#include "thread_win32.h" -#elif defined(HAVE_PTHREAD_H) -#include "thread_pthread.h" -#else -#error "unsupported thread type" -#endif +#include "thread_native.h" #ifndef ENABLE_VM_OBJSPACE #ifdef _WIN32 @@ -341,7 +335,7 @@ typedef struct rb_vm_struct { VALUE self; rb_global_vm_lock_t gvl; - rb_thread_lock_t thread_destruct_lock; + rb_nativethread_lock_t thread_destruct_lock; struct rb_thread_struct *main_thread; struct rb_thread_struct *running_thread; @@ -558,7 +552,7 @@ typedef struct rb_thread_struct { rb_atomic_t interrupt_flag; unsigned long interrupt_mask; - rb_thread_lock_t interrupt_lock; + rb_nativethread_lock_t interrupt_lock; rb_thread_cond_t interrupt_cond; struct rb_unblock_callback unblock; VALUE locking_mutex; @@ -931,9 +925,6 @@ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th); void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v); int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th); -void rb_thread_lock_unlock(rb_thread_lock_t *); -void rb_thread_lock_destroy(rb_thread_lock_t *); - #define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \ if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \ th->pending_interrupt_queue_checked = 0; \ -- cgit v1.2.3