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
2 changes: 1 addition & 1 deletion src/generics/lib.generics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ class ThreadHandle<R> {
// thread does too, so their counts change atomically from here on (erased under the
// other models)
Shared.share(this.start);
this.handle = tslang_thread_spawn(<Opaque>__thread_entry<R>, <Opaque>this.start);
this.handle = tslang_thread_spawn(__thread_entry<R>, <Opaque>this.start);
}

join(): R {
Expand Down
9 changes: 4 additions & 5 deletions src/native/lib.native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ declare function GC_gcollect(): void;
// thread
@nodrops declare function std_this_thread_sleep_for(milliseconds: u32): void;

// Threads (wrappers/thread.cpp). `entry` is a function `(arg: Opaque) => u32` cast to an Opaque: a
// function-typed parameter of a declared function reaches C as a three-pointer struct, not a code
// pointer. The new thread calls back into TypeScript, but only into the ThreadStart `arg` names,
// which the Thread keeps until join: nothing the caller lends is dropped.
@nodrops declare function tslang_thread_spawn(entry: Opaque, arg: Opaque): Opaque;
// Threads (wrappers/thread.cpp). @cdecl: `entry` reaches C as a function pointer. The new thread calls
// back into TypeScript, but only into the ThreadStart `arg` names, which the Thread keeps until join:
// nothing the caller lends is dropped.
@cdecl @nodrops declare function tslang_thread_spawn(entry: (arg: Opaque) => u32, arg: Opaque): Opaque;
@nodrops declare function tslang_thread_join(handle: Opaque): void;
@nodrops declare function tslang_thread_hardware_concurrency(): u32;
// Atomics.wait / notify: 0 "ok", 1 "not-equal", 2 "timed-out"; notify answers how many it woke
Expand Down
3 changes: 1 addition & 2 deletions src/wrappers/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ struct CollectorRegistration

typedef uint32_t (*ThreadEntry)(void *);

extern "C" TSLANG_EXPORT void *tslang_thread_spawn(void *entry, void *arg)
extern "C" TSLANG_EXPORT void *tslang_thread_spawn(ThreadEntry start, void *arg)
{
auto start = reinterpret_cast<ThreadEntry>(entry);
return new std::thread([start, arg]() {
#ifdef TSLANG_MM_GC
CollectorRegistration registration;
Expand Down