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

447 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 12fbdf4d4e
Fix conflicting declaration on Solaris
SunC
```
"cont.c", line 24: identifier redeclared: madvise
	current : function(pointer to char, unsigned int, int) returning int
	previous: function(pointer to void, unsigned int, int) returning int : "/usr/include/sys/mman.h", line 232
```

GCC
```
cont.c:24:12: error: conflicting types for 'madvise'
   24 | extern int madvise(caddr_t, size_t, int);
      |            ^~~~~~~
In file included from cont.c:16:
/usr/include/sys/mman.h:232:12: note: previous declaration of 'madvise' was here
  232 | extern int madvise(void *, size_t, int);
      |            ^~~~~~~
```
2021-11-30 09:10:58 +09:00
Naohisa Goto 8287d2f23c Workaround for implicit declaration of function 'madvise' on Solaris
On Solaris, madvise(3C) is NOT defined for SUS (XPG4v2) or later,
but MADV_* macros are defined when __EXTENSIONS__ is defined.
This may cause compile error on Solaris 10 with GCC when
"-Werror=implicit-function-declaration" and "-D_XOPEN_SOURCE=600"
are added by configure.
2021-11-30 00:03:04 +09:00
卜部昌平 90f2ab9d62 rb_fiber_raise(): add doxygen
Must not be a bad idea to improve documents.
2021-09-30 20:55:23 +13:00
Samuel Williams 88ba5fe547 Expose `rb_fiber_raise` and tidy up the internal implementation. 2021-09-20 18:30:51 +12:00
Nobuyoshi Nakada 9c5ad5d42d
Suppress format-pedantic warnings 2021-09-02 08:47:47 +09:00
Nobuyoshi Nakada 28d03ee776 Remove root_jmpbuf in rb_thread_struct
It has not been used since 1b82c877df.
2021-08-10 19:08:38 +09:00
S-H-GAMELINKS ac7986f46a Remove unneeded rb_fiber_transfer_kw declaration 2021-08-07 17:18:20 +12:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Nobuyoshi Nakada ab37e6ee7e
Adjust styles [ci skip]
* --procnames-start-lines
2021-07-18 19:55:07 +09:00
Kazuki Yamaguchi 4885c44bca cont.c: fix formatting of RDoc for Fiber class 2021-07-17 13:37:41 +09:00
Samuel Williams 42130a64f0
Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
nagachika 8366506de1 cont.c: Replace "iff" with "if and only if" 2021-06-12 20:15:08 +09:00
Nobuyoshi Nakada 93be7a4c6b
Suppress clobbered warnings on Travis-CI ppc64le-linux 2021-06-03 20:07:26 +09:00
Samuel Williams dc25412042 Expose `rb_fiber_transfer` and `rb_fiber_transfer_kw`. 2021-06-03 20:47:31 +12:00
Ryuta Kamizono 33f2ff3bab Fix some typos by spell checker 2021-04-26 10:07:41 +09:00
Samuel Williams 92449e0e99 Fix handling of timeout accessing scheduler outside of non-blocking context. 2021-03-30 18:38:42 +13:00
David CARLIER 875c85a8bd fiber context update for Mac OS.
it is more about memory accounting sake. At allocation time,
 we make clear we re possibly reusing regions marked as reusable.
Noted also calls might not necessarily succeed at first so we do
 only when necessary.
2021-03-29 09:32:40 +13:00
David Carlier 5e16c3a12a solaris/illumos build fix. 2021-03-22 22:51:15 +09:00
Kazuhiro NISHIYAMA ad0fa53203
[DOC] some methods of Fiber do not need to require anymore [Feature #17407] 2021-03-22 18:59:25 +09:00
Nobuyoshi Nakada d91ade3e1e
Renamed functions for Fiber singleton methods 2021-03-12 18:15:56 +09:00
Nobuyoshi Nakada 90c12defb3
Constified variables for getenv 2021-03-12 17:13:53 +09:00
Nobuyoshi Nakada 9d8c66fd6a
rb_fiber_terminate never returns 2021-02-24 04:09:57 +09:00
nicholas a. evans 3ee4fa9491
Send :fiber_switch event for almost every fiber_switch (#4207)
With this patch, TracePoint receives a `:fiber_switch` event for
_almost_ every fiber switch.  Previously, it would not be sent when an
exception was going to be raised. Now the event should only be blockable
by an interrupt (including `Thread#raise`) or a fatal error.

Additionally, interrupts will now be checked on the return fiber
_before_ re-raising the terminating unhandled exception.  And a fiber
that terminates with an unhandled exception no longer creates a pending
interrupt on its thread.  The exception will be raised in the return
fiber the same way as `Fiber#raise`: using `cont.value` with `cont.argc
== -1`

I moved `rb_exc_raise` from `fiber_store` to the end of `fiber_switch`
after _all_ of the other cleanup code: `fiber_stack_release`,
`th->blocking` increment, `RUBY_VM_CHECK_INTS`, and `EXEC_EVENT_HOOK`.
It seems to me that skipping those other cleanup steps may have also
resulted in other bugs.
2021-02-22 10:33:11 +13:00
Samuel Williams 5f69a7f604
Expose scheduler as public interface & bug fixes. (#3945)
* Rename `rb_scheduler` to `rb_fiber_scheduler`.

* Use public interface if available.

* Use `rb_check_funcall` where possible.

* Don't use `unblock` unless the fiber was non-blocking.
2021-02-09 19:39:56 +13:00
Nobuyoshi Nakada 521ad9a13a Moved Fiber methods into core [Feature #17407] 2021-01-13 23:20:02 +09:00
Marcus Stollsteimer 3108ad7bf3 [DOC] Fix grammar: "is same as" -> "is the same as" 2021-01-05 15:13:53 +01:00
Nobuyoshi Nakada 09aca50fc4
Adjusted styles [ci skip] 2020-12-28 19:52:14 +09:00
Marc-Andre Lafortune cf1f9bdc8d Language tweaks to Fiber [doc] 2020-12-27 16:09:06 -05:00
Kazuhiro NISHIYAMA 2c752ff930
Fix a typo [ci skip] 2020-12-24 23:13:36 +09:00
zverok 1415653c84 Redocument non-blocking Fibers and scheduler
* Document Fiber's method related to scheduling;
* Extend Fiber's class docs with concepts of non-blocking
  fibers;
* Introduce "imaginary" (documentation-only) class
  Fiber::SchedulerInterface to properly document how
  scheduler's methods should look.
2020-12-24 03:03:51 -05:00
zverok 24ae0e8ed7 Review comments 2020-12-24 14:37:09 +09:00
zverok 5696c69354 Redocument Fiber#transfer 2020-12-24 14:37:09 +09:00
Delton Ding c6d7e02b90 Enable `Fiber.current` and `Fiber#alive?` call inside ractor 2020-12-23 03:27:14 +09:00
Marc-Andre Lafortune d0050edb84 Update Fiber#backtrace doc [See bug #17408] 2020-12-21 21:07:13 -05:00
zverok 843fd1e8cf Document Fiber#backtrace and #backtrace_locations 2020-12-21 19:22:38 -05:00
nicholas a. evans 31e8de2920 Let Fiber#raise work with transferring fibers
This automatically choosess whether to use transfer on a transferring
fiber or resume on a yielding fiber.  If the fiber is resuming, it
raises a FiberError.
2020-12-12 10:18:19 +13:00
Takashi Kokubun 01f38693aa
Remove obsoleted internal/mjit.h inclusion
🙇
2020-11-22 20:28:34 -08:00
Takashi Kokubun e0156bd396
Make sure all threads are scanned on unload_units
This has been a TODO since 79df14c04b. While adcf0316d1 covered the
root_fiber of the initial thread, it didn't cover root_fibers of other
threads. Now it's hooked properly in rb_threadptr_root_fiber_setup.

With regards to "XXX: Is this mjit_cont `mjit_cont_free`d?", when
rb_threadptr_root_fiber_release is called, although I'm not sure when
th->root_fiber is truthy, fiber_free seems to call cont_free and
mjit_cont_free. So mjit_conts of root_fibers seem to be freed properly.
2020-11-21 19:36:55 -08:00
Koichi Sasada 5e3259ea74 fix public interface
To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
2020-11-18 03:52:41 +09:00
Nobuyoshi Nakada 0d52dce3a3
strip trailing spaces and adjusted indents [ci skip] 2020-11-12 19:27:20 +09:00
Samuel Williams a08ee8330d Rename to `Fiber#set_scheduler`. 2020-11-07 23:39:50 +13:00
Kazuhiro NISHIYAMA 0714cb760c
Remove duplicated line [ci skip]
ref bf3b2a4374
2020-10-14 15:16:36 +09:00
Koichi Sasada bf3b2a4374 relax Fiber#transfer's restriction
Using Fiber#transfer with Fiber#resume for a same Fiber is
limited (once Fiber#transfer is called for a fiber, the fiber
can not be resumed more). This restriction was introduced to
protect the resume/yield chain, but we realized that it is too much
to protect the chain. Instead of the current restriction, we
introduce some other protections.

(1) can not transfer to the resuming fiber.
(2) can not transfer to the yielding fiber.
(3) can not resume transferred fiber.
(4) can not yield from not-resumed fiber.

[Bug #17221]

Also at the end of a transferred fiber, it had continued on root fiber.
However, if the root fiber resumed a fiber (and that fiber can resumed
another fiber), this behavior also breaks the resume/yield chain.
So at the end of a transferred fiber, switch to the edge of resume
chain from root fiber.
For example, root fiber resumed f1 and f1 resumed f2, transferred to
f3 and f3 terminated, then continue from the fiber f2 (it was continued
from root fiber without this patch).
2020-10-12 22:58:41 +09:00
Aaron Patterson 9fb60672d5 Fix a use-after-free bug reported by ASAN
If a fiber and thread are collected at the same time, the thread might
get collected first and the pointer on the fiber will go bad.  I don't
think we need to check whether or not this is the main fiber in order to
release its stack
2020-10-01 08:42:52 -07:00
Benoit Daloze 178c1b0922 Make Mutex per-Fiber instead of per-Thread
* Enables Mutex to be used as synchronization between multiple Fibers
  of the same Thread.
* With a Fiber scheduler we can yield to another Fiber on contended
  Mutex#lock instead of blocking the entire thread.
* This also makes the behavior of Mutex consistent across CRuby, JRuby and TruffleRuby.
* [Feature #16792]
2020-09-14 16:44:09 +12:00
Samuel Williams 132453fa52 Rename `Fiber{}` to `Fiber.schedule{}`. 2020-09-14 16:44:09 +12:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Samuel Williams 0a218a97ad Expose ec -> backtrace (internal) and use it to implement fiber backtrace.
See <https://bugs.ruby-lang.org/issues/16815> for more details.
2020-08-18 00:56:35 +12:00
Samuel Williams 4bff8e8423 Ensure that the head of the vacancy list is correctly inserted into the linked list.
See <https://bugs.ruby-lang.org/issues/16814> for more details.
2020-06-05 11:40:59 +12:00
Jeremy Evans faab5cbeb7 Fix documentation for Fiber#raise [ci skip]
Fixes [Bug #16912]
2020-05-25 19:46:12 -07:00