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 emscripten-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"1.38.14"
"1.38.15"
19 changes: 15 additions & 4 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var LibraryPThread = {
}
if (transferList.length > 0) {
postMessage({
targetThread: parentThreadId,
targetThread: _emscripten_main_browser_thread_id(),
cmd: 'objectTransfer',
offscreenCanvases: offscreenCanvases,
moduleCanvasId: Module['canvas'].id, // moduleCanvasId specifies which canvas is denoted via the "#canvas" shorthand.
Expand Down Expand Up @@ -269,12 +269,13 @@ var LibraryPThread = {
(function(worker) {
worker.onmessage = function(e) {
var d = e.data;
// Sometimes we need to backproxy events to the calling thread (e.g. HTML5 DOM events handlers such as emscripten_set_mousemove_callback()), so keep track in a globally accessible variable about the thread that initiated the proxying.
if (worker.pthread) PThread.currentProxiedOperationCallerThread = worker.pthread.threadInfoStruct;
// TODO: Move the proxied call mechanism into a queue inside heap.
if (d.proxiedCall) {
var returnValue;
var funcTable = (d.func >= 0) ? proxiedFunctionTable : ASM_CONSTS;
var funcIdx = (d.func >= 0) ? d.func : (-1 - d.func);
PThread.currentProxiedOperationCallerThread = worker.pthread.threadInfoStruct; // Sometimes we need to backproxy events to the calling thread (e.g. HTML5 DOM events handlers such as emscripten_set_mousemove_callback()), so keep track in a globally accessible variable about the thread that initiated the proxying.
switch(d.proxiedCall & 31) {
case 1: returnValue = funcTable[funcIdx](); break;
case 2: returnValue = funcTable[funcIdx](d.p0); break;
Expand Down Expand Up @@ -302,6 +303,7 @@ var LibraryPThread = {
Atomics.store(HEAP32, waitAddress >> 2, 1);
Atomics.wake(HEAP32, waitAddress >> 2, 1);
}
PThread.currentProxiedOperationCallerThread = undefined;
return;
}

Expand All @@ -313,6 +315,7 @@ var LibraryPThread = {
} else {
console.error('Internal error! Worker sent a message "' + d.cmd + '" to target pthread ' + d.targetThread + ', but that thread no longer exists!');
}
PThread.currentProxiedOperationCallerThread = undefined;
return;
}

Expand Down Expand Up @@ -345,7 +348,11 @@ var LibraryPThread = {
} else if (d.cmd === 'alert') {
alert('Thread ' + d.threadId + ': ' + d.text);
} else if (d.cmd === 'exit') {
// currently no-op
// Thread is exiting, no-op here
} else if (d.cmd === 'exitProcess') {
// A pthread has requested to exit the whole application process (runtime).
Module['noExitRuntime'] = false;
exit(d.returnCode);
} else if (d.cmd === 'cancelDone') {
PThread.freeThreadData(worker.pthread);
worker.pthread = undefined; // Detach the worker from the pthread object, and return it to the worker pool as an unused worker.
Expand All @@ -359,6 +366,7 @@ var LibraryPThread = {
} else {
err("worker sent an unknown command " + d.cmd);
}
PThread.currentProxiedOperationCallerThread = undefined;
};

worker.onerror = function(e) {
Expand Down Expand Up @@ -621,7 +629,10 @@ var LibraryPThread = {
if (inheritSched) {
var prevSchedPolicy = {{{ makeGetValue('attr', 20/*_a_policy*/, 'i32') }}};
var prevSchedPrio = {{{ makeGetValue('attr', 24/*_a_prio*/, 'i32') }}};
_pthread_getschedparam(_pthread_self(), attr + 20, attr + 24);
// If we are inheriting the scheduling properties from the parent thread, we need to identify the parent thread properly - this function call may
// be getting proxied, in which case _pthread_self() will point to the thread performing the proxying, not the thread that initiated the call.
var parentThreadPtr = PThread.currentProxiedOperationCallerThread ? PThread.currentProxiedOperationCallerThread : _pthread_self();
_pthread_getschedparam(parentThreadPtr, attr + 20, attr + 24);
schedPolicy = {{{ makeGetValue('attr', 20/*_a_policy*/, 'i32') }}};
schedPrio = {{{ makeGetValue('attr', 24/*_a_prio*/, 'i32') }}};
{{{ makeSetValue('attr', 20/*_a_policy*/, 'prevSchedPolicy', 'i32') }}};
Expand Down
3 changes: 3 additions & 0 deletions src/library_pthread_stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ var LibraryPThreadStub = {
sem_trywait: function() {},
sem_destroy: function() {},

emscripten_main_browser_thread_id__deps: ['pthread_self'],
emscripten_main_browser_thread_id: function() { return _pthread_self(); },

// When pthreads is not enabled, we can't use the Atomics futex api to do proper sleeps, so simulate a busy spin wait loop instead.
usleep: function(useconds) {
// int usleep(useconds_t useconds);
Expand Down
1 change: 1 addition & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ function ensureInitRuntime() {
#if USE_PTHREADS
// Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
__register_pthread_ptr(PThread.mainThreadBlock, /*isMainBrowserThread=*/!ENVIRONMENT_IS_WORKER, /*isMainRuntimeThread=*/1);
_emscripten_register_main_browser_thread_id(PThread.mainThreadBlock);
#endif
callRuntimeCallbacks(__ATINIT__);
}
Expand Down
15 changes: 13 additions & 2 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,10 @@

"EM_HTML5_SHORT_STRING_LEN_BYTES",
"EM_HTML5_MEDIUM_STRING_LEN_BYTES",
"EM_HTML5_LONG_STRING_LEN_BYTES"
"EM_HTML5_LONG_STRING_LEN_BYTES",

"EM_CALLBACK_THREAD_CONTEXT_MAIN_BROWSER_THREAD",
"EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD"
],
"structs": {
"EmscriptenKeyboardEvent": [
Expand Down Expand Up @@ -1491,7 +1494,15 @@
"EM_THREAD_STATUS_SLEEPING",
"EM_THREAD_STATUS_WAITFUTEX",
"EM_THREAD_STATUS_WAITPROXY",
"EM_THREAD_STATUS_FINISHED"
"EM_THREAD_STATUS_FINISHED",
"EM_FUNC_SIG_V",
"EM_FUNC_SIG_VI",
"EM_FUNC_SIG_VII",
"EM_FUNC_SIG_VIII",
"EM_FUNC_SIG_I",
"EM_FUNC_SIG_II",
"EM_FUNC_SIG_III",
"EM_FUNC_SIG_IIII"
]
},
{
Expand Down
15 changes: 15 additions & 0 deletions system/include/emscripten/html5.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
#ifndef __emscripten_events_h__
#define __emscripten_events_h__

#ifdef __cplusplus
#if !defined(__DEFINED_pthread_t)
typedef unsigned long pthread_t;
#define __DEFINED_pthread_t
#endif
#else
#if !defined(__DEFINED_pthread_t)
typedef struct __pthread * pthread_t;
#define __DEFINED_pthread_t
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -452,6 +464,9 @@ extern EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target,
extern EMSCRIPTEN_RESULT emscripten_set_element_css_size(const char *target, double width, double height);
extern EMSCRIPTEN_RESULT emscripten_get_element_css_size(const char *target, double *width, double *height);

#define EM_CALLBACK_THREAD_CONTEXT_MAIN_BROWSER_THREAD ((pthread_t)0x1)
#define EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD ((pthread_t)0x2)

#ifdef __cplusplus
} // ~extern "C"
#endif
Expand Down
Loading