summaryrefslogtreecommitdiff
path: root/thread.c
AgeCommit message (Collapse)Author
2020-08-17procnames-start-lines [ci skip]Nobuyoshi Nakada
2020-07-20Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.Samuel Williams
Correctly capture thread before releasing GVL and pass as argument to `rb_thread_scheduler_if_nonblocking`. Notes: Merged: https://github.com/ruby/ruby/pull/3323
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29exec_recursive: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-20compile.c: Improve branch coverage instrumentation [Bug #16967]Yusuke Endoh
Formerly, branch coverage measurement counters are generated for each compilation traverse of the AST. However, ensure clause node is traversed twice; one is for normal-exit case (the resulted bytecode is embedded in its outer scope), and the other is for exceptional case (the resulted bytecode is used in catch table). Two branch coverage counters are generated for the two cases, but it is not desired. This changeset revamps the internal representation of branch coverage measurement. Branch coverage counters are generated only at the first visit of a branch node. Visiting the same node reuses the already-generated counter, so double counting is avoided. Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-05-25Make Thread#thread_variable? similar to #thread_variable_getJeremy Evans
Don't use rb_check_id, which only works for pinned symbols. Switch inadvertent creation test for thread_variable? to only check for pinned symbols, same as thread_variable_get and thread_variable_set. Make key variable name in thread_local_set match thread_local_get and thread_variable?. Fixes [Bug #16906] Notes: Merged: https://github.com/ruby/ruby/pull/3145
2020-05-14Thread scheduler for light weight concurrency.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3032 Merged-By: ioquatix <samuel@codeotaku.com>
2020-05-12Thread#backtrace may return nil [ci skip]Kazuhiro NISHIYAMA
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-09should check pending interrupts correctly.Koichi Sasada
rb_uninterruptible() disables any interrupts using handle_interrupt feature (This function is used by `p`). After this function, pending interrupts should be checked correctly, however there is no chance to setup interrupt flag of working threads, it means that nobody checks pending interrupts. For example, it ignores terminate signal delivered at the end of main thread and program can't stop. This patch set interrupt flag if there are pending interrupts.
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-26check flags passed to rb_nogvl()Koichi Sasada
RB_NOGVL_UBF_ASYNC_SAFE is wrongly specified because flags is not checked. [Bug #15499] 23444302
2020-02-20fix arity mismatch卜部昌平
This is a ruby method with arity zero. Which means, this function takes one argument (that is self).
2020-02-07more on NULL versus functions.卜部昌平
Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
2020-01-11st_delete_wrap is no longer usedNobuyoshi Nakada
2020-01-11Let execution context local storage be an ID tableLourens Naudé
Notes: Merged: https://github.com/ruby/ruby/pull/2814
2020-01-02Fully separate positional arguments and keyword argumentsJeremy Evans
This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p(). Notes: Merged: https://github.com/ruby/ruby/pull/2794
2019-12-28Fix typoKazuhiro NISHIYAMA
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26TIMESPEC_SEC_MAX might be bigger than 53 bits.卜部昌平
The same as 41bc766763dba63ae2529f2f9070b8e26399745c. Read that commit for what is happening. Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26other minior internal header tweaks卜部昌平
These headers need no rewrite. Just add some minor tweaks, like addition of #include lines. Mainly cosmetic. TIMET_MAX_PLUS_ONE was deleted because the macro was used from only one place (directly write expression there). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-16thread.c: avoid needless read after select|ppollEric Wong
We do not need to issue pipe|eventfd read(2) syscall unless select, ppoll|poll declares the FD needs reading.
2019-12-11Make Thread#to_s consistent with Method and Proc to_sJean byroot Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/2738
2019-12-05move an interrupt point.Koichi Sasada
`args_ptr` can be corrupted by interrupt handlers. Pointed by nagachika <https://ruby-trunk-changes.hatenablog.com/entry/ruby_trunk_changes_20191204>.
2019-12-03Check interrupts before starting threadJeremy Evans
Fixes a hang when Thread.new calls Thread.new in a loop. Fixes [Bug #13688] Notes: Merged: https://github.com/ruby/ruby/pull/2715
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-04Use ident hash for top-level recursion checkJohn Hawthorn
We track recursion in order to not infinite loop in ==, inspect, and similar methods by keeping a thread-local 1 or 2 level hash. This allows us to track when we have seen the same object (ex. using inspect) or same pair of objects (ex. using ==) in this stack before and to treat that differently. Previously both levels of this Hash used the object's memory_id as a key (using object_id would be slow and wasteful). Unfortunately, prettyprint (pp.rb) uses this thread local variable to "pretend" to be inspect and inherit its same recursion behaviour. This commit changes the top-level hash to be an identity hash and to use objects as keys instead of their object_ids. I'd like to have also converted the 2nd level hash to an ident hash, but it would have prevented an optimization which avoids allocating a 2nd level hash for only a single element, which we want to keep because it's by far the most common case. So the new format of this hash is: { object => true } (not paired) { lhs_object => rhs_object_memory_id } (paired, single object) { lhs_object => { rhs_object_memory_id => true, ... } } (paired, many objects) We must also update pp.rb to match this (using identity hashes). Notes: Merged: https://github.com/ruby/ruby/pull/2644
2019-10-09Prefer st_is_member over st_lookup with 0Ben Woosley
The st_is_member DEFINE has simpler semantics, for more readable code. Notes: Merged: https://github.com/ruby/ruby/pull/1622
2019-10-09avoid overflow in integer multiplication卜部昌平
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes. Notes: Merged: https://github.com/ruby/ruby/pull/2540
2019-09-26Add rb_adjust_argv_kw_splat to internal.hJeremy Evans
We are calling this in a few other files, it is better to have it in a header than adding prototypes to the other files. Notes: Merged: https://github.com/ruby/ruby/pull/2491
2019-09-27Check the argument sizeNobuyoshi Nakada
Ensure that argument array size does not overflow as `int`, before cast in thread_do_start after new thread created.
2019-09-26Fix shorten-64-to-32 compile warnings/errorsJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2484
2019-09-26Fix keyword argument separation issues in Thread.newJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2484
2019-09-23Adjusted directives order of a function [ci skip]Nobuyoshi Nakada
2019-09-23Lazy init thread local storageLourens Naudé
Notes: Merged: https://github.com/ruby/ruby/pull/2295
2019-09-14Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans
It is not safe to set this in C functions that can be called from other C functions, as in the non argument-delegation case, you can end up calling a Ruby method with a flag indicating keywords are set without passing keywords. Introduce some new *_kw functions that take a kw_splat flag and use these functions to set RB_PASS_CALLED_KEYWORDS in places where we know we are delegating methods (e.g. Class#new, Method#call)
2019-09-05Add VM_NO_KEYWORDSJeremy Evans
I think this is easier to read than using literal 0 with comments in every case where it is used.
2019-09-05Propagate kw_splat informationYusuke Endoh
The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
2019-08-29drop-in type check for rb_define_singleton_method卜部昌平
We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
2019-08-27rb_uninterruptible now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This function has only one call site so adding appropriate prototype is trivial.
2019-08-27rb_thread_create now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_thread_create, which seems very safe to do.
2019-08-19unsigned int should have enough bits for rb_thread_shield_waitingNobuyoshi Nakada
2019-08-09gc.h is required on mswin build.Koichi Sasada
thread.c requires gc.h on mswin build. Sorry.
2019-08-09add rp() and bp() in internal.h.Koichi Sasada
debug utility macro rp() (rp_m()) and bp() are introduced. * rp(obj) shows obj information w/o any side-effect to STDERR. * rp_m(m, obj) is similar to rp(obj), but show m before. * bp() is alias of ruby_debug_breakpoint(), which is registered as a breakpoint in run.gdb (used by `make gdb` or make gdb-ruby`).
2019-07-19Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams
2019-07-15check return value of blocking_region_begin().Koichi Sasada
blocking_region_begin() can return FALSE if it fails to acquire GVL, so check it.
2019-07-15thread.c (rb_thread_shield_waiting_{inc,dec}): prefer long to intYusuke Endoh
`(unsigned int)(THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT)` is 0xffffffff, and w > 0xffffffff is always true. Coverity Scan pointed out this issue.
2019-06-28[DOC] Re-apply r11000, 41256fd43275c8bf66460510da7ab958a802e2a2Nobuyoshi Nakada
* eval.c (rb_thread_kill): fix Thread#kill docs, which returns the thread object in all cases. From: why the lucky stiff <why@ruby-lang.org>