Permalink
Switch branches/tags
Commits on Apr 1, 2010
  1. * include/ruby/ruby.h (InitVM): calls per-VM initialization in

      single VM, but does nothing in MVM.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@27162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Apr 1, 2010
  2. * merged from trunk r27020:27160.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@27161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Apr 1, 2010
Commits on Mar 23, 2010
  1. * merged from trunk r26967:27020.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@27021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Mar 23, 2010
Commits on Mar 18, 2010
  1. * Makefile.in (miniruby): link $(NORMALMAINOBJ).

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Mar 18, 2010
Commits on Mar 17, 2010
  1. * merged from trunk r26939:26967.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Mar 17, 2010
Commits on Mar 15, 2010
  1. * merged from trunk r26885:26939.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Mar 15, 2010
Commits on Mar 12, 2010
  1. * merged from trunk r26747:26885.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Mar 12, 2010
Commits on Feb 24, 2010
  1. * merged from trunk r26697:26747.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 24, 2010
Commits on Feb 17, 2010
  1. * vm.c (InitVM_VM): fixed commit miss.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 17, 2010
  2. * merged from trunk r26678:26697.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 17, 2010
  3. * 2010-02-17

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    svn committed Feb 17, 2010
  4. * thread_pthread.c (native_thread_init_stack): fixed merge miss.

    * variable.c (rb_ivar_count): ditto.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 17, 2010
Commits on Feb 16, 2010
  1. * merged from trunk r25728:26678.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 16, 2010
Commits on Feb 12, 2010
  1. * vm_core.h (enum ruby_vm_interrupted_bits): named.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 12, 2010
  2. * 2010-02-13

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    svn committed Feb 12, 2010
  3. * (ruby_vm_send_signal): deal with signals properly.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@26653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Feb 12, 2010
Commits on Nov 20, 2009
  1. * thread.c (rb_queue_mark): mark possible objects.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 20, 2009
  2. * vm.c (rb_vm_s_parent, rb_vm_parent): new methods to return the

      parent VM.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 20, 2009
  3. * file.c (Init_File): initialize key for separator only once.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 20, 2009
Commits on Nov 19, 2009
  1. * vm.c (rb_vm_start): handshake.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 19, 2009
  2. * string.c (rb_str_copy_to_vm): reset instance variables.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 19, 2009
  3. commit miss.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 19, 2009
  4. * vm.c (rb_vm_send, rb_vm_recv): supported strings.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 19, 2009
  5. * thread.c (rb_queue_shift_wait): fixed the case of no-timeout.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 19, 2009
Commits on Nov 17, 2009
  1. * vm_core.h (rb_vm_t): manage references from other VMs.

    * mvm.c (ruby_vm_destruct): ditto.
    
    * vm.c (ruby_vm_free, vm_init2, vm_create, InitVM_VM): ditto.
    
    * vm.c (rb_vm_send): reject terminated VM.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 17, 2009
  2. * 2009-11-17

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    svn committed Nov 17, 2009
  3. * vm_core.h: fixed function names.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 17, 2009
Commits on Nov 16, 2009
  1. * regint.h (USE_PARSE_TREE_NODE_RECYCLE): disabled.

    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25802 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 16, 2009
  2. * dir.c (ruby_dirfd): need O_DIRECTORY and O_LARGEFILE.

    * vm.c (ruby_make_bare_vm): initialize thread cwd.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 16, 2009
  3. * thread_pthread.c (get_stack): fixed stack start address on the

      platforms using pthread_attr_t.
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 16, 2009
Commits on Nov 15, 2009
  1. * thread.c (rb_queue_shift_wait): added.

    * vm.c (rb_vm_send, rb_vm_recv): new methods.
    
    * vm_core.h (rb_queue_t): added condition variable.
    
    * vm_core.h (rb_vm_t): moved message queue from rb_thread_t.
    
    Index: vm_core.h
    ===================================================================
    --- vm_core.h	(revision 25770)
    +++ vm_core.h	(working copy)
    @@ -265,4 +265,15 @@ void rb_objspace_free(struct rb_objspace
     #endif
     
    +typedef struct rb_queue_element {
    +    struct rb_queue_element *next;
    +    void *value;
    +} rb_queue_element_t;
    +
    +typedef struct rb_queue {
    +    rb_thread_lock_t lock;
    +    rb_thread_cond_t wait;
    +    rb_queue_element_t *head, **tail;
    +} rb_queue_t;
    +
     typedef struct rb_vm_struct {
         VALUE self;
    @@ -311,4 +322,8 @@ typedef struct rb_vm_struct {
         } trap_list[RUBY_NSIG];
     
    +    struct {
    +	rb_queue_t message;
    +    } queue;
    +
         /* hook */
         rb_event_hook_t *event_hooks;
    @@ -397,18 +412,9 @@ struct rb_unblock_callback {
     struct rb_mutex_struct;
     
    -typedef struct rb_queue_element {
    -    struct rb_queue_element *next;
    -    void *value;
    -} rb_queue_element_t;
    -
    -typedef struct rb_queue {
    -    rb_thread_lock_t lock;
    -    rb_queue_element_t *head, **tail;
    -} rb_queue_t;
    -
     void rb_queue_initialize(rb_queue_t *);
     void rb_queue_destroy(rb_queue_t *);
     int rb_queue_push(rb_queue_t *, void *);
     int rb_queue_shift(rb_queue_t *, void **);
    +int rb_queue_shift_wait(rb_queue_t *, void **, const struct timeval *);
     int rb_queue_empty_p(const rb_queue_t *);
     
    @@ -458,5 +464,5 @@ typedef struct rb_thread_struct
     
         struct {
    -	rb_queue_t signal, message;
    +	rb_queue_t signal;
         } queue;
     
    Index: thread.c
    ===================================================================
    --- thread.c	(revision 25778)
    +++ thread.c	(working copy)
    @@ -876,4 +876,7 @@ getclockofday(struct timeval *tp)
     }
     
    +static void add_tv(struct timeval *to, const struct timeval *from);
    +static int subtract_tv(struct timeval *to, const struct timeval *from);
    +
     static void
     sleep_timeval(rb_thread_t *th, struct timeval tv)
    @@ -883,9 +886,5 @@ sleep_timeval(rb_thread_t *th, struct ti
     
         getclockofday(&to);
    -    to.tv_sec += tv.tv_sec;
    -    if ((to.tv_usec += tv.tv_usec) >= 1000000) {
    -	to.tv_sec++;
    -	to.tv_usec -= 1000000;
    -    }
    +    add_tv(&to, &tv);
     
         th->status = THREAD_STOPPED;
    @@ -893,15 +892,10 @@ sleep_timeval(rb_thread_t *th, struct ti
     	native_sleep(th, &tv);
     	RUBY_VM_CHECK_INTS();
    +	tv = to;
     	getclockofday(&tvn);
    -	if (to.tv_sec < tvn.tv_sec) break;
    -	if (to.tv_sec == tvn.tv_sec && to.tv_usec <= tvn.tv_usec) break;
    +	if (!subtract_tv(&tv, &tvn)) break;
     	thread_debug("sleep_timeval: %ld.%.6ld > %ld.%.6ld\n",
     		     (long)to.tv_sec, (long)to.tv_usec,
     		     (long)tvn.tv_sec, (long)tvn.tv_usec);
    -	tv.tv_sec = to.tv_sec - tvn.tv_sec;
    -	if ((tv.tv_usec = to.tv_usec - tvn.tv_usec) < 0) {
    -	    --tv.tv_sec;
    -	    tv.tv_usec += 1000000;
    -	}
         } while (th->status == THREAD_STOPPED);
         th->status = prev_status;
    @@ -1137,4 +1131,5 @@ void
     rb_queue_initialize(rb_queue_t *que)
     {
    +    native_cond_initialize(&que->wait);
         ruby_native_thread_lock_initialize(&que->lock);
         que->head = 0;
    @@ -1155,4 +1150,5 @@ rb_queue_destroy(rb_queue_t *que)
         ruby_native_thread_unlock(&que->lock);
         native_mutex_destroy(&que->lock);
    +    native_cond_destroy(&que->wait);
     }
     
    @@ -1167,8 +1163,45 @@ rb_queue_push(rb_queue_t *que, void *val
         *que->tail = e;
         que->tail = &e->next;
    +    ruby_native_cond_signal(&que->wait);
         ruby_native_thread_unlock(&que->lock);
         return Qtrue;
     }
     
    +#define QUEUE_SHIFT(e, que) (	       \
    +	(e = que->head) != 0 &&	       \
    +	((que->head = e->next) != 0 || \
    +	 (que->tail = &que->head, 1)))
    +
    +int
    +rb_queue_shift_wait(rb_queue_t *que, void **value, const struct timeval *tv)
    +{
    +    rb_queue_element_t *e;
    +    struct timeval to, td, tvn;
    +
    +    if (tv) {
    +	getclockofday(&to);
    +	add_tv(&to, tv);
    +    }
    +    ruby_native_thread_lock(&que->lock);
    +    while (!QUEUE_SHIFT(e, que) &&
    +	   native_cond_timedwait(&que->wait, &que->lock, tv) == ETIMEDOUT) {
    +	if (tv) {
    +	    if (QUEUE_SHIFT(e, que)) break;
    +	    td = to;
    +	    getclockofday(&tvn);
    +	    if (!subtract_tv(&td, &tvn)) break;
    +	    tv = &td;
    +	}
    +    }
    +    ruby_native_thread_unlock(&que->lock);
    +    if (!e) {
    +	errno = ETIMEDOUT;
    +	return FALSE;
    +    }
    +    *value = e->value;
    +    free(e);
    +    return TRUE;
    +}
    +
     int
     rb_queue_shift(rb_queue_t *que, void **value)
    @@ -2479,4 +2512,5 @@ cmp_tv(const struct timeval *a, const st
         return (d != 0) ? d : (a->tv_usec - b->tv_usec);
     }
    +#endif
     
     static int
    @@ -2494,5 +2528,14 @@ subtract_tv(struct timeval *rest, const 
         return 1;
     }
    -#endif
    +
    +static void
    +add_tv(struct timeval *to, const struct timeval *ta)
    +{
    +    to->tv_sec += ta->tv_sec;
    +    if ((to->tv_usec += ta->tv_usec) >= 1000000) {
    +	to->tv_sec++;
    +	to->tv_usec -= 1000000;
    +    }
    +}
     
     static int
    Index: vm.c
    ===================================================================
    --- vm.c	(revision 25779)
    +++ vm.c	(working copy)
    @@ -1504,4 +1504,5 @@ rb_vm_free(void *ptr)
     	ruby_native_cond_signal(&vm->global_vm_waiting);
     	ruby_native_cond_destroy(&vm->global_vm_waiting);
    +	rb_queue_destroy(&vm->queue.message);
     #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
     	if (objspace) {
    @@ -1538,4 +1539,5 @@ vm_init2(rb_vm_t *vm)
         ruby_native_thread_lock_initialize(&vm->global_vm_lock);
         ruby_native_cond_initialize(&vm->global_vm_waiting);
    +    rb_queue_initialize(&vm->queue.message);
         vm->objspace = rb_objspace_alloc();
         vm->src_encoding_index = -1;
    @@ -1689,5 +1691,4 @@ thread_free(void *ptr)
     #endif
     
    -	rb_queue_destroy(&th->queue.message);
     	rb_queue_destroy(&th->queue.signal);
     
    @@ -1757,5 +1758,4 @@ th_init(rb_thread_t *th, VALUE self)
     
         rb_queue_initialize(&th->queue.signal);
    -    rb_queue_initialize(&th->queue.message);
     
         /* allocate thread stack */
    @@ -2062,4 +2062,46 @@ rb_vm_join(VALUE self)
     }
     
    +VALUE
    +rb_vm_send(VALUE self, VALUE val)
    +{
    +    rb_vm_t *vm;
    +
    +    GetVMPtr(self, vm);
    +    if (!rb_special_const_p(val) && vm->objspace != GET_VM()->objspace) {
    +	rb_raise(rb_eTypeError, "expected special constants");
    +    }
    +    if (!rb_queue_push(&vm->queue.message, (void *)val))
    +	rb_sys_fail(0);
    +    return (VALUE)val;
    +}
    +
    +VALUE
    +rb_vm_recv(VALUE self, const struct timeval *tv)
    +{
    +    rb_vm_t *vm;
    +    void *val;
    +
    +    GetVMPtr(self, vm);
    +    if (!rb_queue_shift_wait(&vm->queue.message, &val, tv))
    +	rb_sys_fail(0);
    +    if (!rb_special_const_p((VALUE)val)) {
    +	rb_raise(rb_eTypeError, "expected special constants");
    +    }
    +    return (VALUE)val;
    +}
    +
    +struct timeval rb_time_interval(VALUE);
    +
    +static VALUE
    +rb_vm_recv_m(int argc, VALUE *argv, VALUE self)
    +{
    +    struct timeval timeout = {0, 0}, *t = 0;
    +    if (rb_scan_args(argc, argv, "01", 0)) {
    +	timeout = rb_time_interval(argv[0]);
    +	t = &timeout;
    +    }
    +    return rb_vm_recv(self, t);
    +}
    +
     void
     Init_VM(void)
    @@ -2080,4 +2122,6 @@ InitVM_VM(void)
         rb_define_method(rb_cRubyVM, "to_s", rb_vm_to_s, 0);
         rb_define_method(rb_cRubyVM, "start", rb_vm_start, 0);
    +    rb_define_method(rb_cRubyVM, "send", rb_vm_send, 1);
    +    rb_define_method(rb_cRubyVM, "recv", rb_vm_recv_m, -1);
         rb_define_method(rb_cRubyVM, "join", rb_vm_join, 0);
         rb_define_singleton_method(rb_cRubyVM, "current", rb_vm_current, 0);
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 15, 2009
  2. * vm.c (rb_vm_current): new method RubyVM.current.

    * vm.c (rb_vm_to_s): include address of rb_vm_t in RubyVM#to_s.
    
    Index: vm.c
    ===================================================================
    --- vm.c	(revision 25770)
    +++ vm.c	(working copy)
    @@ -2003,4 +2003,22 @@ rb_vm_initialize(int argc, VALUE *argv, 
     }
     
    +static VALUE
    +rb_vm_current(VALUE self)
    +{
    +    return GET_VM()->self;
    +}
    +
    +static VALUE
    +rb_vm_to_s(VALUE self)
    +{
    +    rb_vm_t *vm;
    +    VALUE str = rb_call_super(0, 0);
    +
    +    rb_str_set_len(str, RSTRING_LEN(str)-1);
    +    GetVMPtr(self, vm);
    +    rb_str_catf(str, ":(%p)>", vm);
    +    return str;
    +}
    +
     static rb_thread_t *vm_make_main_thread(rb_vm_t *vm);
     
    @@ -2060,6 +2078,8 @@ InitVM_VM(void)
         rb_define_alloc_func(rb_cRubyVM, rb_vm_s_alloc);
         rb_define_method(rb_cRubyVM, "initialize", rb_vm_initialize, -1);
    +    rb_define_method(rb_cRubyVM, "to_s", rb_vm_to_s, 0);
         rb_define_method(rb_cRubyVM, "start", rb_vm_start, 0);
         rb_define_method(rb_cRubyVM, "join", rb_vm_join, 0);
    +    rb_define_singleton_method(rb_cRubyVM, "current", rb_vm_current, 0);
     
         /* ::VM::FrozenCore */
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 15, 2009
  3. * mvm.c (ruby_vm_new): create new vm unless initial vm.

    * thread.c (thread_start_func_2): ruby_vm_destruct destroys
      global_vm_lock.
    
    Index: mvm.c
    ===================================================================
    --- mvm.c	(revision 25770)
    +++ mvm.c	(working copy)
    @@ -28,6 +28,5 @@ ruby_vm_new(int argc, char *argv[])
         rb_vm_t *vm = ruby_init();
     
    -    if (!vm) return 0;
    -    if (!(vm = ruby_make_bare_vm())) return 0;
    +    if (!vm && !(vm = ruby_make_bare_vm())) return 0;
         vm->argc = argc;
         vm->argv = argv;
    Index: thread.c
    ===================================================================
    --- thread.c	(revision 25770)
    +++ thread.c	(working copy)
    @@ -542,9 +542,11 @@ thread_start_func_2(rb_thread_t *th, VAL
     	int signo = 0;
     	ruby_vm_cleanup(th->vm, state, &signo);
    -	if (signo && !ruby_vm_alone()) signo = 0;
    +	if (signo && !ruby_vm_main_p(th->vm)) signo = 0;
     	ruby_vm_destruct(th->vm);
     	if (signo) ruby_default_signal(signo);
         }
    -    native_mutex_unlock(&th->vm->global_vm_lock);
    +    else {
    +	native_mutex_unlock(&th->vm->global_vm_lock);
    +    }
     
         return 0;
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 15, 2009
  4. * thread.c (rb_thread_start_timer_thread),

      thread_{pthread,win32}.c (native_stop_timer_thread): deal with
      working count.
    
    Index: thread.c
    ===================================================================
    --- thread.c	(revision 25770)
    +++ thread.c	(working copy)
    @@ -2814,5 +2814,5 @@ void
     rb_thread_start_timer_thread(void)
     {
    -    system_working = 1;
    +    system_working++;
         rb_thread_create_timer_thread();
     }
    Index: thread_pthread.c
    ===================================================================
    --- thread_pthread.c	(revision 25770)
    +++ thread_pthread.c	(working copy)
    @@ -842,5 +842,5 @@ native_stop_timer_thread(void)
         int stopped;
         native_mutex_lock(&timer_thread_lock);
    -    stopped = --system_working <= 0;
    +    stopped = --system_working == 0;
         if (stopped) {
     	native_cond_signal(&timer_thread_cond);
    Index: thread_win32.c
    ===================================================================
    --- thread_win32.c	(revision 25770)
    +++ thread_win32.c	(working copy)
    @@ -596,5 +596,5 @@ static int
     native_stop_timer_thread(void)
     {
    -    int stopped = --system_working <= 0;
    +    int stopped = --system_working == 0;
         if (stopped) {
     	SetEvent(timer_thread_lock);
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 15, 2009
  5. * 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)
     {
         /* */
    
    
    git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/mvm@25776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
    nobu committed Nov 15, 2009