Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions coroutine/asyncify/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ 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());
Expand All @@ -77,7 +79,11 @@ 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;
}
Expand Down
6 changes: 6 additions & 0 deletions coroutine/emscripten/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ 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(&current->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;
}
Expand Down
4 changes: 4 additions & 0 deletions coroutine/pthread/Context.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ 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;
}
Expand Down
6 changes: 6 additions & 0 deletions coroutine/ucontext/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ 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(&current->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;
}
Expand Down
5 changes: 3 additions & 2 deletions ext/digest/blake3/blake3_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
#endif

#if !defined(BLAKE3_ATOMICS)
#if defined(__has_include)
#if defined(__has_include) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 201112L
#if __has_include(<stdatomic.h>) && !defined(_MSC_VER)
#define BLAKE3_ATOMICS 1
#else
#define BLAKE3_ATOMICS 0
#endif /* __has_include(<stdatomic.h>) && !defined(_MSC_VER) */
#else
#define BLAKE3_ATOMICS 0
#endif /* defined(__has_include) */
#endif /* defined(__has_include) && C11 */
#endif /* BLAKE3_ATOMICS */

#if BLAKE3_ATOMICS
Expand Down
16 changes: 10 additions & 6 deletions ext/digest/blake3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# Extra per-object compiler flags, keyed by object basename.
simd_cflags = {}

def blake3_disable(macro)
$CPPFLAGS << " -D#{macro}"
end

# Probe used to confirm the compiler both accepts +flag+ and can compile the
# intrinsics the backend relies on.
def blake3_have_isa?(name, flag, snippet)
Expand Down Expand Up @@ -55,7 +59,7 @@ def blake3_have_isa?(name, flag, snippet)
objs << obj
simd_cflags[obj] = flag
else
$defs << "-D#{no_macro}"
blake3_disable(no_macro)
end
end
when /\A(aarch64|arm64)\z/i
Expand All @@ -67,11 +71,11 @@ def blake3_have_isa?(name, flag, snippet)
# No optimized backend wired up for this architecture (e.g. 32-bit x86,
# ppc): build portable-only. Disabling every x86 ISA keeps the dispatcher
# from referencing backends we didn't compile, and NEON is forced off.
$defs << "-DBLAKE3_NO_SSE2"
$defs << "-DBLAKE3_NO_SSE41"
$defs << "-DBLAKE3_NO_AVX2"
$defs << "-DBLAKE3_NO_AVX512"
$defs << "-DBLAKE3_USE_NEON=0"
blake3_disable("BLAKE3_NO_SSE2")
blake3_disable("BLAKE3_NO_SSE41")
blake3_disable("BLAKE3_NO_AVX2")
blake3_disable("BLAKE3_NO_AVX512")
blake3_disable("BLAKE3_USE_NEON=0")
end

$objs = objs.map { |o| "#{o}.#{$OBJEXT}" }
Expand Down
4 changes: 4 additions & 0 deletions thread_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ static pthread_condattr_t *condattr_monotonic = &condattr_mono;
static const void *const condattr_monotonic = NULL;
#endif

/* 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
Expand Down