diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-19 04:40:22 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-19 04:40:22 +0000 |
commit | 4ea96ece8400f1c6caa8a2429f6d93f15434238f (patch) | |
tree | 577fa0eb2d207dca593a9a0e8316dde7fa15ecfb /thread.c | |
parent | b945ad289f14c1b1ba65bdd9a4e1106f3cee134c (diff) | |
download | ruby-4ea96ece8400f1c6caa8a2429f6d93f15434238f.tar.gz |
* internal.h: added a declaration of ruby_kill().
* thread.c (ruby_kill): helper function of kill().
* signal.c (rb_f_kill): use ruby_kill() instead of kill().
* signal.c (rb_f_kill): call rb_thread_execute_interrupts()
to ensure that make SignalException if sent a signal
to myself. [Bug #7951] [ruby-core:52864]
* vm_core.h (typedef struct rb_thread_struct): added
th->interrupt_cond.
* thread.c (rb_threadptr_interrupt_common): added to
initialization of th->interrupt_cond.
* thread.c (thread_create_core): ditto.
* test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
the above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -337,6 +337,7 @@ rb_threadptr_interrupt_common(rb_thread_t *th, int trap) else { /* none */ } + native_cond_signal(&th->interrupt_cond); native_mutex_unlock(&th->interrupt_lock); } @@ -624,6 +625,7 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) th->interrupt_mask = 0; native_mutex_initialize(&th->interrupt_lock); + native_cond_initialize(&th->interrupt_cond, RB_CONDATTR_CLOCK_MONOTONIC); /* kick thread */ err = native_thread_create(th); @@ -5055,6 +5057,8 @@ Init_Thread(void) gvl_acquire(th->vm, th); native_mutex_initialize(&th->vm->thread_destruct_lock); native_mutex_initialize(&th->interrupt_lock); + native_cond_initialize(&th->interrupt_cond, + RB_CONDATTR_CLOCK_MONOTONIC); th->pending_interrupt_queue = rb_ary_tmp_new(0); th->pending_interrupt_queue_checked = 0; @@ -5198,3 +5202,22 @@ rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data) return rb_ensure(b_proc, data, rb_ary_pop, cur_th->pending_interrupt_mask_stack); } + +void +ruby_kill(pid_t pid, int sig) +{ + int err; + rb_thread_t *th = GET_THREAD(); + rb_vm_t *vm = GET_VM(); + + if ((th == vm->main_thread) && (pid == getpid())) { + native_mutex_lock(&th->interrupt_lock); + err = kill(pid, sig); + native_cond_wait(&th->interrupt_cond, &th->interrupt_lock); + native_mutex_unlock(&th->interrupt_lock); + } else { + err = kill(pid, sig); + } + if (err < 0) + rb_sys_fail(0); +} |