Skip to content

Commit e642863

Browse files
authored
Move thread profile block declaration into pthread_impl.h. NFC. (#13840)
Moves the declaration to where its actaully used/needed. Also mark the profileBlock as atomic so that native code can access it (although right now its only accessed via JS atomic APIs).
1 parent fd97775 commit e642863

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var LibraryPThread = {
135135
setThreadName: function(pthreadPtr, name) {
136136
var profilerBlock = Atomics.load(HEAPU32, (pthreadPtr + {{{ C_STRUCTS.pthread.profilerBlock }}} ) >> 2);
137137
if (!profilerBlock) return;
138-
stringToUTF8(name, profilerBlock + {{{ C_STRUCTS.thread_profiler_block.name }}}, 32);
138+
stringToUTF8(name, profilerBlock + {{{ C_STRUCTS.thread_profiler_block.name }}}, {{{ cDefine('EM_THREAD_NAME_MAX') }}});
139139
},
140140

141141
getThreadName: function(pthreadPtr) {

src/struct_info.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,14 +1258,6 @@
12581258
},
12591259
{
12601260
"file": "emscripten/threading.h",
1261-
"structs": {
1262-
"thread_profiler_block": [
1263-
"threadStatus",
1264-
"currentStatusStartTime",
1265-
"timeSpentInStatus",
1266-
"name"
1267-
]
1268-
},
12691261
"defines": [
12701262
"EM_PROXIED_PTHREAD_CREATE",
12711263
"EM_PROXIED_CREATE_CONTEXT",

src/struct_info_internal.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
"canceldisable",
2121
"cancelasync",
2222
"locale"
23+
],
24+
"thread_profiler_block": [
25+
"threadStatus",
26+
"currentStatusStartTime",
27+
"timeSpentInStatus",
28+
"name"
2329
]
2430
},
25-
"defines": ["__ATTRP_C11_THREAD"]
31+
"defines": [
32+
"__ATTRP_C11_THREAD",
33+
"EM_THREAD_NAME_MAX"
34+
]
2635
},
2736
{
2837
"file": "libc.h",

system/include/emscripten/threading.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,6 @@ int emscripten_pthread_attr_gettransferredcanvases(const pthread_attr_t *a, cons
345345
// The special value "#canvas" denotes the element stored in Module.canvas.
346346
int emscripten_pthread_attr_settransferredcanvases(pthread_attr_t *a, const char *str);
347347

348-
struct thread_profiler_block
349-
{
350-
// One of THREAD_STATUS_*
351-
int threadStatus;
352-
// Wallclock time denoting when the current thread state was entered in.
353-
double currentStatusStartTime;
354-
// Accumulated duration times denoting how much time has been spent in each
355-
// state, in msecs.
356-
double timeSpentInStatus[EM_THREAD_STATUS_NUMFIELDS];
357-
// A human-readable name for this thread.
358-
char name[32];
359-
};
360-
361348
// Called when blocking on the main thread. This will error if main thread
362349
// blocking is not enabled, see ALLOW_BLOCKING_ON_MAIN_THREAD.
363350
void emscripten_check_blocking_allowed(void);

system/lib/libc/musl/src/internal/pthread_impl.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@
1515

1616
#define pthread __pthread
1717

18+
#ifdef __EMSCRIPTEN__
19+
#define EM_THREAD_NAME_MAX 32
20+
21+
typedef struct thread_profiler_block {
22+
// One of THREAD_STATUS_*
23+
int threadStatus;
24+
// Wallclock time denoting when the current thread state was entered in.
25+
double currentStatusStartTime;
26+
// Accumulated duration times denoting how much time has been spent in each
27+
// state, in msecs.
28+
double timeSpentInStatus[EM_THREAD_STATUS_NUMFIELDS];
29+
// A human-readable name for this thread.
30+
char name[EM_THREAD_NAME_MAX];
31+
} thread_profiler_block;
32+
#endif
33+
1834
struct pthread {
1935
// XXX Emscripten: Need some custom thread control structures.
2036
#ifdef __EMSCRIPTEN__
2137
// Note: The specific order of these fields is important, since these are accessed
2238
// by direct pointer arithmetic in worker.js.
2339
int threadStatus; // 0: thread not exited, 1: exited.
2440
int threadExitCode; // Thread exit code.
25-
void *profilerBlock; // If --threadprofiler is enabled, this pointer is allocated to contain internal information about the thread state for profiling purposes.
41+
thread_profiler_block * _Atomic profilerBlock; // If --threadprofiler is enabled, this pointer is allocated to contain internal information about the thread state for profiling purposes.
2642
#endif
2743

2844
struct pthread *self;

tests/reference_struct_info.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
"EM_PROXIED_RESIZE_OFFSCREENCANVAS": 657457152,
238238
"EM_QUEUED_CALL_MAX_ARGS": 11,
239239
"EM_QUEUED_JS_CALL_MAX_ARGS": 20,
240+
"EM_THREAD_NAME_MAX": 32,
240241
"EM_THREAD_STATUS_FINISHED": 6,
241242
"EM_THREAD_STATUS_NOTSTARTED": 0,
242243
"EM_THREAD_STATUS_RUNNING": 1,

0 commit comments

Comments
 (0)