Skip to content

Commit

Permalink
Use existing result rather than adding to pthread struct. NFC (emsc…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Aug 12, 2021
1 parent daa21d3 commit 7e538a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
12 changes: 7 additions & 5 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,12 @@ var LibraryPThread = {
for (;;) {
var threadStatus = Atomics.load(HEAPU32, (thread + {{{ C_STRUCTS.pthread.threadStatus }}} ) >> 2);
if (threadStatus == 1) { // Exited?
var threadExitCode = Atomics.load(HEAPU32, (thread + {{{ C_STRUCTS.pthread.threadExitCode }}} ) >> 2);
if (status) {{{ makeSetValue('status', 0, 'threadExitCode', 'i32') }}};
Atomics.store(HEAPU32, (thread + {{{ C_STRUCTS.pthread.detached }}} ) >> 2, 1); // Mark the thread as detached.

if (status) {
var result = Atomics.load(HEAPU32, (thread + {{{ C_STRUCTS.pthread.result }}} ) >> 2);
{{{ makeSetValue('status', 0, 'result', 'i32') }}};
}
// Mark the thread as detached.
Atomics.store(HEAPU32, (thread + {{{ C_STRUCTS.pthread.detached }}} ) >> 2, 1);
if (!ENVIRONMENT_IS_PTHREAD) cleanupThread(thread);
else postMessage({ 'cmd': 'cleanupThread', 'thread': thread });
return 0;
Expand Down Expand Up @@ -970,7 +972,7 @@ var LibraryPThread = {
Atomics.store(HEAPU32, (tb + {{{ C_STRUCTS.pthread.cancelasync }}} ) >> 2, 0/*PTHREAD_CANCEL_DEFERRED*/);
PThread.runExitHandlers();

Atomics.store(HEAPU32, (tb + {{{ C_STRUCTS.pthread.threadExitCode }}} ) >> 2, status);
Atomics.store(HEAPU32, (tb + {{{ C_STRUCTS.pthread.result }}} ) >> 2, status);
// When we publish this, the main thread is free to deallocate the thread object and we are done.
// Therefore set _pthread_self = 0; above to 'release' the object in this worker thread.
Atomics.store(HEAPU32, (tb + {{{ C_STRUCTS.pthread.threadStatus }}} ) >> 2, 1); // Mark the thread as no longer running.
Expand Down
2 changes: 1 addition & 1 deletion src/struct_info_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"structs": {
"pthread": [
"threadStatus",
"threadExitCode",
"profilerBlock",
"self",
"tsd",
"detached",
"stack",
"stack_size",
"result",
"attr",
"robust_list",
"tid",
Expand Down
1 change: 0 additions & 1 deletion system/lib/libc/musl/src/internal/pthread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct pthread {
// Note: The specific order of these fields is important, since these are accessed
// by direct pointer arithmetic in worker.js.
int threadStatus; // 0: thread not exited, 1: exited.
int threadExitCode; // Thread exit code.
thread_profiler_block * _Atomic profilerBlock; // If --threadprofiler is enabled, this pointer is allocated to contain internal information about the thread state for profiling purposes.
#endif

Expand Down
28 changes: 14 additions & 14 deletions tests/reference_struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,21 +1405,21 @@
"p_proto": 8
},
"pthread": {
"__size__": 228,
"attr": 104,
"cancelasync": 60,
"canceldisable": 56,
"detached": 64,
"locale": 172,
"profilerBlock": 8,
"robust_list": 152,
"self": 12,
"stack": 76,
"stack_size": 80,
"threadExitCode": 4,
"__size__": 224,
"attr": 100,
"cancelasync": 56,
"canceldisable": 52,
"detached": 60,
"locale": 168,
"profilerBlock": 4,
"result": 88,
"robust_list": 148,
"self": 8,
"stack": 72,
"stack_size": 76,
"threadStatus": 0,
"tid": 40,
"tsd": 100
"tid": 36,
"tsd": 96
},
"rlimit": {
"__size__": 16,
Expand Down

0 comments on commit 7e538a4

Please sign in to comment.