mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
3742192919
commit
bd058912da
9 changed files with 70 additions and 31 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
Tue Jul 23 18:44:15 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* 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@atdot.net>
|
Tue Jul 23 16:14:57 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (gc_before_sweep): fix spacing.
|
* gc.c (gc_before_sweep): fix spacing.
|
||||||
|
|
|
@ -612,7 +612,7 @@ ENCODING_H_INCLUDES= {$(VPATH)}encoding.h {$(VPATH)}oniguruma.h
|
||||||
PROBES_H_INCLUDES = {$(VPATH)}probes.h
|
PROBES_H_INCLUDES = {$(VPATH)}probes.h
|
||||||
VM_CORE_H_INCLUDES = {$(VPATH)}vm_core.h {$(VPATH)}thread_$(THREAD_MODEL).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)}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
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
|
22
thread.c
22
thread.c
|
@ -241,7 +241,7 @@ static void timer_thread_function(void *);
|
||||||
|
|
||||||
#if THREAD_DEBUG
|
#if THREAD_DEBUG
|
||||||
static int debug_mutex_initialized = 1;
|
static int debug_mutex_initialized = 1;
|
||||||
static rb_thread_lock_t debug_mutex;
|
static rb_nativethread_lock_t debug_mutex;
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_thread_debug(
|
rb_thread_debug(
|
||||||
|
@ -277,17 +277,29 @@ rb_vm_gvl_destroy(rb_vm_t *vm)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
rb_thread_lock_destroy(rb_thread_lock_t *lock)
|
rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
native_mutex_destroy(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
|
static int
|
||||||
set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg,
|
set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg,
|
||||||
struct rb_unblock_callback *old, int fail_if_interrupted)
|
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
|
typedef struct rb_mutex_struct
|
||||||
{
|
{
|
||||||
rb_thread_lock_t lock;
|
rb_nativethread_lock_t lock;
|
||||||
rb_thread_cond_t cond;
|
rb_thread_cond_t cond;
|
||||||
struct rb_thread_struct volatile *th;
|
struct rb_thread_struct volatile *th;
|
||||||
int cond_waiting;
|
int cond_waiting;
|
||||||
|
|
21
thread_native.h
Normal file
21
thread_native.h
Normal file
|
@ -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
|
|
@ -418,7 +418,7 @@ native_cond_timeout(rb_thread_cond_t *cond, struct timespec timeout_rel)
|
||||||
#ifdef USE_SIGNAL_THREAD_LIST
|
#ifdef USE_SIGNAL_THREAD_LIST
|
||||||
static void add_signal_thread_list(rb_thread_t *th);
|
static void add_signal_thread_list(rb_thread_t *th);
|
||||||
static void remove_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
|
#endif
|
||||||
|
|
||||||
static pthread_key_t ruby_native_thread_key;
|
static pthread_key_t ruby_native_thread_key;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
#endif
|
#endif
|
||||||
typedef pthread_t rb_thread_id_t;
|
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 {
|
typedef struct rb_thread_cond_struct {
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
|
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 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_lock(rb_nativethread_lock_t *lock);
|
||||||
static int native_mutex_unlock(rb_thread_lock_t *lock);
|
static int native_mutex_unlock(rb_nativethread_lock_t *lock);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
w32_error(const char *func)
|
w32_error(const char *func)
|
||||||
|
@ -331,7 +331,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
native_mutex_lock(rb_thread_lock_t *lock)
|
native_mutex_lock(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
w32_mutex_lock(lock->mutex);
|
w32_mutex_lock(lock->mutex);
|
||||||
|
@ -342,7 +342,7 @@ native_mutex_lock(rb_thread_lock_t *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
native_mutex_unlock(rb_thread_lock_t *lock)
|
native_mutex_unlock(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
thread_debug("release mutex: %p\n", lock->mutex);
|
thread_debug("release mutex: %p\n", lock->mutex);
|
||||||
|
@ -354,7 +354,7 @@ native_mutex_unlock(rb_thread_lock_t *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
native_mutex_trylock(rb_thread_lock_t *lock)
|
native_mutex_trylock(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
int result;
|
int result;
|
||||||
|
@ -374,7 +374,7 @@ native_mutex_trylock(rb_thread_lock_t *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
native_mutex_initialize(rb_thread_lock_t *lock)
|
native_mutex_initialize(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
lock->mutex = w32_mutex_create();
|
lock->mutex = w32_mutex_create();
|
||||||
|
@ -385,7 +385,7 @@ native_mutex_initialize(rb_thread_lock_t *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
native_mutex_destroy(rb_thread_lock_t *lock)
|
native_mutex_destroy(rb_nativethread_lock_t *lock)
|
||||||
{
|
{
|
||||||
#if USE_WIN32_MUTEX
|
#if USE_WIN32_MUTEX
|
||||||
w32_close_handle(lock->mutex);
|
w32_close_handle(lock->mutex);
|
||||||
|
@ -442,7 +442,7 @@ native_cond_broadcast(rb_thread_cond_t *cond)
|
||||||
|
|
||||||
|
|
||||||
static int
|
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;
|
DWORD r;
|
||||||
struct cond_event_entry entry;
|
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
|
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);
|
return native_cond_timedwait_ms(cond, mutex, INFINITE);
|
||||||
}
|
}
|
||||||
|
@ -495,7 +495,7 @@ abs_timespec_to_timeout_ms(struct timespec *ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
unsigned long timeout_ms;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ typedef HANDLE rb_thread_id_t;
|
||||||
typedef union rb_thread_lock_union {
|
typedef union rb_thread_lock_union {
|
||||||
HANDLE mutex;
|
HANDLE mutex;
|
||||||
CRITICAL_SECTION crit;
|
CRITICAL_SECTION crit;
|
||||||
} rb_thread_lock_t;
|
} rb_nativethread_lock_t;
|
||||||
|
|
||||||
typedef struct rb_thread_cond_struct {
|
typedef struct rb_thread_cond_struct {
|
||||||
struct cond_event_entry *next;
|
struct cond_event_entry *next;
|
||||||
|
|
15
vm_core.h
15
vm_core.h
|
@ -24,13 +24,7 @@
|
||||||
#include "method.h"
|
#include "method.h"
|
||||||
#include "ruby_atomic.h"
|
#include "ruby_atomic.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#include "thread_native.h"
|
||||||
#include "thread_win32.h"
|
|
||||||
#elif defined(HAVE_PTHREAD_H)
|
|
||||||
#include "thread_pthread.h"
|
|
||||||
#else
|
|
||||||
#error "unsupported thread type"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ENABLE_VM_OBJSPACE
|
#ifndef ENABLE_VM_OBJSPACE
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -341,7 +335,7 @@ typedef struct rb_vm_struct {
|
||||||
VALUE self;
|
VALUE self;
|
||||||
|
|
||||||
rb_global_vm_lock_t gvl;
|
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 *main_thread;
|
||||||
struct rb_thread_struct *running_thread;
|
struct rb_thread_struct *running_thread;
|
||||||
|
@ -558,7 +552,7 @@ typedef struct rb_thread_struct {
|
||||||
|
|
||||||
rb_atomic_t interrupt_flag;
|
rb_atomic_t interrupt_flag;
|
||||||
unsigned long interrupt_mask;
|
unsigned long interrupt_mask;
|
||||||
rb_thread_lock_t interrupt_lock;
|
rb_nativethread_lock_t interrupt_lock;
|
||||||
rb_thread_cond_t interrupt_cond;
|
rb_thread_cond_t interrupt_cond;
|
||||||
struct rb_unblock_callback unblock;
|
struct rb_unblock_callback unblock;
|
||||||
VALUE locking_mutex;
|
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);
|
void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
|
||||||
int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th);
|
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 { \
|
#define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
|
||||||
if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
|
if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
|
||||||
th->pending_interrupt_queue_checked = 0; \
|
th->pending_interrupt_queue_checked = 0; \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue