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
12 changes: 6 additions & 6 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ var LibraryPThread = {
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.detached }}} >> 2), threadParams.detached);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.stack_size }}} >> 2), threadParams.stackSize);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.stack }}} >> 2), stackHigh);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} >> 2), threadParams.stackSize);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 8 >> 2), stackHigh);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 12 >> 2), threadParams.detached);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 0/*_a_stacksize*/ >> 2), threadParams.stackSize);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 8/*_a_stackaddr*/ >> 2), stackHigh);
Atomics.store(HEAPU32, tis + ({{{ C_STRUCTS.pthread.attr }}} + 12/*_a_detach*/ >> 2), threadParams.detached);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use C_STRUCTS.struct.field to avoid hardcoded constants here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are not declared in the structure sadly. I think musl is trying to hide the implementation detail by not declaring them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for the pending musl upgrade this isn't necessary, because this field was removed with musl commit 6f1866768a86239672ed811777dfe89994d64a65.

#if PTHREADS_PROFILING
PThread.createProfilerBlock(pthread.threadInfoStruct);
Expand Down Expand Up @@ -666,7 +666,7 @@ var LibraryPThread = {
// Deduce which WebGL canvases (HTMLCanvasElements or OffscreenCanvases) should be passed over to the
// Worker that hosts the spawned pthread.
// Comma-delimited list of CSS selectors that must identify canvases by IDs: "#canvas1, #canvas2, ..."
var transferredCanvasNames = attr ? {{{ makeGetValue('attr', 40, POINTER_TYPE) }}} : 0;
var transferredCanvasNames = attr ? {{{ makeGetValue('attr', C_STRUCTS.pthread_attr_t._a_transferredcanvases, POINTER_TYPE) }}} : 0;
#if OFFSCREENCANVASES_TO_PTHREAD
// Proxied canvases string pointer -1 is used as a special token to fetch
// whatever canvases were passed to build in -s
Expand Down Expand Up @@ -777,7 +777,7 @@ var LibraryPThread = {
// When musl creates C11 threads it passes __ATTRP_C11_THREAD (-1) which
// treat as if it was NULL.
if (attr && attr != {{{ cDefine('__ATTRP_C11_THREAD') }}}) {
stackSize = {{{ makeGetValue('attr', 0, 'i32') }}};
stackSize = {{{ makeGetValue('attr', 0/*_a_stacksize*/, 'i32') }}};
// Musl has a convention that the stack size that is stored to the pthread
// attribute structure is always musl's #define DEFAULT_STACK_SIZE
// smaller than the actual created stack size. That is, stored stack size
Expand All @@ -787,7 +787,7 @@ var LibraryPThread = {
// the pthread API. When reading the structure directly on JS side
// however, we need to offset the size manually here.
stackSize += {{{ cDefine('DEFAULT_STACK_SIZE') }}};
stackBase = {{{ makeGetValue('attr', 8, 'i32') }}};
stackBase = {{{ makeGetValue('attr', 8/*_a_stackaddr*/, 'i32') }}};
detached = {{{ makeGetValue('attr', 12/*_a_detach*/, 'i32') }}} !== 0/*PTHREAD_CREATE_JOINABLE*/;
} else {
// According to
Expand Down
3 changes: 3 additions & 0 deletions src/struct_info_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"result",
"attr"
],
"pthread_attr_t#": [
"_a_transferredcanvases"
],
"thread_profiler_block": [
"threadStatus",
"currentStatusStartTime",
Expand Down
4 changes: 4 additions & 0 deletions tests/reference_struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,10 @@
"stack_size": 76,
"threadStatus": 0
},
"pthread_attr_t": {
"__size__": 44,
"_a_transferredcanvases": 40
},
"sockaddr": {
"__size__": 16,
"sa_data": 2,
Expand Down
2 changes: 1 addition & 1 deletion tools/gen_struct_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def parse_c_output(lines):

def gen_inspect_code(path, struct, code):
if path[0][-1] == '#':
path[0] = path[0][:-1]
path[0] = path[0].rstrip('#')
prefix = ''
else:
prefix = 'struct '
Expand Down