mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
coroutine: consistently return the context that resumed transfer. (#18814)
This commit is contained in:
1 parent
46c2853661
commit
84a8652f01
5 files changed
+12
-40
Notes:
git
2026-09-14 03:04:34 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
No files matched your search
@@ -62,9 +62,6 @@ static inline void coroutine_initialize(struct coroutine_context *context, corou
|
||||
static inline struct coroutine_context * coroutine_transfer(struct coroutine_context * current, struct coroutine_context * target)
|
||||
{
|
||||
if (ASYNCIFY_CORO_DEBUG) fprintf(stderr, "[%s] entry (current = %p, target = %p)\n", __func__, current, target);
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
struct coroutine_context * previous = target->from;
|
||||
#endif
|
||||
|
||||
target->from = current;
|
||||
if (ASYNCIFY_CORO_DEBUG) fprintf(stderr, "[%s] current->current_sp = %p -> %p\n", __func__, current->current_sp, rb_wasm_get_stack_pointer());
|
||||
@@ -79,13 +76,8 @@ static inline struct coroutine_context * coroutine_transfer(struct coroutine_con
|
||||
|
||||
rb_wasm_set_stack_pointer(current->current_sp);
|
||||
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
/* from is read only by coroutine_trampoline, when target starts, which has
|
||||
* happened before we get here. */
|
||||
target->from = previous;
|
||||
#endif
|
||||
|
||||
return target;
|
||||
/* current may have been resumed by a context other than target. */
|
||||
return current->from;
|
||||
}
|
||||
|
||||
static inline void coroutine_destroy(struct coroutine_context * context)
|
||||
|
||||
@@ -60,19 +60,11 @@ static inline void coroutine_initialize(
|
||||
|
||||
static inline struct coroutine_context * coroutine_transfer(struct coroutine_context * current, struct coroutine_context * target)
|
||||
{
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
struct coroutine_context * previous = target->from;
|
||||
#endif
|
||||
|
||||
target->from = current;
|
||||
emscripten_fiber_swap(¤t->state, &target->state);
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
/* from is read only by coroutine_trampoline, when target starts, which has
|
||||
* happened before we get here. */
|
||||
target->from = previous;
|
||||
#endif
|
||||
|
||||
return target;
|
||||
/* current may have been resumed by a context other than target. */
|
||||
return current->from;
|
||||
}
|
||||
|
||||
static inline void coroutine_destroy(struct coroutine_context * context)
|
||||
|
||||
@@ -229,13 +229,8 @@ struct coroutine_context * coroutine_transfer(struct coroutine_context * current
|
||||
pthread_testcancel();
|
||||
#endif
|
||||
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
/* from is read only by coroutine_trampoline, when target starts, which has
|
||||
* happened before we get here. */
|
||||
target->from = previous;
|
||||
#endif
|
||||
|
||||
return target;
|
||||
/* current may have been resumed by a context other than target. */
|
||||
return current->from;
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
@@ -60,19 +60,16 @@ static inline void coroutine_initialize(
|
||||
|
||||
static inline struct coroutine_context * coroutine_transfer(struct coroutine_context * current, struct coroutine_context * target)
|
||||
{
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
struct coroutine_context * previous = target->from;
|
||||
#endif
|
||||
|
||||
target->from = current;
|
||||
swapcontext(¤t->state, &target->state);
|
||||
#ifndef COROUTINE_TARGET_MAY_BE_FREED
|
||||
/* from is read only by coroutine_trampoline, when target starts, which has
|
||||
* happened before we get here. */
|
||||
target->from = previous;
|
||||
#endif
|
||||
if (swapcontext(¤t->state, &target->state) == -1) {
|
||||
target->from = previous;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return target;
|
||||
/* current may have been resumed by a context other than target. */
|
||||
return current->from;
|
||||
}
|
||||
|
||||
static inline void coroutine_destroy(struct coroutine_context * context)
|
||||
|
||||
@@ -67,10 +67,6 @@ static const void *const condattr_monotonic = NULL;
|
||||
// otherwise the caller has to restate the deadline in the condvar's clock.
|
||||
#define RB_NATIVE_COND_HRTIME_DEADLINE_P() (condattr_monotonic != NULL)
|
||||
|
||||
/* A retiring shared native thread frees its own context while the threads it
|
||||
* parked are still suspended with that context as their target. */
|
||||
#define COROUTINE_TARGET_MAY_BE_FREED 1
|
||||
|
||||
#include COROUTINE_H
|
||||
|
||||
#ifndef HAVE_SYS_EVENT_H
|
||||
|
||||
Reference in new issue
Block a user