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

599 Коммитов

Автор SHA1 Сообщение Дата
zzak f7a7138d5b * thread.c (rb_thread_wakeup): rdoc formatting
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 03:58:36 +00:00
zzak e016ec1707 thread.c (rb_thread_group): rdoc formatting
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 03:53:13 +00:00
zzak 7c4084f9fb * thread.c (thread_raise_m): rdoc formatting
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-27 01:24:08 +00:00
nobu eed06bb043 thread.c: remove unnecessary sentence
* thread.c (thread_start): initialize method is not concerned with
  Thread.start and Thread.fork.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-25 04:10:54 +00:00
zzak 84e8862c56 * thread.c: Document Thread::new, clean up ::fork and mention calling
super if subclassing Thread


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-25 03:50:20 +00:00
zzak 1f9fa7c62f * thread.c: Document ThreadGroup::Default
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-24 05:29:06 +00:00
zzak 5feede6f3b * thread.c: Grammar for #backtrace_locations and ::handle_interrupt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-24 05:23:51 +00:00
zzak a153ce31a1 * thread.c: Documentation for Thread#backtrace_locations
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 07:52:46 +00:00
zzak 5f2e433813 * thread.c: Improved rdoc for ::handle_interrupt, ::pending_interrupt?
and #pending_interrupt?


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 07:00:51 +00:00
takano32 bd0be3c4fd Thu Jan 10 19:39:05 2013 TAKANO `takano32' Mitsuhiro <tak@no32.tk>
* thread.c: fix RB_GC_SAVE_MACHINE_REGISTER_STACK define for ia64.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-10 10:45:05 +00:00
usa 2f345f9de6 * ChangeLog: revert a part of r38595. 'iff' means 'if and only if', not typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 10:45:20 +00:00
usa a3d9672407 * bignum.c, include/ruby/intern.h (rb_big_eql): exported.
* thread.c (recursive_check): object_id maybe a Bignum, not Fixnum on
  LLP64.  see also r38493 and r38548.
  reported by Heesob Park at [ruby-core:51083] [Bug #7607], and patched
  by shirosaki at [ruby-core:51095]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 10:14:12 +00:00
ko1 48f320194a add empty line for style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-25 07:17:55 +00:00
ko1 0f9b33c793 * thread.c: rename methods:
from Thread.async_interrupt_timing to Thread.handle_interrupt,
  from Thread.async_interrupted? to Thread.pending_interrupt?.
  Also rename option from `defer' to `never'.
  [ruby-core:51074] [ruby-trunk - Feature #6762]
* vm_core.c, thread.c: rename functions and data structure
  `async_errinfo' to `pending_interrupt'.
* thread.c: add global variables sym_immediate, sym_on_blocking and
  sym_never.
* cont.c, process.c, vm.c, signal.c: ditto.
* lib/sync.rb, lib/thread.rb: catch up this renaming.
* test/ruby/test_thread.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-23 10:18:58 +00:00
nobu 482bf47d1f thread.c: ignore result of blocking_region_begin
* thread.c (BLOCKING_REGION): if fail_if_interrupted is false ignore
  the result of blocking_region_begin(), since it always is true in
  that case.  suppress "uninitialized" warnings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-23 05:35:15 +00:00
nagachika 6a35c26b2d * cont.c (rb_fiber_start): in case of jump with TAG_FATAL,
enqueue error into async_errinfo_queue, because you cannot call
  TH_TAG_JUMP() in this function. [ruby-dev:45218]  [Bug #5993]

* thread.c (rb_threadptr_execute_interrupts): now INT2FIX(TAG_FATAL)
  can be popped from async_errinfo_queue.

* vm.c (rb_vm_make_jump_tag_but_local_jump): revert r38441.
  rb_vm_make_jump_tag_but_local_jump() shouldn't return exception
  in case of state == TAG_FATAL.

* test/ruby/test_fiber.rb (test_exit_in_fiber): fix a test to illuminate
  Thread.exit should terminate current Thread.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 06:45:28 +00:00
kosaki b842263696 style fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-19 11:19:37 +00:00
kosaki 005db82d36 * thread.c (rb_thread_wait_fd_rw): fix infinite loop bug.
rb_wait_for_single_fd() never return positive number.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-18 10:07:05 +00:00
nobu 2ca5e8eeab * parse.y (yycompile0): adjust indent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-15 06:10:01 +00:00
kosaki e78d4e69fe * thread.c (rb_mutex_owned_p): remove static.
* io.c (io_flush_buffer): don't hold mutex if already have.
  Now recursive lock may occur when following scenario.
  fptr_finalize -> finish_writeconv_sync -> finish_writeconv
  -> io_fflush.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-15 05:40:18 +00:00
kosaki 47fa79203d * thread.c (rb_thread_wait_fd_rw): remove silly rb_thread_alone()
check.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-15 05:39:25 +00:00
nobu ce6a2c7fac thread.c: revert r38382 but deprecate rb_thread_polling()
* thread.c (rb_thread_polling): revert but deprecate.
* include/ruby/intern.h (rb_thread_polling): deprecate.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-15 01:22:44 +00:00
kosaki a24f2d9915 * file.c (rb_file_flock): use rb_thread_wait_for() instead of
rb_thread_polling(). When getting EAGAIN, we need to wait a
  while even if no multi threading.
* thread.c (sleep_for_polling, rb_thread_polling) removed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-14 18:08:40 +00:00
kosaki fe6b2e20e9 * thread.c (rb_uninterruptible): helper function for providing
temporary async_interrupt_timing(Object => :defer)

* io.c (rb_f_p): use rb_uninterruptible.
* io.c (rb_f_p_internal): helper function for rb_f_p().
* io.c (struct rb_f_p_arg): new struct for rb_f_p_internal.

* test/ruby/test_thread.rb (test_async_interrupt_and_p): test for
  the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-05 19:37:49 +00:00
tarui 17a11774ca * thread.c (rb_thread_s_async_interrupt_timing): have to check ints before jumpping out.
* test/ruby/test_thread.rb (test_async_interrupt_with_return): add test
	  rescue has to catch a queued async exception at the time of return.
	* test/ruby/test_thread.rb (test_async_interrupt_with_break): add test
	  rescue has to catch a queued async exception at the time of break.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-05 09:54:58 +00:00
tarui 64f634f1de * vm_core.h (RUBY_VM_CHECK_INTS_BLOCKING): check async queue everytime.
* thread.c (sleep_forever): check RUBY_VM_CHECK_INTS_BLOCKING first.
        * thread.c (sleep_timeval): ditto.
        * test/ruby/test_thread.rb (test_async_interrupt_blocking): add a test
          exceptions are correctly defared and raised on :on_blocking context.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 18:38:21 +00:00
kosaki 70d603a412 supress warning
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 16:06:43 +00:00
kosaki 3765f668c6 supress warning
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 16:05:40 +00:00
kosaki bbfbf662cc * thread.c (rb_mutex_owned_p): new method that return current
thread have the target mutex or not. [Feature #7505] [ruby-dev:46697]
* test/ruby/test_thread.rb (test_mutex_owned, test_mutex_owned2):
  test for the above.
* NEWS: new for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-04 16:02:07 +00:00
tarui c1e6052bfe * thread.c (RB_GC_SAVE_MACHINE_CONTEXT, rb_gc_save_machine_context):
extract rb_gc_save_machine_context to RB_GC_SAVE_MACHINE_CONTEXT.
	  NOTE: machine_regs and machine_stack_end must be set in current scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-02 10:28:27 +00:00
tarui d64a73e1dd revert r38141 for stack problem
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-02 08:56:27 +00:00
tarui 1e88b393e0 * thread.c (RB_GC_SAVE_MACHINE_CONTEXT, rb_gc_save_machine_context):
Don't set machine_regs and machine_stack_end with a different scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-02 08:45:14 +00:00
ko1 e742a446c8 * thread.c (Thread.async_interrupt_timing): fix RDoc.
:never is not used any more.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 18:47:00 +00:00
kosaki a113ab64b2 * thread.c (rb_threadptr_interrupt_mask, async_interrupt_timing_func):
merge into them into rb_thread_s_async_interrupt_timing.
* thread.c (rb_thread_s_async_interrupt_timing): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 17:39:59 +00:00
kosaki 279cd29b1b * thread.c (rb_threadptr_interrupt_mask): add argument check.
* thread.c (async_interrupt_timing_arg_check_i): helper function
  for the above.
* test/ruby/test_thread.rb (test_async_interrupt_timing_invalid_argument):
  test for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 17:39:48 +00:00
kosaki 15b25acd25 * vm_core.h (rb_vm_struct): add thread_destruct_lock field.
* thread.c (Init_Thread): ditto.
* thread.c (rb_vm_gvl_destroy): ditto.

* thread.c (thread_start_func_2): make sure vm->running_thread
  don't point to dead thread.
* thread.c (timer_thread_function): close a race against thead
  destruction. [Bug #4911][ruby-dev:43859]

* vm_core.h (rb_thread_set_current): reset running time of
  current thread instead of previous thread. We no longer
  assume previous running thread still live.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 13:52:34 +00:00
kosaki 2e72d1c323 revert r35486 (add rb_thread_t#yeiling field). because it doesn't help
to close a race.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 13:52:24 +00:00
ko1 bb4410a289 * thread.c: TracePoint#self returns invoking/exitting thread object
at thread_begin/end event.
* test/ruby/test_settracefunc.rb: fix test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 11:50:26 +00:00
ko1 719e0cd530 * thread.c: rename Thread.control_interrupt
to Thread.async_interrupt_timing.
  The option name `:never' is also changed to  `:defer'.
  [ruby-core:50375] [ruby-trunk - Feature #6762]
* thread.c: remove Thread.check_interrupt.
  This method is difficult to understand by name.
* thraed.c: add Thread.async_interrupted?.
  This method check any defered async interrupts.
* test/ruby/test_thread.rb: change tests for above.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30 09:28:35 +00:00
ko1 c86379402c * thread.c (rb_thread_interrupted): avoid warning of
implicit conversion.
* thread.c (rb_threadptr_execute_interrupts): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 22:44:51 +00:00
ko1 4db8340398 [EXPERIMENTAL: NEED DISCUSS]
* vm_trace.c: add events
* :thread_begin - hook at thread beggining.
* :thead_end - hook at thread ending.
* :b_call - hook at block enter.
* :b_return - hook at block leave.
  This change slow down block invocation.
  Please try and give us feedback until 2.0 code freeze.
* include/ruby/ruby.h: ditto.
* compile.c (rb_iseq_compile_node): ditto.
* insns.def: ditto.
* thread.c: ditto.
* vm.c: ditto.
* include/ruby/debug.h: add a comment.
* test/ruby/test_settracefunc.rb: add a tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 22:28:16 +00:00
kosaki c058d821f8 Revert r37956: thread.c (thread_start_func_2): small cleanups.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 02:50:11 +00:00
kosaki 989c529c89 * thread.c (thread_start_func_2): remove unused code. When
th->safe_level == 4, th->errinfo never be thrown. So, to
  create new exception makes no sense.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 02:09:36 +00:00
naruse d1dfebc05a Revert r37953: thread.c (thread_start_func_2): remove unused code. security
This sticks at bootstraptest/test_fork.rb:24 on FreeBSD and darwin.
http://fb.rubyci.org/~chkbuild/ruby-trunk/log/20121128T230302Z.log.html.gz
http://a.mrkn.jp/~mrkn/chkbuild/sl/ruby-trunk-m64-gcc42-o0/log/20121128T235908Z.log.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 01:11:47 +00:00
naruse e2779a53ef * thread.c (do_select): suppress warning (uninitialized value warning)
with UNINITIALIZED_VAR().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29 00:52:51 +00:00
kosaki b76b6b5c98 * thread.c (thread_start_func_2): small cleanups.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 21:55:26 +00:00
kosaki 5e606aee2f * thread.c (thread_start_func_2): remove unused code.
this function never be used for main thread.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 21:55:14 +00:00
kosaki fdda95ed8c * thread.c (thread_start_func_2): remove unused code.
errinfo = th->errinfo; and errinfo = rb_errinfo(); are
  the same.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 21:55:03 +00:00
kosaki 1d207fcff0 * thread.c (thread_start_func_2): remove unused code. security
level is checked before rb_eSecurityError raises.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 21:54:52 +00:00
ko1 09f9aa4385 * thread.c (rb_mutex_sleep): fix to allow spurious wakeup.
* NEWS: write about spurious wakeup.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 14:40:00 +00:00
ko1 9d0de48e66 * include/ruby/thread.h (rb_thread_call_without_gvl2): change
meaning of function.
  This function is called with same parameters of
  `rb_thread_call_without_gvl()'.
  However, if interrupts are detected, when return immediately.
* thread.c: implement `rb_thread_call_without_gvl2()'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 13:01:25 +00:00
tarui f5dc27aa77 * thread.c (thread_join_sleep): check spurious wakeup by itself for
corresponding status change in trap context.
	* vm_core.h (struct rb_thread_struct): add rb_thread_list_t and use as join_list for
	reentry by trap context.
	* thread.c (thread_start_func_2): ditto.
	* thread.c (remove_from_join_list): ditto.
	* thread.c (rb_thread_atfork): ditto.
	* thread.c (thread_join): ditto. & remove trap handler check.
	* thread.c (sleep_forever): add argument : spurious_check.
	* thread.c (sleep_timeval): ditto.
	* thread.c (rb_thread_sleep_forever): set spurious_check.
	* thread.c (rb_thread_sleep_deadly): ditto.
	* thread.c (sleep_for_polling): ditto.
	* thread.c (rb_thread_wait_for): ditto.
	* thread.c (sleep_wait_for_interrupt): bypass spurious_check.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 12:34:15 +00:00
kosaki 9cbf473287 * vm_core.h (enum rb_thread_status): remove THREAD_TO_KILL
* vm_core.h (struct rb_thread_struct): add to_kill field
* thread.c (terminate_i): convert THREAD_TO_KILL to to_kill.
* thread.c (rb_threadptr_to_kill): ditto.
* thread.c (rb_thread_kill): ditto.
* thread.c (rb_thread_wakeup_alive): ditto.
* thread.c (thread_list_i): ditto.
* thread.c (static const char): ditto.
* thread.c (thread_status_name): ditto.
* thread.c (rb_thread_status): ditto.
* thread.c (rb_thread_inspect): ditto.
* vm_backtrace.c (thread_backtrace_to_ary): ditto.

* thread.c (rb_threadptr_execute_interrupts): fix thread status
  overwritten issue. [Bug #7450] [ruby-core:50249]

* test/ruby/test_thread.rb (test_hread_status_raise_after_kill):
  test for the above.
* test/ruby/test_thread.rb (test_thread_status_in_trap): test for
  thread status in trap.
* test/ruby/test_thread.rb (test_status_and_stop_p): remove
  Thread.control_interrupt unsafe test. Thread#kill no longer
  changes thread status. Instead of, Thread#kill receiver changes
  their own status when receiving kill signal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 08:31:03 +00:00
kosaki b8a1e36201 * thread.c (struct rb_mutex_struct): add allow_trap field.
* internal.h (rb_mutex_allow_trap): added.
* thread.c (rb_mutex_lock, rb_mutex_unlock): check mutex->allow_trap.
* thread.c (mutex_sleep): remove trap check because it uses
  rb_mutex_lock and rb_mutex_unlock internally.
* thread.c (rb_mutex_allow_trap): new helper function for the above.

* io.c (io_binwrite): mark fptr->write_lock as writable in trap.

* test/ruby/test_signal.rb (test_trap_puts): test for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 08:30:51 +00:00
kosaki 835d24f637 * thread.c (rb_mutex_lock): moved trap context check from
rb_mutex_trylock because try_lock have no change to make
  a deadlock.
* thread.c (rb_mutex_trylock): ditto.
* NEWS: news for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 05:40:54 +00:00
kosaki 8111b32d68 * thread.c (thread_s_new): uses main_thread->status instead of
th->inhibit_thread_creation for preventing thread creation.
* vm_core.h (rb_vm_struct): remove inhibit_thread_creation field.
* thread.c (rb_thread_terminate_all): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 04:43:15 +00:00
kosaki 694c77633c * thread.c (thread_join): A trap handler check was moved from
thread_join_m because Thread#value should be raised an exception
  too.
* thread.c (thread_join_m): remove trap handler check.
* test/ruby/test_thread.rb (test_thread_join_in_trap): add test
  for thread#value.
* NEWS: documentation fix for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 04:09:38 +00:00
ko1 c72f0daa87 * thread.c (rb_thread_terminate_all): retry broadcast only when
an exception is raised.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27 03:18:29 +00:00
ko1 2f9ee7af47 * thread.c (rb_thread_terminate_all): broadcast terminate event
not only an interrupt exception but any exceptions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27 03:04:36 +00:00
kosaki 863e087326 * thread.c (rb_thread_terminate_all): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27 02:00:29 +00:00
kosaki b1a18cf49b * thread.c (thread_join): raises ThreadError if target therad
is a main thread.
* test/ruby/test_thread.rb (test_thread_join_main_thread):
  test for the above.
* NEWS: news for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27 02:00:19 +00:00
kosaki 8079f8a6f2 * thread.c (thread_join): raises ThreadError if target thread
is a current thread.
* test/ruby/test_thread.rb (test_thread_join_current):
  test for the above.
* NEWS: news for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27 02:00:09 +00:00
kosaki a916278900 * thread.c (rb_thread_terminate_all): broadcast eTerminateSignal
again when Ctrl-C was pressed. [Feature #1952] [ruby-dev:39107]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 23:08:36 +00:00
kosaki 253938067a * thread.c (rb_thread_terminate_all): add RUBY_VM_CHECK_INTS_BLOCKING().
Otherwise the loop in this function behave as busy loop because
  native_sleep() return immediately when RUBY_VM_INTERRUPTED() is true.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 22:49:36 +00:00
kosaki 5b238e8dc7 * thread.c (rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):
raises ThreadError if called from trap handler as Thread#join.
* NEWS: news fot the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 15:17:01 +00:00
kosaki 39d38ff82f * thread.c (rb_thread_terminate_all): use native_sleep() instead
of rb_thread_schedule(). Otherwise, it consume 100% cpu meaninglessly.
  [Bug #5368] [ruby-dev:44546]
* thread.c (thread_start_func_2): last sub-thread wakes up main thread.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 13:47:23 +00:00
kosaki 66e2e6ee69 * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT)
(RUBY_VM_SET_FINALIZER_INTERRUPT, RUBY_VM_SET_TRAP_INTERRUPT)
(RUBY_VM_INTERRUPTED): use enum symbol instead of immediate value.
* thread.c (thread_join_m, rb_threadptr_execute_interrupts): ditto.
* signal.c (signal_exec): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 12:17:10 +00:00
kosaki 58543f00b6 * thread.c (thread_join_m): use th->interrupt_mask instead of
th->in_trap.

* vm_core.h (struct rb_thread_struct): remove in_trap member.
* signal.c (signal_exec): ditto.
* thread.c (thread_create_core): ditto.
* thread.c (Init_Thread): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 11:45:39 +00:00
kosaki 6190bb4d8a * ruby_atomic.h (ATOMIC_CAS): new macro for compare-and-exchange.
* vm_core.h (struct rb_thread_struct): add interrupt_mask member.
* thread.c (thread_create_core, Init_Thread): initialize
  th->thread_mask.

* vm_core.h (RUBY_VM_INTERRUPTED_ANY): new macro for avoiding
  bare th->interrupt_flag.
* vm_core.h (RUBY_VM_INTERRUPTED, RUBY_VM_INTERRUPTED): check
  th->interrupt_mask.
* thread.c (set_unblock_function, rb_thread_schedule): replace
  th->interrupt_flag with RUBY_VM_INTERRUPTED_ANY()

* signal.c (signal_exec): set up thread->interrupt_mask for
  preventing recursive trap handler.
* vm_core.h (RUBY_VM_CHECK_INTS, RUBY_VM_CHECK_INTS_BLOCKING): ditto.

* thread.c (rb_threadptr_execute_interrupts):
  don't process interrupt if it is masked.
  [Bug #6009] [ruby-core:42524]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 10:57:39 +00:00
kosaki 7087153156 split trap interrupt and async interrupt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 09:22:01 +00:00
kosaki f150ed1532 * vm_core.h (rb_thread_struct): added 'in_trap' member for marking
running trap handler.
* signal.c (signal_exec): turn on in_trap when running trap.
* thread.c (Init_Thread, thread_create_core): initialize in_trap
  when creating new threads.
* thread.c (thread_join_m): raise ThreadError when running trap
  handler.Bug [#6416][ruby-core:44956]
* test/ruby/test_thread.rb (test_thread_join_in_trap): new test
  for the above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26 08:05:49 +00:00
kosaki 82b33551a4 * thread.c (thread_create_core): don't use th->thread_id before
initialized.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-24 02:00:10 +00:00
ko1 553931962a * vm_trace.c: add two methods:
(1) TracePoint#return_value which returns return
  value on the :return and :c_return event.
  (2) TracePoint#raised_exception which returns raised exception
  value on the :raise event.
  Eeach methods raise RuntimeError if it is called at unsupported
  event.
  Please review and give us feedback until next preview
  release (Dec/2012) of Ruby 2.0.0.
* insns.def, vm.c, vm_eval.c, vm_insnhelper.c, eval.c, thread.c:
  ditto.
* vm_trace.c, vm_core.h: move definition of rb_trace_arg_t from
  vm_trace.c to vm_core.h.
  Caller fills rb_trace_arg_t and pass the pointer of this variable.
* test/ruby/test_settracefunc.rb: fix tests to test this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 09:48:24 +00:00
kosaki b74e1b21db revert r37730
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20 01:21:19 +00:00
kosaki 57ee812851 * thread.c (rb_thread_s_check_interrupt): removed redundant
GET_THREAD().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:15:07 +00:00
kosaki 4b25e0ceca * thread.c (rb_threadptr_async_errinfo_active_p): added a small
comment.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:13:40 +00:00
kosaki 212150c2e1 * thread.c, vm_core.h: big rename th to cur_th when works only
th is current thread.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:10:24 +00:00
kosaki 0a2da327f4 * thread.c (rb_thread_blocking_region_end): replaced GET_THREAD()
with ruby_thread_from_native(). We don't have GVL here.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:07:53 +00:00
kosaki 7643e4604b * thread.c (rb_threadptr_execute_interrupts) removed.
* thread.c (rb_threadptr_execute_interrupts_common) renamed to
  rb_threadptr_execute_interrupts. I.e. unified
  rb_threadptr_execute_interrupts and rb_threadptr_execute_interrupts_common.
* thread.c (rb_thread_schedule, rb_thread_execute_interrupts) s/_common//.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 11:04:39 +00:00
kosaki 6c56dae4b2 * prelude.rb: Moved Mutex#synchronize to
* thread.c (rb_mutex_synchronize_m): here. [Bug #4266]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 10:22:53 +00:00
ko1 15d940b8b0 * thread.c: add `Thread#backtrace_locations' method.
This method is similart to `caller_locations' method for
  specific method.
  And fix to accept `level' and `n' parameters for `Thread#backtrace'
  and `Thread#backtrace_locations'.
  `caller' (and `caller_locations') do not return `caller' method
  frame.
  However, `Thread#backtrace' (and `Thread#backtrace_locations')
  return `Thread#backtrace' method frame itself
  if `Thread.current.backtrace' was called.
* vm_backtrace.c: ditto.
* internal.h: ditto.
* test/ruby/test_backtrace.rb: add tests.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 06:07:06 +00:00
ko1 9ee34b15e4 * thread.c (rb_thread_call_without_gvl2): change the parameter of
`func' from `int *skip_interrupt' to `VALUE *flags'.
  If (flags & RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS) is not zero,
  then skip checking interrupt.
  [ruby-core:46547]
* include/ruby/thread.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-16 10:34:54 +00:00
naruse 71dcc25fb7 suppress warning: 'val' may be used uninitialized in this function
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-01 19:48:34 +00:00
drbrain 7ae466f134 * thread.c (rb_thread_call_without_gvl2): Note that ubf() may or may
not be called with the GVL.  Hinted that rb_thread_call_with_gvl()
  can be used to access ruby functionality.  [ruby-trunk - #6433]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-31 00:29:27 +00:00
drbrain 5562411c7f * thread.c (rb_thread_call_without_gvl2): Update documentation to
natural English.
* thread.c (rb_thread_call_with_gvl):  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-31 00:07:17 +00:00
tenderlove 2285319b31 * thread.c: added Thread#thread_variable_(get|set),
Thread#thread_variable?, and Thread#thread_variables for operating
  on variables that are local to threads. [ruby-core:47790]

* vm.c: ditto

* test/ruby/test_thread.rb: tests for thread variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-29 17:22:36 +00:00
ko1 479d8ce5b5 * thread.c (thread_raise_m): check interrupts after Thread#raise
if a target thread is the current thread because the behavior
  of Thread.current.raise is expected to perform same as
  Kernel.raise (by rubyspec).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 13:37:45 +00:00
ko1 a4f79a6ece Revert the last commit because some tests (in btest) fail
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 04:52:20 +00:00
ko1 d41ec2a79a * thread.c (rb_threadptr_raise): check interrupts after
Thread#raise because the behavior of Thread.current.raise is
  expected to perform same as Kernel.raise (by rubyspec).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 04:33:04 +00:00
ko1 8addee9649 * thread.c (rb_threadptr_interrupt_mask): fix to check interrupt
after interrupt_mask changed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-16 23:03:54 +00:00
zzak 61d460e5e1 * thread.c (rb_thread_aref):
Grammar in Thread documentation.
  Patch by Steve Klabnik [ruby-dev:47799] [Bug #7099]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-06 19:51:40 +00:00
nobu f228a4b209 thread.c: static
* thread.c (patrol_thread): should be static.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-10 08:21:02 +00:00
kosaki 10c14095de * thread.c (rb_mutex_lock): stop multiple threads use
pthread_cond_timedwait() concurrently. [Bug #6278] [ruby-core:44275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-09 06:27:02 +00:00
nobu ceece4650a vm_insnhelper.c: iclass as klass in cfp
* vm_insnhelper.c (vm_call_method): follow iclasses as klass in cfp
  but not included modules.  [ruby-core:47241] [Bug #6891]
* vm_insnhelper.c (vm_call_bmethod): pass defined_class to follow
  proper ancestors.  [ruby-core:47241] [Bug #6891]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-20 11:36:34 +00:00
ko1 4a4a702e61 * vm_trace.c, vm_core.h: simplify tracing mechanism.
(1) add rb_hook_list_t data structure which includes
  hooks, events (flag) and `need_clean' flag.
  If the last flag is true, then clean the hooks list.
  In other words, deleted hooks are contained by `hooks'.
  Cleanup process should run before traversing the list.
  (2) Change check mechanism
  See EXEC_EVENT_HOOK() in vm_core.h.
  (3) Add `raw' hooks APIs
  Normal hooks are guarded from exception by rb_protect().
  However, this protection is overhead for too simple
  functions which never cause exceptions.  `raw' hooks
  are executed without protection and faster.
  Now, we only provide registration APIs.  All `raw'
  hooks are kicked under protection (same as normal hooks).
* include/ruby/ruby.h: remove internal data definition and
  macros.
* internal.h (ruby_suppress_tracing), vm_trace.c: rename
  ruby_suppress_tracing() to rb_suppress_tracing()
  and remove unused function parameter.
* parse.y: fix to use renamed rb_suppress_tracing().
* thread.c (thread_create_core): no need to set RUBY_VM_VM.
* vm.c (mark_event_hooks): move definition to vm_trace.c.
* vm.c (ruby_vm_event_flags): add a global variable.
  This global variable represents all of Threads and VM's
  event masks (T1#events | T2#events | ... | VM#events).
  You can check the possibility kick trace func or not
  with ruby_vm_event_flags.
  ruby_vm_event_flags is maintained by vm_trace.c.
* cont.c (fiber_switch, rb_cont_call): restore tracing status.
  [Feature #4347]
* test/ruby/test_continuation.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-16 11:41:24 +00:00
ko1 8eb93103e4 * vm_trace.c: separate trace_func related functions from
thread.c.
* thread.c: ditto.
* common.mk: add vm_trace.o.
* inits.c: call Init_vm_trace().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-15 04:39:10 +00:00
nagachika 9cdf55485a * thread.c (thread_create_core): hide th->async_errinfo_mask_stack from
ObjectSpace.each_object. refix of r36539.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-29 16:00:36 +00:00
ktsj afde2e8d05 * thread.c (Init_Thread): does not need to set klass
explicitly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-29 05:28:04 +00:00
nagachika ea637ebaa4 * thread.c (thread_create_core, Init_Thread): hide
th->async_errinfo_queue and th->async_errinfo_mask_stack from
  ObjectSpace.each_object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-25 16:40:04 +00:00
naruse ee755e2ce9 * thread.c (rb_threadptr_execute_interrupts_common): increase
running_time_us on THREAD_TO_KILL like on THREAD_RUNNABLE.
  This cause not to siwtch from a thread which is to be killed
  on FreeBSD and Mac OS X. see also the test.
  This issue maybe exist for long time but happens after r36430.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-22 15:04:11 +00:00
ko1 f4a8db647a * thread.c (rb_thread_s_control_interrupt,
rb_thread_s_check_interrupt): added for
  Thread.control_intgerrupt and Thread.check_interrupt.
  See details on rdoc.
  I'll make an ticket for this feature.
* test/ruby/test_thread.rb: add a test for Thread.control_intgerrupt.
* thread.c (rb_threadptr_raise): make a new exception object
  even if argc is 0.
* thread.c (rb_thread_kill): kill thread immediately if target thread
  is current thread.
* vm_core.h (RUBY_VM_CHECK_INTS_BLOCKING): added.
  CHECK_INTS while/after blocking operation.
* vm_core.h (RUBY_VM_CHECK_INTS): require rb_thread_t ptr.
* cont.c (fiber_switch): use replaced RUBY_VM_CHECK_INTS().
* eval.c (ruby_cleanup): ditto.
* insns.def: ditto.
* process.c (rb_waitpid): ditto.
* vm_eval.c (vm_call0): ditto.
* vm_insnhelper.c (vm_call_method): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-19 14:19:40 +00:00
nobu 5e7fa03bc0 thread.c: remove deprecated
* thread.c (rb_gc_mark_threads): remove deprecated function.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-19 05:15:51 +00:00
ko1 e9a91d2c95 * thread.c (rb_thread_call_without_gvl2): added.
it can skip last CHECK_INTS.  See document for more details.
  Document about it was updated a bit.
* include/ruby/thread.h (decl. of rb_thread_call_without_gvl2): added.
* thread.c (rb_thread_call_with_gvl): remove "EXPERIMENTAL!"
  warning from a document.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-18 06:47:43 +00:00
ko1 eff4b2b2e1 * thread.c: fix last commit miss.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-18 05:47:48 +00:00
ko1 28144433b2 * thread.c (rb_threadptr_async_errinfo_*): manage async errors queue.
Async events such as an exception throwed by Thread#raise,
  Thread#kill and thread termination (after main thread termination)
  will be queued to th->async_errinfo_queue.
  - clear: clear the queue.
  - enque: enque err object into queue.
  - deque: deque err object from queue.
  - active_p: return 1 if the queue should be checked.
  rb_thread_t#thrown_errinfo was removed.
* vm_core.h: add declarations of rb_threadptr_async_errinfo_*.
  remove rb_thread_t#thrown_errinfo field and
  add rb_thread_t#async_errinfo_queue (queue body: Array),
  rb_thread_t#async_errinfo_queue_checked (flag),
  rb_thread_t#async_errinfo_mask_stack(Array, not used yet).
* vm.c (rb_thread_mark): fix a mark function.
* cont.c (rb_fiber_start): enque an error.
* process.c (after_fork): clear async errinfo queue.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-18 05:46:40 +00:00
nobu c51a826764 rb_thread_call_without_gvl
* include/ruby/thread.h: new header file for thread stuff.
* thread.c (rb_thread_call_without_gvl): export.  [Feature#4328]
  returns void* instead of VALUE.  [Feature #5543]
* thread.c (rb_thread_blocking_region): deprecate.  [ruby-core:46295]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-10 13:57:11 +00:00
nobu 8a995a56c7 thread.c: unsigned
* thread.c (rb_thread_shield_waiting_{inc,dec}): should be unsigned.
  int is large enough since ruby requires it to be 32bit at least.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-06 03:46:39 +00:00
nobu a2d0ee620f ThreadShield: check waiting count
* thread.c (rb_thread_shield_waiting_{inc,dec}): check waiting count.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-06 03:24:41 +00:00
nobu 0f020f7ca4 * thread.c: fix typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-05 14:10:48 +00:00
nobu 51f458d4db ThreadShield
* thread.c (ThreadShield): rename from Barrier.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-05 07:00:29 +00:00
nobu 1655b26f67 thread.c: fix rdoc
* thread.c (rb_thread_blocking_region): fix typo and the description
  in "Safe C API".  ruby_xmalloc(), ruby_xrealloc() never try acquire
  GVL automatically unless GC runs, but had race condtions without GVL
  acquired until r36284.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-04 02:46:33 +00:00
akr c03d1c2736 * thread.c (rb_thread_aref): add explanation for why Thread#[] and
Thread#[]= are fiber-local and not thread-local.
  reported by Julien A.  [ruby-core:41606] [ruby-trunk - Bug #5750]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-02 13:15:29 +00:00
nobu f4d2374b45 adjust style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-27 05:37:15 +00:00
ko1 0a71db8a74 * vm_core.h: remove lfp (local frame pointer) and rename
dfp (dynamic frame pointer) to ep (environment pointer).
  This change make VM `normal' (similar to other interpreters).
  Before this commit:
  Each frame has two env pointers lfp and dfp.  lfp points
  local environment which is method/class/toplevel frame.
  lfp[0] is block pointer.
  dfp is block local frame. dfp[0] points previous (parent)
  environment pointer.
  lfp == dfp when frame is method/class/toplevel.
  You can get lfp from dfp by traversing previous environment
  pointers.
  After this commit:
  Each frame has only `ep' to point respective enviornoment.
  If there is parent environment, then ep[0] points parent
  envioenment (as dfp).  If there are no more environment,
  then ep[0] points block pointer (as lfp).  We call such ep
  as `LEP' (local EP).  We add some macros to get LEP and to
  detect LEP or not.
  In short, we replace dfp and lfp with ep and LEP.
  rb_block_t and rb_binding_t member `lfp' and `dfp' are removed
  and member `ep' is added.
  rename rb_thread_t's member `local_lfp' and `local_svar' to
  `root_lep' and `root_svar'.
  (VM_EP_PREV_EP(ep)): get previous environment pointer.  This macro
  assume that ep is not LEP.
  (VM_EP_BLOCK_PTR(ep)): get block pointer.  This macro assume
  that ep is LEP.
  (VM_EP_LEP_P(ep)): detect ep is LEP or not.
  (VM_ENVVAL_BLOCK_PTR(ptr)): make block pointer.
  (VM_ENVVAL_BLOCK_PTR_P(v)): detect v is block pointer.
  (VM_ENVVAL_PREV_EP_PTR(ptr)): make prev environment pointer.
  (VM_ENVVAL_PREV_EP_PTR_P(v)): detect v is prev env pointer.
* vm.c: apply above changes.
  (VM_EP_LEP(ep)): get LEP.
  (VM_CF_LEP(cfp)): get LEP of cfp->ep.
  (VM_CF_PREV_EP(cfp)): utility function VM_EP_PREV_EP(cfp->ep).
  (VM_CF_BLOCK_PTR(cfp)): utility function VM_EP_BLOCK_PTR(cfp->ep).
* vm.c, vm_eval.c, vm_insnhelper.c, vm_insnhelper.h, insns.def:
  apply above changes.
* cont.c: ditto.
* eval.c, eval_intern.h: ditto.
* proc.c: ditto.
* thread.c: ditto.
* vm_dump.c: ditto.
* vm_exec.h: fix function name (on vm debug mode).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-11 03:14:59 +00:00
naruse 190d319dab * thread.c (vm_living_thread_num): suppress a warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-03 10:47:45 +00:00
nobu b0dd250dc9 use RB_TYPE_P() instead of comparison of TYPE()
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-23 07:13:21 +00:00
yugui 82983e834d * thread.c, thread_pthread.c: Moved pthread-specific preprocessor
hacks to thread_pthread.c


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-17 03:54:50 +00:00
yugui 76bc2d1ed7 Imports Ruby's port to NativeClient (a.k.a NaCl).
Patch by Google Inc. [ruby-core:45073].

* configure.in (RUBY_NACL): New M4 func to configure variables for
  NaCl.
  (RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
  of Pepper interface types.
  (BTESTRUBY): New variable to specify which ruby should be run on
  "make btest". NaCl can run the built binary by sel_ldr, but it need
  rbconfig.rb. So this variable is distinguished from $MINIRUBY.
  
* thread_pthread.c: Disabled some features on NaCl.

* io.c: ditto.

* process.c: ditto.

* signal.c: ditto.

* file.c: ditto.

* missing/flock.c: ditto.

* nacl/pepper_main.c: An example implementation of Pepper application
  that embeds Ruby.

* nacl/example.html: An example of web page that uses the Pepper
  application.

* nacl/nacl-config.rb: Detects variants of NaCl SDK.

* nacl/GNUmakefile.in: Makefile template for NaCl specific build
  process.

* nacl/package.rb: script for packaging a NaCl-Ruby embedding
  application. 

* nacl/reate_nmf.rb: Wrapper script of create_nmf.py

* dln.c (dln_load): Added a hack to call on NaCl.

* util.c (ruby_getcwd): Path to the current directort is not available
  on NaCl.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-17 02:48:59 +00:00
naruse cc08e95b20 Revert r35622.
It breaks bootstraptest/test_exception.rb:388.

"* thread.c (rb_threadptr_execute_interrupts_common): th->errinfo is"

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-11 15:24:27 +00:00
naruse 38d3b013b7 * thread.c (rb_threadptr_execute_interrupts_common): th->errinfo is
not Fixnum, but exception object.
  This causes test_signal_requiring of test/ruby/test_signal.rb fail
  if the sub process is killed on waiting IO in lex_io_gets in require
  itself, not sleep.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-11 14:03:40 +00:00
ko1 6978b8ca67 * vm_core.h (rb_thread_t#yielding): add a field.
* thread.c (rb_thread_schedule_limits): set th#yielding while
  release GVL to yield CPU time.
* thread.c (timer_thread_function): skip timer interrupt when
  th#yielding is true.  This patch fixes r35480.
* thread.c (rb_threadptr_execute_interrupts_common): revert
  a patch of r35480.
* ChangeLog: add an extended memo of r35480.
  http://bugs.ruby-lang.org/projects/ruby-trunk/wiki/R35480_ExtendedMemo



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-28 09:59:44 +00:00
naruse c746b6fa42 * thread.c (rb_threadptr_execute_interrupts_common):
handle timer_interrupt only on the first loop for the case to avoid
  the infinite loop like following case:
  * there is 2 Ruby threads (3 pthreads)
  (1) main thread is waiting at gvl_yield:112 (native_cond_wait)
  (2) sub thread works
  (3) sub thread waits at gvl_yield:133 (native_mutex_unlock)
  (4) main thread works
  (5) main thread goes to gvl_acquire_common
  (6) main thread call rb_wakeup_timer_thread
  (7) timer thread set timer interrupt to the main thread
  (8) main thread works
  (9) main thread waits at gvl_acquire_common:64 (native_cond_wait)
  (10) sub tread works
  (11) set sub thread as the current thread
  (12) run Ruby thread
  (13) ...100ms
  (14) sub thread goes to rb_threadptr_execute_interrupts_common
  (15) sub thread call rb_thread_schedule_limits
  (16) sub thread call gvl_release_common
  (17) sub threads waits at gvl_yield:121 (native_cond_wait)
  (18) main threads works
  (19) main thread back to gvl_yield
  (20) set main thread as the current thread
  (21) main thread call gvl_yield
  (22) main thread waits at gvl_yield:112 (native_cond_wait)
  As described above, the main thread can't escape from
  rb_threadptr_execute_interrupts_common.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-26 23:19:11 +00:00
mame 7320d83753 * thread.c (rb_check_deadlock): refine an error message of deadlock
detection.  [ruby-core:44336] [Bug #6288]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-23 15:27:00 +00:00
usa fea7a74ee3 * thread.c (rb_threadptr_execute_interrupts_common): use defined
TIME_QUANTUM_USEC instead of a magic number.  there is no meanings
  to use different values for checking interval of interruption and
  thread switching limits.
  cf. [Bug #6098]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-03-29 01:15:37 +00:00
nobu 6b1bae9641 * thread.c (rb_mutex_unlock_th): simplified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-13 09:29:13 +00:00
nobu 8032371462 * thread.c (rb_barrier_waiting): fix potential overflows.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-13 09:25:54 +00:00
ayumin 966d1f8962 * thread.c: changed documentation for "thread-local" variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-03 07:01:15 +00:00
naruse 82ab1e189b * thread.c (rb_barrier_waiting): save the number of waiting threads
in RBASIC()->flags. [ruby-dev:45002] [Bug #5768]

* thread.c (rb_barrier_wait): increment and decrement around
  rb_mutex_lock, and use rb_barrier_waiting().

* thread.c (rb_barrier_release): use rb_barrier_waiting().

* thread.c (rb_barrier_destroy): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-30 22:25:16 +00:00
nobu 50c1985555 * load.c (load_unlock): release loading barrier and then remove it
from loading_table if it is not in-use.  [Bug #5754]
* thread.c (rb_barrier_release, rb_barrier_destroy): return
  whether any other threads are waiting on it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-14 03:20:02 +00:00
nobu f2fff83e96 * load.c (load_lock): delete the loading barrier if it has been
destroyed.
* thread.c (rb_barrier_wait): return nil for recursive lock
  instead of false, to distinguish it from destroyed barrier.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-14 01:20:11 +00:00
nobu ab6c8910f4 * load.c (load_unlock): all threads requiring one file should
share same loading barrier, so it must be kept alive while those
  are waiting on it.  [ruby-core:41618] [Bug #5754]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-13 07:13:31 +00:00
akr 3d25acdccc * io.c, thread.c, ext/pty/pty.c, ext/fiddle/closure.c: use
__linux__ macro for consistency.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-15 11:09:47 +00:00
naruse b10c3136b0 * thread.c (do_select): fix cast, tv_sec is time_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-09 02:06:49 +00:00
nobu ac46d76ce8 * thread.c (rb_fd_rcopy): suppress warnings on mingw32.
* win32/win32.c (overlapped_socket_io, recvmsg, sendmsg, dupfd):
  ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-11-03 13:50:55 +00:00
nobu 8e6e8e6288 * use RB_TYPE_P which is optimized for constant types, instead of
comparison with TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-29 11:07:45 +00:00
kosaki 1bdf1a5c6f * thread_pthread.c: make native_fd_select().
* thread.c (do_select): remove #ifdef _WIN32. Instead, use
  native_fd_select() always.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-27 00:59:04 +00:00
kosaki 2cc5eeaf6c * thread.c (do_select): remove cygwin specific hack. It's layer
violation and too large hack.
* thread.c (cmp_tv, subtract_tv): removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-27 00:50:29 +00:00
kosaki d24e1dac2b * thread.c (rb_fd_rcopy): added an argument guard.
Patch by NAKAMURA Usaku. [Bug #5306] [ruby-core:39435]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-14 02:44:57 +00:00
kosaki 2c9375ba69 * thread.c (rb_thread_select): fix to ignore an argument
modification of rb_thread_fd_select().
  based on a patch by Eric Wong. [Bug #5306] [ruby-core:39435]
* thread.c (rb_fd_rcopy): New. for reverse fd copy.

* test/-ext-/old_thread_select/test_old_thread_select.rb
(test_old_select_false_positive): test for bug5306.

* ext/-test-/old_thread_select/old_thread_select.c (fdset2array):
  New. convert fdsets to array.
* ext/-test-/old_thread_select/old_thread_select.c (old_thread_select):
  return 'read', 'write', 'except' argument of rb_thread_select()
  to ruby script.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-12 11:36:06 +00:00
nobu 61b062ba6d * thread.c (rb_thread_select): fix a typo to initialize efds
properly.  [Bug #5299] [ruby-core:39380]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-09-09 01:22:06 +00:00
usa a34f81561d * thread.c (rb_thread_select): critical typo in r33117.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-30 15:49:55 +00:00
usa ee7d523631 * win32/win32.c, include/ruby/intern.h (rb_w32_fd_copy): implement
for rb_thread_select() in thread.c.  the use of rb_fd_copy() is
  introduced in r33117.
  [Bug #5229] [ruby-core:39102]

* thread.c (rb_thread_select): must call rb_fd_init() before using
  rb_fdset_t.  see the implementations of rb_fd_init()s if you want to
  know the reason.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-30 15:04:11 +00:00
kosaki 0cebfad20a * thread.c (rb_thread_select): rewrite by using
rb_thread_fd_select(). old one is EINTR unsafe.
  Patch by Eric Wong. [Bug #5229] [ruby-core:39102]

* test/-ext-/old_thread_select/test_old_thread_select.rb:
  a testcase for rb_thread_select().
* ext/-test-/old_thread_select/old_thread_select.c: ditto.
* ext/-test-/old_thread_select/depend: ditto.
* ext/-test-/old_thread_select/extconf.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-30 00:33:05 +00:00
mame 54163e2b52 * thread.c (update_coverage): skip coverage count up if the current
line is out of the way.  rb_sourceline() is unreliable when source
  code is big.  [ruby-dev:44413]

* test/coverage/test_coverage.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-23 15:44:26 +00:00
mrkn 248d589b55 * thread.c: add a description for the behavior of select(2) on
Mac OS X 10.7 (Lion).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-19 04:17:04 +00:00
mame 9752864b88 * thread.c (set_trace_func, thread_set_trace_func_m): reset tracing
state when set_trace_func hook is removed.  This is workaround patch
  to force to reset tracing state that is broken by continuation call.
  a patch from James M. Lawrence.  [Feature #4347] [ruby-core:34998]

* test/ruby/test_continuation.rb (class TestContinuation): add a test
  for above.  a patch from James M. Lawrence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-21 11:09:52 +00:00
kosaki b9a13f4962 * thread_pthread.c (mutex_debug): use exit(EXIT_FAILURE) instad of
exit(1).
* thread_pthread.c (add_signal_thread_list): ditto.
* thread.c (rb_thread_call_with_gvl): ditto.
* util.c (Bug): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-10 08:29:46 +00:00
kosaki a119b9d146 * vm_core.h (typedef struct rb_vm_struct): create a new
'inhibit_thread_createion' field.
* thread.c (rb_thread_terminate_all): set inhibit_thread_creation.
* thread.c (thread_s_new): don't permit to create new thread
  if the VM is under destruction. Otherwise evil finalizer code
  can make SEGV. [Bug #4992][ruby-core:37858]

* bootstraptest/test_objectspace.rb: new test for this fix.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-10 07:46:00 +00:00
nobu 837e73ab6d * thread.c (cmp_tv, subtract_tv): no longer used on Win32.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-08 07:01:12 +00:00
kosaki 554a33d838 * thread.c (rb_mutex_unlock_all): folded into
rb_threadptr_unlock_all_locking_mutexes.
* thread.c (rb_threadptr_unlock_all_locking_mutexes) ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-07-08 04:50:25 +00:00