File tree Expand file tree Collapse file tree 4 files changed +31
-23
lines changed Expand file tree Collapse file tree 4 files changed +31
-23
lines changed Original file line number Diff line number Diff line change @@ -1110,7 +1110,6 @@ var LibraryPThread = {
11101110 }
11111111 worker . postMessage ( { 'cmd' : 'processProxyingQueue' , 'queue' : queue } ) ;
11121112 }
1113- return 1 ;
11141113 }
11151114} ;
11161115
Original file line number Diff line number Diff line change 55 * found in the LICENSE file.
66 */
77
8+ #include <emscripten/threading.h>
9+ #include <stdatomic.h>
810#include <stdlib.h>
911#include <string.h>
1012
@@ -102,3 +104,27 @@ task em_task_queue_dequeue(em_task_queue* queue) {
102104 queue -> head = (queue -> head + 1 ) % queue -> capacity ;
103105 return t ;
104106}
107+
108+ // Send a postMessage notification containing the em_task_queue pointer to the
109+ // target thread so it will execute the queue when it returns to the event loop.
110+ // Also pass in the current thread and main thread ids to minimize calls back
111+ // into Wasm.
112+ void _emscripten_notify_task_queue (pthread_t target_thread ,
113+ pthread_t curr_thread ,
114+ pthread_t main_thread ,
115+ em_task_queue * queue );
116+
117+ void em_task_queue_notify (em_task_queue * queue ) {
118+ // If there is no pending notification for this queue, create one. If an old
119+ // notification is currently being processed, it may or may not execute this
120+ // work. In case it does not, the new notification will ensure the work is
121+ // still executed.
122+ notification_state previous =
123+ atomic_exchange (& queue -> notification , NOTIFICATION_PENDING );
124+ if (previous != NOTIFICATION_PENDING ) {
125+ _emscripten_notify_task_queue (queue -> thread ,
126+ pthread_self (),
127+ emscripten_main_browser_thread_id (),
128+ queue );
129+ }
130+ }
Original file line number Diff line number Diff line change @@ -41,15 +41,6 @@ typedef struct em_task_queue {
4141 int tail ;
4242} em_task_queue ;
4343
44- // Send a postMessage notification containing the em_task_queue pointer to the
45- // target thread so it will execute the queue when it returns to the event loop.
46- // Also pass in the current thread and main thread ids to minimize calls back
47- // into Wasm.
48- extern int _emscripten_notify_task_queue (pthread_t target_thread ,
49- pthread_t curr_thread ,
50- pthread_t main_thread ,
51- em_task_queue * queue );
52-
5344em_task_queue * em_task_queue_create (pthread_t thread );
5445
5546void em_task_queue_destroy (em_task_queue * queue );
@@ -72,3 +63,7 @@ int em_task_queue_enqueue(em_task_queue* queue, task t);
7263
7364// Not thread safe. Assumes the queue is not empty.
7465task em_task_queue_dequeue (em_task_queue * queue );
66+
67+ // Schedule the queue to be executed next time its owning thread returns to its
68+ // event loop.
69+ void em_task_queue_notify (em_task_queue * queue );
Original file line number Diff line number Diff line change 99#include <emscripten/proxying.h>
1010#include <emscripten/threading.h>
1111#include <pthread.h>
12- #include <stdatomic.h>
1312#include <stdlib.h>
1413#include <string.h>
1514
@@ -268,18 +267,7 @@ int emscripten_proxy_async(em_proxying_queue* q,
268267 return 0 ;
269268 }
270269
271- // If there is no pending notification for this queue, create one. If an old
272- // notification is currently being processed, it may or may not execute this
273- // work. In case it does not, the new notification will ensure the work is
274- // still executed.
275- notification_state previous =
276- atomic_exchange (& tasks -> notification , NOTIFICATION_PENDING );
277- if (previous != NOTIFICATION_PENDING ) {
278- _emscripten_notify_task_queue (target_thread ,
279- pthread_self (),
280- emscripten_main_browser_thread_id (),
281- tasks );
282- }
270+ em_task_queue_notify (tasks );
283271 return 1 ;
284272}
285273
You can’t perform that action at this time.
0 commit comments