diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-20 10:47:53 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-20 10:47:53 +0000 |
commit | 9f06a9618a54a2117759537573de77a6a58c57ea (patch) | |
tree | 329d42bdbd0d45463caf6b6f3c67c9443f9153be | |
parent | abc2a8b24620d2e355d72e540a9c5a33dd6ca912 (diff) | |
download | ruby-9f06a9618a54a2117759537573de77a6a58c57ea.tar.gz ruby-9f06a9618a54a2117759537573de77a6a58c57ea.tar.xz ruby-9f06a9618a54a2117759537573de77a6a58c57ea.zip |
* gc.h, vm_core.h: decl of rb_gc_save_machine_context()
should be at vm_core.h.
* include/ruby/ruby.h, intern.h: remove type rb_thread_t.
* include/ruby/intern.h: change rb_unblock_function_t,
rb_unblock_function_t.
* file.c, process.c: apply above changes.
* thread.c, thread_pthread.ci, thread_win32.ci: ditto.
* io.c: support blocking open (2). [ruby-core:13614]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | gc.h | 2 | ||||
-rw-r--r-- | include/ruby/intern.h | 5 | ||||
-rw-r--r-- | include/ruby/ruby.h | 3 | ||||
-rw-r--r-- | io.c | 24 | ||||
-rw-r--r-- | process.c | 2 | ||||
-rw-r--r-- | thread.c | 46 | ||||
-rw-r--r-- | thread_pthread.ci | 9 | ||||
-rw-r--r-- | thread_win32.ci | 13 | ||||
-rw-r--r-- | vm_core.h | 4 |
11 files changed, 86 insertions, 40 deletions
@@ -1,3 +1,19 @@ +Tue Nov 20 19:36:21 2007 Koichi Sasada <[email protected]> + + * gc.h, vm_core.h: decl of rb_gc_save_machine_context() + should be at vm_core.h. + + * include/ruby/ruby.h, intern.h: remove type rb_thread_t. + + * include/ruby/intern.h: change rb_unblock_function_t, + rb_unblock_function_t. + + * file.c, process.c: apply above changes. + + * thread.c, thread_pthread.ci, thread_win32.ci: ditto. + + * io.c: support blocking open (2). [ruby-core:13614] + Tue Nov 20 17:10:11 2007 Tanaka Akira <[email protected]> * io.c (rb_io_close_on_exec_p): new method IO#close_on_exec?. @@ -3172,7 +3172,7 @@ extern unsigned long __attribute__((stdcall)) GetLastError(void); #endif static VALUE -rb_thread_flock(rb_thread_t *th, void *data) +rb_thread_flock(void *data) { #ifdef __CYGWIN__ int old_errno = errno; @@ -10,8 +10,6 @@ NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p)); #define USE_CONSERVATIVE_STACK_END #endif -NOINLINE(void rb_gc_save_machine_context(rb_thread_t *)); - /* for GC debug */ #ifndef RUBY_MARK_FREE_DEBUG diff --git a/include/ruby/intern.h b/include/ruby/intern.h index ca6937a42..dbb9a9b07 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -543,9 +543,8 @@ VALUE rb_struct_iv_get(VALUE, const char*); VALUE rb_struct_s_members(VALUE); VALUE rb_struct_members(VALUE); /* thread.c */ -typedef struct rb_thread_struct rb_thread_t; -typedef void rb_unblock_function_t(rb_thread_t *, void *); -typedef VALUE rb_blocking_function_t(rb_thread_t *th, void *); +typedef void rb_unblock_function_t(void *); +typedef VALUE rb_blocking_function_t(void *); VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data1, rb_unblock_function_t *ubf, void *data2); #define RB_UBF_DFL ((rb_unblock_function_t *)-1) diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 581c1957d..384f7f4f5 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -963,11 +963,8 @@ typedef struct rb_event_hook_struct { struct rb_event_hook_struct *next; } rb_event_hook_t; -void rb_thread_add_event_hook(rb_thread_t *th, rb_event_hook_func_t func, - rb_event_flag_t events, VALUE data); void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); -int rb_thread_remove_event_hook(rb_thread_t *th, rb_event_hook_func_t func); int rb_remove_event_hook(rb_event_hook_func_t func); #if defined(__cplusplus) @@ -3015,16 +3015,36 @@ rb_io_modenum_mode(int flags) return NULL; /* not reached */ } +struct sysopen_struct { + char *fname; + int flag; + unsigned int mode; +}; + +static VALUE +sysopen_func(void *ptr) +{ + struct sysopen_struct *data = ptr; + return (VALUE)open(data->fname, data->flag, data->mode); +} + +static int +rb_sysopen_internal(char *fname, int flags, unsigned int mode) +{ + struct sysopen_struct data = {fname, flags, mode}; + return (int)rb_thread_blocking_region(sysopen_func, &data, RB_UBF_DFL, 0); +} + static int rb_sysopen(char *fname, int flags, unsigned int mode) { int fd; - fd = open(fname, flags, mode); + fd = rb_sysopen_internal(fname, flags, mode); if (fd < 0) { if (errno == EMFILE || errno == ENFILE) { rb_gc(); - fd = open(fname, flags, mode); + fd = rb_sysopen_internal(fname, flags, mode); } if (fd < 0) { rb_sys_fail(fname); @@ -593,7 +593,7 @@ struct waitpid_arg { #endif static VALUE -rb_waitpid_blocking(rb_thread_t *th, void *data) +rb_waitpid_blocking(void *data) { rb_pid_t result; #ifndef NO_WAITPID @@ -220,7 +220,7 @@ rb_thread_interrupt(rb_thread_t *th) native_mutex_lock(&th->interrupt_lock); th->interrupt_flag = 1; if (th->unblock_function) { - (th->unblock_function)(th, th->unblock_function_arg); + (th->unblock_function)(th->unblock_function_arg); } else { /* none */ @@ -671,10 +671,11 @@ rb_thread_blocking_region( if (ubf == RB_UBF_DFL) { ubf = ubf_select; + data2 = th; } BLOCKING_REGION({ - val = func(th, data1); + val = func(data1); }, ubf, data2); return val; @@ -1757,7 +1758,7 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except, BLOCKING_REGION({ result = select(n, read, write, except, timeout); if (result < 0) lerrno = errno; - }, ubf_select, 0); + }, ubf_select, GET_THREAD()); #endif errno = lerrno; @@ -2253,38 +2254,37 @@ rb_mutex_trylock(VALUE self) } static VALUE -lock_func(rb_thread_t *th, void *ptr) +lock_func(rb_thread_t *th, mutex_t *mutex) { int locked = 0; - mutex_t *mutex = (mutex_t *)ptr; while (locked == 0) { native_mutex_lock(&mutex->lock); - - if (mutex->th == 0) { - mutex->th = th; - locked = 1; - } - else { - mutex->cond_waiting++; - native_cond_wait(&mutex->cond, &mutex->lock); - - if (th->interrupt_flag) { - locked = 1; - } - else if (mutex->th == 0) { + { + if (mutex->th == 0) { mutex->th = th; locked = 1; } - } + else { + mutex->cond_waiting++; + native_cond_wait(&mutex->cond, &mutex->lock); + if (th->interrupt_flag) { + locked = 1; + } + else if (mutex->th == 0) { + mutex->th = th; + locked = 1; + } + } + } native_mutex_unlock(&mutex->lock); } return Qnil; } static void -lock_interrupt(rb_thread_t *th, void *ptr) +lock_interrupt(void *ptr) { mutex_t *mutex = (mutex_t *)ptr; native_mutex_lock(&mutex->lock); @@ -2311,11 +2311,13 @@ rb_mutex_lock(VALUE self) GetMutexPtr(self, mutex); while (mutex->th != th) { - rb_thread_blocking_region(lock_func, mutex, lock_interrupt, mutex); + BLOCKING_REGION({ + lock_func(th, mutex); + }, lock_interrupt, mutex); + RUBY_VM_CHECK_INTS(); } } - return self; } diff --git a/thread_pthread.ci b/thread_pthread.ci index 3874a46bd..6004d4aa3 100644 --- a/thread_pthread.ci +++ b/thread_pthread.ci @@ -346,8 +346,9 @@ native_thread_apply_priority(rb_thread_t *th) } static void -ubf_pthread_cond_signal(rb_thread_t *th, void *ptr) +ubf_pthread_cond_signal(void *ptr) { + rb_thread_t *th = (rb_thread_t *)ptr; thread_debug("ubf_pthread_cond_signal (%p)\n", th); pthread_cond_signal(&th->native_thread_data.sleep_cond); } @@ -363,8 +364,9 @@ ubf_select_each(rb_thread_t *th) } static void -ubf_select(rb_thread_t *th, void *ptr) +ubf_select(void *ptr) { + rb_thread_t *th = (rb_thread_t *)ptr; add_signal_thread_list(th); ubf_select_each(th); } @@ -403,6 +405,8 @@ native_sleep(rb_thread_t *th, struct timeval *tv) } else { th->unblock_function = ubf_pthread_cond_signal; + th->unblock_function_arg = th; + if (tv == 0) { thread_debug("native_sleep: pthread_cond_wait start\n"); pthread_cond_wait(&th->native_thread_data.sleep_cond, @@ -418,6 +422,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv) thread_debug("native_sleep: pthread_cond_timedwait end (%d)\n", r); } th->unblock_function = 0; + th->unblock_function_arg = 0; } pthread_mutex_unlock(&th->interrupt_lock); diff --git a/thread_win32.ci b/thread_win32.ci index c2a4a286a..d71040836 100644 --- a/thread_win32.ci +++ b/thread_win32.ci @@ -122,7 +122,7 @@ w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th) return ret; } -static void ubf_handle(rb_thread_t *th, void *ptr); +static void ubf_handle(void *ptr); #define ubf_select ubf_handle int @@ -136,7 +136,8 @@ rb_w32_wait_events(HANDLE *events, int num, DWORD timeout) { int ret; - BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout), ubf_handle, 0); + BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout), + ubf_handle, GET_THREAD()); return ret; } @@ -187,7 +188,8 @@ rb_w32_Sleep(unsigned long msec) { int ret; - BLOCKING_REGION(ret = rb_w32_sleep(msec), ubf_handle, 0); + BLOCKING_REGION(ret = rb_w32_sleep(msec), + ubf_handle, GET_THREAD()); return ret; } @@ -208,10 +210,12 @@ native_sleep(rb_thread_t *th, struct timeval *tv) int status = th->status; th->status = THREAD_STOPPED; th->unblock_function = ubf_handle; + th->unblock_function_arg = th; thread_debug("native_sleep start (%d)\n", (int)msec); ret = w32_wait_events(0, 0, msec, th); thread_debug("native_sleep done (%d)\n", ret); th->unblock_function = 0; + th->unblock_function_arg = 0; th->status = status; } GVL_UNLOCK_END(); @@ -465,8 +469,9 @@ native_thread_apply_priority(rb_thread_t *th) } static void -ubf_handle(rb_thread_t *th, void *ptr) +ubf_handle(void *ptr) { + rb_thread_t *th = (rb_thread_t *)ptr; thread_debug("ubf_handle: %p\n", th); w32_set_event(th->native_thread_data.interrupt_event); } @@ -360,6 +360,8 @@ struct rb_vm_trap_tag { #define RUBY_VM_VALUE_CACHE_SIZE 0x1000 #define USE_VALUE_CACHE 0 +typedef struct rb_thread_struct rb_thread_t; + struct rb_thread_struct { VALUE self; @@ -605,6 +607,8 @@ VALUE vm_call0(rb_thread_t *th, VALUE klass, VALUE recv, VALUE id, ID oid, int vm_get_sourceline(rb_control_frame_t *); +NOINLINE(void rb_gc_save_machine_context(rb_thread_t *)); + RUBY_EXTERN VALUE sysstack_error; /* for thread */ |