* compar.c (cmp_eq): fail if recursion. [ruby-core:57736] [Bug #9003]
* thread.c (rb_exec_recursive_paired_outer): new function which is
combinnation of paired and outer variants.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (terminate_atfork_i): fix locking mutexes not unlocked in
forks when not tracked in thread. [ruby-core:55102] [Bug #8433]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RARRAY_RAWPTR(ary) returns (const VALUE *) type pointer and
usecase of this macro is not acquire raw pointer, but acquire
read-only pointer. So we rename to better name.
RSTRUCT_RAWPTR() is also renamed to RSTRUCT_CONST_PTR()
(I expect that nobody use it).
* array.c, compile.c, cont.c, enumerator.c, gc.c, proc.c, random.c,
string.c, struct.c, thread.c, vm_eval.c, vm_insnhelper.c:
catch up this change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
require extension libraries. The patch is from nobu
(Nobuyoshi Nakada).
* ext/thread/extconf.rb: for build ext/thread/thread.c.
* include/ruby/intern.h: ditto.
* thread.c: ditto.
* lib/thread.rb: removed and replaced by ext/thread/thread.c.
* ext/thread/thread.c: Queue, SizedQueue and ConditionVariable
implementations in C. This patch is based on patches from panaggio
(Ricardo Panaggio) and funny_falcon (Yura Sokolov) and ko1
(Koichi Sasada). [ruby-core:31513] [Feature #3620]
* test/thread/test_queue.rb (test_queue_thread_raise): add a test for
ensuring that killed thread should be removed from waiting threads.
It is based on a code by ko1 (Koichi Sasada). [ruby-core:45950]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
use RARRAY_RAWPTR() instead of RARRAY_PTR() because
there is no new reference.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Move native thread related lines from vm_core.h.
And declare several functions "rb_nativethread_lock_*",
manipulate locking.
* common.mk: add thread_native.h.
* thread.c: add functions "rb_nativethread_lock_*".
* thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t
to rb_nativethread_lock_t to make it clear that this lock is for
native thraeds, not for ruby threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
By Tim Abdulla [Fixes GH-342] https://github.com/ruby/ruby/pull/342
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* RUBY_INTERNAL_EVENT_NEWOBJ: object created.
* RUBY_INTERNAL_EVENT_FREE: object freeed.
* RUBY_INTERNAL_EVENT_GC_START: GC started.
And rename `RUBY_EVENT_SWITCH' to `RUBY_INTERNAL_EVENT_SWITCH'.
Internal events can not invoke any Ruby program because the tracing
timing may be critical (under huge restriction).
These events can be hooked only by C-extensions.
We recommend to use rb_potponed_job_register() API to call Ruby
program safely.
This change is mostly written by Aman Gupta (tmm1).
https://bugs.ruby-lang.org/issues/8107#note-12
[Feature #8107]
* include/ruby/debug.h, vm_trace.c: added two new APIs.
* rb_tracearg_event_flag() returns rb_event_flag_t of this event.
* rb_tracearg_object() returns created/freeed object.
* ext/-test-/tracepoint/extconf.rb,
ext/-test-/tracepoint/tracepoint.c,
test/-ext-/tracepoint/test_tracepoint.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Postponed jobs are registered with this API. Registered jobs
are invoked at `ruby-running-safe-point' as soon as possible.
This timing is completely same as finalizer timing.
There are two APIs:
* rb_postponed_job_register(flags, func, data): register a
postponed job with data. flags are reserved.
* rb_postponed_job_register_one(flags, func, data): same as
`rb_postponed_job_register', but only one `func' job is
registered (skip if `func' is already registered).
This change is mostly written by Aman Gupta (tmm1).
https://bugs.ruby-lang.org/issues/8107#note-15
[Feature #8107]
* gc.c: use postponed job API for finalizer.
* common.mk: add dependency from vm_trace.c to debug.h.
* ext/-test-/postponed_job/extconf.rb, postponed_job.c,
test/-ext-/postponed_job/test_postponed_job.rb: add a test.
* thread.c: implement postponed API.
* vm_core.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
(SIGNED_INTEGER_MAX): Ditto.
(SIGNED_INTEGER_MIN): Ditto.
(UNSIGNED_INTEGER_MAX): Ditto.
(TIMET_MAX): Use SIGNED_INTEGER_MAX and UNSIGNED_INTEGER_MAX.
(TIMET_MIN): Use SIGNED_INTEGER_MIN.
* thread.c (TIMEVAL_SEC_MAX): Use SIGNED_INTEGER_MAX.
(TIMEVAL_SEC_MIN): Use SIGNED_INTEGER_MIN.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
sizeof(time_t) is smaller than sizeof(tv_sec), such as
OpenBSD 5.2 (amd64).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (sleep_timeval): get rid of overflow on Windows where
timeval.tv_sec is not time_t but mere long.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_local_aset): no needs to allocate local_storage
before deleting.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in (TYPEOF_TIMEVAL_TV_SEC): check for x64-mingw, where
timeval.tv_sec is not time_t.
* thread.c (double2timeval): use TYPEOF_TIMEVAL_TV_SEC to get rid of
overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (ruby_kill): get rid of deadlock on signal 0.
[ruby-dev:47182] [Bug #8137]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
this fixes the build failure of mswin introduced at r39819.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
[Bug #8080] [ruby-core:53349]
* test/ruby/test_io.rb (TestIO#test_io_select_with_many_files):
test for the above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* 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
* 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
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
* 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
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
* 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
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
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
* 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
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
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
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
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
* 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
* 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
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
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
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
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
* 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
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