Граф коммитов

342 Коммитов

Автор SHA1 Сообщение Дата
kosaki 5e15194561 * thread.c (rb_thread_schedule_rec): move interrupt_flag check to
rb_thread_schedule().
  And also rename to rb_thead_schedule_limits() and remove
  sched_depth argument. It's no longer called recursive.
* thread.c (rb_thread_schedule): add to check interrupt_flag as
  above explained.

* thread.c (rb_threadptr_execute_interrupts_rec): rename to
  rb_threadptr_execute_interrupts_common() and remove sched_depth
  argument. It's no longer called recursive.

* thread.c (rb_thread_sleep): adapt the renaming.
* thread.c (rb_threadptr_execute_interrupts): ditto.
* thread.c (rb_thread_execute_interrupts): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-29 17:36:00 +00:00
kosaki ed0876f66d * thread.c (thread_s_pass): change RDoc description and remove
a sample code. The actual implementaion never behave as explained by
  an example. It's a documentation bug.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-29 16:34:51 +00:00
kosaki 3a9117011f * thread.c (rb_thread_stop): change RDoc sample code. The old
example is buggy and may cause deadlock. The patch is
  suggested by Heesob Park <phasis@gmail.com>. Thank you!
  [Bug #3606][ruby-core:31454]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-29 15:55:44 +00:00
kosaki b3ad7b9ea1 * thread.c (rb_thread_wakeup): change RDoc sample code. The old
example is buggy and may not display anything by a race.
  The patch is suggested by Heesob Parrk <phasis@gmail.com>.
  Thank you! [Bug #3606][ruby-core:31454]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-29 15:51:54 +00:00
kosaki b07b51f7fc * thread.c (rb_thread_run): change RDoc. The old example is buggy
and may cause deadlock. The patch is suggested by Heesob Park
  <phasis@gmail.com>. Thank you! [Bug #3606][ruby-core:31454]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-29 15:47:24 +00:00
nahi 4a42dda482 * thread.c (rb_thread_local_aref): RDoc fix. Thread#[] example
had a race. See #4480.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27 20:09:59 +00:00
ko1 d1d5d5e798 * thread_pthread.c: Stop polling in the timer thread when there are
no waiting thread.  If there are 2 or more runnable threads,
  the timer thread does polling.  Avoid polling makes power save
  for several computers (0.2W per a Ruby process, when I measured).
  If outside-event such as signal or Thread#kill was occuerred
  when the timer thread does not do polling, then wake-up
  the timer thread using communication-pipe (the timer thread
  waits this communication-pipe with select(2)).
  The discussion about this modification can be found from the post
  [ruby-core:33456] and other related posts.
  Note that Eric Wong and KOSAKI Motohiro give us the huge
  contributions for this modification.  Thanks.
* thread_pthread.c (rb_thread_wakeup_timer_thread): add a function.
  This function wakes up the timer thread using communication-pipe.
* thread.c (rb_thread_stop_timer_thread): add a parameter which
  specify closing communication-pipe or not.
* thread.c (rb_thread_terminate_all): do not stop timer thread here
  (ruby_cleanup() terminate timer thread).
* signal.c: wake up timer thread using
  rb_thread_wakeup_timer_thread() from signal handler.
* eval.c (ruby_cleanup): use rb_thread_stop_timer_thread(1).
* process.c: use rb_thread_stop_timer_thread(0)
  (reuse communication-pipe).
* thread_win32.c (rb_thread_wakeup_timer_thread): add a dummy
  function.
* vm_core.h: add and fix decl. of functions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27 00:30:41 +00:00
nagachika fb72e453f9 * thread.c (sleep_forever): now Kernel#sleep don't wakeup by
signal handler execution. [Bug #4072]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-25 14:28:56 +00:00
nagachika 1a196574c4 * thread.c (rb_threadptr_check_signal): remove unnecessary th->status
backup. fix race condition which may results unexpected main thread's
  status transition. see #4072

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-25 14:21:16 +00:00
akr 5ed8c08aa0 * eval.c, hash.c, load.c, proc.c, range.c, thread.c, time.c: don't
declare internal functions.

* internal.h, vm_core.h: declare internal functions.

* array.c: include internal.h.

* common.mk: update dependency for array.o.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 08:26:19 +00:00
akr 7da3ea811e * method.h, internal.h iseq.h: declare internal functions.
* compile.c, eval.c, iseq.c, object.c, parse.y, proc.c, process.c,
  thread.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c: don't
  declare internal functions.

  Note that rb_method_entry_eq() is defined in vm_method.c but
  there was a declaration in proc.c with different const-ness.
  Now it is declared in method.h with same const-ness to the
  definition.

* object.c (rb_mod_module_exec): don't declare functions declared in
  include/ruby/intern.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 03:49:33 +00:00
akr afd7e4668f * internal.h: declare more internal functions.
* iseq.h (rb_method_get_iseq): declared.

* compile.c, eval.c, eval_error.c, iseq.c, parse.y, proc.c, range.c,
  ruby.c, time.c, util.c, vm.c: don't declare internal functions.

* eval.c, parse.y, thread_pthread.c: non-existing function declarations
  removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 01:54:57 +00:00
akr e7996eb3cc * internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.

* iseq.h: declare rb_iseq_t dependent internal functions here.

* vm_core.h: declare rb_thread_t dependent internal functions here.

* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
  enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
  iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
  proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
  thread.c, time.c, transcode.c, variable.c, vm.c,
  tool/compile_prelude.rb: don't declare internal functions declared
  in above headers.  include above headers if required.

  Note that rb_thread_mark() was declared as
  void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
  void rb_thread_mark(void *ptr) in vm.c.  Now it is declared as
  the later in internal.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 22:43:38 +00:00
kosaki 3c23284734 * thread.c (rb_thread_schedule_rec): fix {UN,}LIKELY macro misuse.
* gc.c (rb_newobj): ditto.
* vm_insnhelper.c (vm_method_search): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-16 14:42:02 +00:00
nobu 685444569c * fix for build on solaris 10.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-16 00:12:55 +00:00
usa a8bdd28d10 * thread.c (do_select): Windows: no need to poll if select(2) is
cancelable.

* thread_win32.c (native_fd_select): new function to make select(2)
  cancelable.

* thread_win32.c (rb_w32_check_interrupt): new function for checking
  interrupt.

* win32/win32.c (rb_w32_select_with_thread): new function. cancelable
  select(2).

* win32/win32.c (rb_w32_select): use above function internally.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-15 18:04:13 +00:00
kosaki 2ebd80d115 * thread.c: remove BLOCKING_REGION_CORE() macro. It's no longer used
since r32021.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-15 14:13:01 +00:00
kosaki afd1a64cd6 * thread.c (rb_thread_schedule_rec): call gvl_yield() unconditionally.
* thread_pthread.c: remove HAVE_GVL_YIELD macro.
* thread_win32.c (gvl_yield): new. this fallback logic was moved from
  rb_thread_schedule_rec().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 15:06:30 +00:00
kosaki bcfc22b10e * thread_pthread.c: rewrite GVL completely.
* thread_win32.c: ditto.
* thread_pthread.h: ditto.
* vm_core.h: ditto.
* thread.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13 14:14:53 +00:00
kosaki f0041fa0fd * thread.c: remove th->transition_for_lock. It's thread unsafe.
[Bug #4723][ruby-dev:43563]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-12 06:58:15 +00:00
kosaki 614fcdf66c * thread.c: introduce spurious wakeup safe deadlock check.
[Bug #4696][ruby-dev:43554]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-12 06:55:12 +00:00
kosaki 9d4e471cf9 * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT,
RUBY_VM_SET_FINALIZER_INTERRUPT): use atomic ops for preventing
  interrupt_flag bit lost.
* thread.c (rb_threadptr_execute_interrupts_rec): ditto.
* vm_core.h (typedef struct rb_thread_struct): change type of
  interrupt_flag to rb_atomic_t.
* atomic.h: move atomic ops definition from signal.c.
* signal.c: remove atomic ops definition.
* common.mk (gc, signal, thread, cont): add to dependency to atomic.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-11 14:27:08 +00:00
akr 71fdb43e6e * thread.c (rb_thread_execute_interrupts): use GetThreadPtr to extract
rb_thread_t from VALUE.
  reorted by Motohiro KOSAKI.  [ruby-dev:43700]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-11 01:17:11 +00:00
akr 87f025da25 * io.c: fix IO.copy_stream interrupt handling.
based on the patch by Eric Wong.  [ruby-core:36156]

* vm_core.h (rb_thread_call_with_gvl): don't declare here.

* thread.c: include internal.h.
  (rb_thread_execute_interrupts): new function.

* internal.h (rb_thread_execute_interrupts): declared.
  (rb_thread_call_with_gvl): declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-09 15:02:46 +00:00
nagachika 1fdbe0f437 * gc.c (rb_objspace_call_finalizer): use rb_typeddata_is_kind_of() for
type check to get rid of a double free when main Thread has singleton
  class. [ruby-core:36741] [Bug #4828]
* thread.c (rb_obj_is_mutex): add a new utility function.
* vm.c (rb_obj_is_thread): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-09 14:45:56 +00:00
nagai e65e24bd27 * thread.c (ppoll): typo bug fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-26 23:48:31 +00:00
kosaki e48e12ec09 * thread.c (Init_Thread): add a code comment why the meaningless
line is necessary.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-21 19:12:10 +00:00
nobu 2082417a48 * eval.c (setup_exception): internal exception should be hidden
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31626 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-18 13:36:46 +00:00
kosaki 63d3eec7c4 * thread.c (rb_mutex_lock): remove remove_signal_thread_list() call.
It's meaningless because lock_interrupt doesn't call
  add_signal_thread_list().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-17 12:25:48 +00:00
kosaki d734c9dea2 * include/ruby/intern.h: resurrect old rb_fd_copy().
* thread.c (rb_fd_copy): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-15 14:57:35 +00:00
kosaki 2b7996e839 * include/ruby/intern.h: remove rb_fd_copy() to rb_fd_dup() and
rb_w32_fdcopy() to rb_w32_fd_dup().
* win32/win32.c: ditto.
* thread.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-15 14:51:09 +00:00
kosaki 76734388a2 * thread.c (rb_fd_zero): remove redundant zero fill.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 13:44:27 +00:00
kosaki 9468e945c8 * thread.c (rb_fd_init): remove volatile qualifier.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 13:40:56 +00:00
kosaki 156ccab796 * thread.c (rb_fd_init_copy): new internal api. It provide efficient
copy constructor semantics.
* thread.c (do_select): use rb_fd_init_copy().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 13:36:08 +00:00
kosaki ddcd5c2939 r31460 is wrong fix. fix it again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 13:22:12 +00:00
kosaki fa319c5774 fix incorrect native_cond_signal call when deadlock was detected.
* thread.c (lock_func): timedwait don't touch cond_waiting and
  cond_notifid variables.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07 06:20:39 +00:00
kosaki b2ea836ae7 mutex: deadlock check timeout use monotonic time.
* thread_pthread.c (native_cond_timeout): new internal api.
  it calculate a proper time for argument of native_cond_timedwait().
* thread_win32.c (native_cond_timeout): ditto.

* thread_pthread.c (thread_timer): use native_cond_timeout()
  instead of get_ts.
* thread.c (lock_func): ditto.

* thread_pthread.c (get_ts): removed. use native_cond_timeout().
* thread.c (init_lock_timeout): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 17:39:32 +00:00
kosaki a1cfaf4b1f * thread_pthread.h (rb_thread_cond_t): add clockid field. it's
no longer an alias of pthread_cond_t.
* thread_pthread.c: adapt new rb_thread_cond_t type.
* thread.c (mutex_alloc): ditto.
* thread_win32.c (native_cond_initialize): ditto.
* configure.in: add check for pthread_cond_attr_setclock() and
  clockid_t type.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 16:47:38 +00:00
kosaki 4a9883e92f * thread.c (rb_wait_for_single_fd): use ppoll() instead of poll()
if possible. based on a patch from Eric Wong. [ruby-core:36003].



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06 14:58:38 +00:00
kosaki c06da4735d * thread.c (rb_wait_for_single_fd): Fix wrong return value.
* test/-ext-/wait_for_single_fd/test_wait_for_single_fd.rb
(TestWaitForSingleFD#test_wait_for_closed_pipe): test for it.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31429 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-04 10:02:06 +00:00
kosaki 951b090130 * thread.c (rb_wait_for_single_fd): Added POLLNVAL check.
based on a patch from Eric Wong at [ruby-core:35991].



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-04 03:47:33 +00:00
kosaki 249fe0e742 * thread.c (rb_wait_for_single_fd): new. poll(2) based backend for rb_wait_for_single_fd().
Now only Linux uses it.

The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-04 01:07:03 +00:00
kosaki 9be37ca7d5 * thread.c (rb_wait_for_single_fd): new.
* thread.c (select_single): select(2) based backend for rb_wait_for_single_fd().

* io.c (make_writeconv): use rb_wait_for_single_fd() instaed of
  rb_thread_fd_select().
* io.c (rb_io_wait_readable): ditto.
* thread.c (rb_thread_wait_fd_rw): ditto.

* io.c (wait_readable): removed.
* thread.c (init_set_fd): new helper function.
* include/ruby/io.h (RB_WAITFD_IN, RB_WAITFD_PRI, RB_WAITFD_OUT):
  new constant for rb_single_wait_fd().

The patch was written by Eric Wong. [Ruby 1.9 - Feature #4531]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-04 00:59:57 +00:00
kosaki f081eca1d7 * thread.c (rb_fd_copy): fix wrong argument.This issue was pointed
out by Eric Wong. [ruby-core:35982]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-03 22:37:07 +00:00
nobu 55a1b1d97a * thread.c (rb_thread_select): preserve errno if no error
occurred.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-02 19:27:59 +00:00
kosaki 4d88169267 * thread.c (rb_thread_select): release GVL while waiting select().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-30 16:08:20 +00:00
kosaki 3c68095b8a * thread.c (do_select): Change arugment type to rb_fdset_t.
Now do_select() is free from unexpected hangup if
  HAVE_RB_FD_INIT=1 [Bug #4636]

* thread.c (rb_thread_fd_select, rb_thread_wait_fd_rw):
  adapt new argument type.

* thread.c (rb_thread_select): make dummy implementation.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-30 11:23:08 +00:00
kosaki 225fa965bc * thread.c (rb_fd_copy): Change function argument. Now
rb_fd_copy() has fully copy semantics.
* include/ruby/intern.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-30 11:18:14 +00:00
kosaki 4c926e9f15 * thread.c (do_select): remove useless ifdef. time calculation
is not heavy weight.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-30 11:08:39 +00:00
kosaki 9d4ae4ab0c fix indentation
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-04-29 03:23:13 +00:00