[前][次][番号順一覧][スレッド一覧]

ruby-changes:30081

From: ko1 <ko1@a...>
Date: Tue, 23 Jul 2013 18:53:25 +0900 (JST)
Subject: [ruby-changes:30081] ko1:r42133 (trunk): * thread_native.h: added.

ko1	2013-07-23 18:53:14 +0900 (Tue, 23 Jul 2013)

  New Revision: 42133

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42133

  Log:
    * 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.

  Added files:
    trunk/thread_native.h
  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/thread.c
    trunk/thread_pthread.c
    trunk/thread_pthread.h
    trunk/thread_win32.c
    trunk/thread_win32.h
    trunk/vm_core.h

Index: thread_win32.c
===================================================================
--- thread_win32.c	(revision 42132)
+++ thread_win32.c	(revision 42133)
@@ -24,8 +24,8 @@ https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L24
 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 tim https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L331
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L342
 }
 
 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 *lo https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L354
 }
 
 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 *l https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L374
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L385
 }
 
 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 * https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L442
 
 
 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_ https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L473
 }
 
 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 timesp https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L495
 }
 
 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;
 
Index: thread_win32.h
===================================================================
--- thread_win32.h	(revision 42132)
+++ thread_win32.h	(revision 42133)
@@ -26,7 +26,7 @@ typedef HANDLE rb_thread_id_t; https://github.com/ruby/ruby/blob/trunk/thread_win32.h#L26
 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;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42132)
+++ ChangeLog	(revision 42133)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 23 18:44:15 2013  Koichi Sasada  <ko1@a...>
+
+	* 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  <ko1@a...>
 
 	* gc.c (gc_before_sweep): fix spacing.
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 42132)
+++ thread_pthread.c	(revision 42133)
@@ -418,7 +418,7 @@ native_cond_timeout(rb_thread_cond_t *co https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L418
 #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;
Index: thread_pthread.h
===================================================================
--- thread_pthread.h	(revision 42132)
+++ thread_pthread.h	(revision 42133)
@@ -16,7 +16,7 @@ https://github.com/ruby/ruby/blob/trunk/thread_pthread.h#L16
 #include <pthread_np.h>
 #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;
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 42132)
+++ vm_core.h	(revision 42133)
@@ -24,13 +24,7 @@ https://github.com/ruby/ruby/blob/trunk/vm_core.h#L24
 #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 { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L335
     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 { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L552
 
     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_clea https://github.com/ruby/ruby/blob/trunk/vm_core.h#L925
 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;			\
Index: thread.c
===================================================================
--- thread.c	(revision 42132)
+++ thread.c	(revision 42133)
@@ -241,7 +241,7 @@ static void timer_thread_function(void * https://github.com/ruby/ruby/blob/trunk/thread.c#L241
 
 #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) https://github.com/ruby/ruby/blob/trunk/thread.c#L277
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/thread.c#L387
 
 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;
Index: common.mk
===================================================================
--- common.mk	(revision 42132)
+++ common.mk	(revision 42133)
@@ -612,7 +612,7 @@ ENCODING_H_INCLUDES= {$(VPATH)}encoding. https://github.com/ruby/ruby/blob/trunk/common.mk#L612
 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
 
 ###
 
Index: thread_native.h
===================================================================
--- thread_native.h	(revision 0)
+++ thread_native.h	(revision 42133)
@@ -0,0 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/thread_native.h#L1
+#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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]