Skip to content

Commit 7163beb

Browse files
authored
Move internal-only parts of emscripten/threading.h (#15756)
The layout of the em_called_queue struct does not need to be public.
1 parent 27de75a commit 7163beb

File tree

5 files changed

+86
-73
lines changed

5 files changed

+86
-73
lines changed

src/struct_info.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@
999999
"EM_PROXIED_CREATE_CONTEXT",
10001000
"EM_PROXIED_RESIZE_OFFSCREENCANVAS",
10011001
"EM_PROXIED_JS_FUNCTION",
1002-
"EM_QUEUED_CALL_MAX_ARGS",
10031002
"EM_QUEUED_JS_CALL_MAX_ARGS",
10041003
"EM_THREAD_STATUS_NOTSTARTED",
10051004
"EM_THREAD_STATUS_RUNNING",

system/include/emscripten/threading.h

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -42,40 +42,11 @@ int emscripten_futex_wait(volatile void/*uint32_t*/ *addr, uint32_t val, double
4242
// INT_MAX to wake all waiters on that location.
4343
int emscripten_futex_wake(volatile void/*uint32_t*/ *addr, int count);
4444

45-
typedef union em_variant_val
46-
{
47-
int i;
48-
int64_t i64;
49-
float f;
50-
double d;
51-
void *vp;
52-
char *cp;
53-
} em_variant_val;
54-
55-
// Proxied C/C++ functions support at most this many arguments. Dispatch is
56-
// static/strongly typed by signature.
57-
#define EM_QUEUED_CALL_MAX_ARGS 11
5845
// Proxied JS function can support a few more arguments than proxied C/C++
5946
// functions, because the dispatch is variadic and signature independent.
6047
#define EM_QUEUED_JS_CALL_MAX_ARGS 20
61-
typedef struct em_queued_call
62-
{
63-
int functionEnum;
64-
void *functionPtr;
65-
_Atomic uint32_t operationDone;
66-
em_variant_val args[EM_QUEUED_JS_CALL_MAX_ARGS];
67-
em_variant_val returnValue;
68-
69-
// An optional pointer to a secondary data block that should be free()d when
70-
// this queued call is freed.
71-
void *satelliteData;
72-
73-
// If true, the caller has "detached" itself from this call object and the
74-
// Emscripten main runtime thread should free up this em_queued_call object
75-
// after it has been executed. If false, the caller is in control of the
76-
// memory.
77-
int calleeDelete;
78-
} em_queued_call;
48+
49+
typedef struct em_queued_call em_queued_call;
7950

8051
void emscripten_sync_run_in_main_thread(em_queued_call *call);
8152
void *emscripten_sync_run_in_main_thread_0(int function);
@@ -84,39 +55,6 @@ void *emscripten_sync_run_in_main_thread_2(int function, void *arg1, void *arg2)
8455
void *emscripten_sync_run_in_main_thread_3(int function, void *arg1, void *arg2, void *arg3);
8556
void *emscripten_sync_run_in_main_thread_7(int function, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7);
8657

87-
typedef void (*em_func_v)(void);
88-
typedef void (*em_func_vi)(int);
89-
typedef void (*em_func_vf)(float);
90-
typedef void (*em_func_vii)(int, int);
91-
typedef void (*em_func_vif)(int, float);
92-
typedef void (*em_func_vff)(float, float);
93-
typedef void (*em_func_viii)(int, int, int);
94-
typedef void (*em_func_viif)(int, int, float);
95-
typedef void (*em_func_viff)(int, float, float);
96-
typedef void (*em_func_vfff)(float, float, float);
97-
typedef void (*em_func_viiii)(int, int, int, int);
98-
typedef void (*em_func_viifi)(int, int, float, int);
99-
typedef void (*em_func_vifff)(int, float, float, float);
100-
typedef void (*em_func_vffff)(float, float, float, float);
101-
typedef void (*em_func_viiiii)(int, int, int, int, int);
102-
typedef void (*em_func_viffff)(int, float, float, float, float);
103-
typedef void (*em_func_viiiiii)(int, int, int, int, int, int);
104-
typedef void (*em_func_viiiiiii)(int, int, int, int, int, int, int);
105-
typedef void (*em_func_viiiiiiii)(int, int, int, int, int, int, int, int);
106-
typedef void (*em_func_viiiiiiiii)(int, int, int, int, int, int, int, int, int);
107-
typedef void (*em_func_viiiiiiiiii)(int, int, int, int, int, int, int, int, int, int);
108-
typedef void (*em_func_viiiiiiiiiii)(int, int, int, int, int, int, int, int, int, int, int);
109-
typedef int (*em_func_i)(void);
110-
typedef int (*em_func_ii)(int);
111-
typedef int (*em_func_iii)(int, int);
112-
typedef int (*em_func_iiii)(int, int, int);
113-
typedef int (*em_func_iiiii)(int, int, int, int);
114-
typedef int (*em_func_iiiiii)(int, int, int, int, int);
115-
typedef int (*em_func_iiiiiii)(int, int, int, int, int, int);
116-
typedef int (*em_func_iiiiiiii)(int, int, int, int, int, int, int);
117-
typedef int (*em_func_iiiiiiiii)(int, int, int, int, int, int, int, int);
118-
typedef int (*em_func_iiiiiiiiii)(int, int, int, int, int, int, int, int, int);
119-
12058
// Encode function signatures into a single uint32_t integer.
12159
// N.B. This encoding scheme is internal to the implementation, and can change
12260
// in the future. Do not depend on the exact numbers in this scheme.

system/lib/pthread/library_pthread.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <emscripten/threading.h>
3535
#include <emscripten/stack.h>
3636

37+
#include "threading_internal.h"
38+
3739
void __pthread_testcancel();
3840

3941
int emscripten_pthread_attr_gettransferredcanvases(const pthread_attr_t* a, const char** str) {
@@ -90,10 +92,10 @@ void emscripten_thread_sleep(double msecs) {
9092
emscripten_current_thread_process_queued_calls();
9193

9294
// If we have less than this many msecs left to wait, busy spin that instead.
93-
const double minimumTimeSliceToSleep = 0.1;
95+
double min_ms_slice_to_sleep = 0.1;
9496

9597
// runtime thread may need to run proxied calls, so sleep in very small slices to be responsive.
96-
const double maxMsecsSliceToSleep = emscripten_is_main_runtime_thread() ? 1 : 100;
98+
double max_ms_slice_to_sleep = emscripten_is_main_runtime_thread() ? 1 : 100;
9799

98100
emscripten_conditional_set_current_thread_status(
99101
EM_THREAD_STATUS_RUNNING, EM_THREAD_STATUS_SLEEPING);
@@ -105,11 +107,13 @@ void emscripten_thread_sleep(double msecs) {
105107
emscripten_current_thread_process_queued_calls();
106108

107109
now = emscripten_get_now();
108-
double msecsToSleep = target - now;
109-
if (msecsToSleep > maxMsecsSliceToSleep)
110-
msecsToSleep = maxMsecsSliceToSleep;
111-
if (msecsToSleep >= minimumTimeSliceToSleep)
112-
emscripten_futex_wait(&dummyZeroAddress, 0, msecsToSleep);
110+
double ms_to_sleep = target - now;
111+
if (ms_to_sleep > max_ms_slice_to_sleep) {
112+
ms_to_sleep = max_ms_slice_to_sleep;
113+
}
114+
if (ms_to_sleep >= min_ms_slice_to_sleep) {
115+
emscripten_futex_wait(&dummyZeroAddress, 0, ms_to_sleep);
116+
}
113117
now = emscripten_get_now();
114118
};
115119

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2021 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#pragma once
9+
10+
typedef union em_variant_val
11+
{
12+
int i;
13+
int64_t i64;
14+
float f;
15+
double d;
16+
void *vp;
17+
char *cp;
18+
} em_variant_val;
19+
20+
// Proxied C/C++ functions support at most this many arguments. Dispatch is
21+
// static/strongly typed by signature.
22+
#define EM_QUEUED_CALL_MAX_ARGS 11
23+
typedef struct em_queued_call
24+
{
25+
int functionEnum;
26+
void *functionPtr;
27+
_Atomic uint32_t operationDone;
28+
em_variant_val args[EM_QUEUED_JS_CALL_MAX_ARGS];
29+
em_variant_val returnValue;
30+
31+
// An optional pointer to a secondary data block that should be free()d when
32+
// this queued call is freed.
33+
void *satelliteData;
34+
35+
// If true, the caller has "detached" itself from this call object and the
36+
// Emscripten main runtime thread should free up this em_queued_call object
37+
// after it has been executed. If false, the caller is in control of the
38+
// memory.
39+
int calleeDelete;
40+
} em_queued_call;
41+
42+
typedef void (*em_func_v)(void);
43+
typedef void (*em_func_vi)(int);
44+
typedef void (*em_func_vf)(float);
45+
typedef void (*em_func_vii)(int, int);
46+
typedef void (*em_func_vif)(int, float);
47+
typedef void (*em_func_vff)(float, float);
48+
typedef void (*em_func_viii)(int, int, int);
49+
typedef void (*em_func_viif)(int, int, float);
50+
typedef void (*em_func_viff)(int, float, float);
51+
typedef void (*em_func_vfff)(float, float, float);
52+
typedef void (*em_func_viiii)(int, int, int, int);
53+
typedef void (*em_func_viifi)(int, int, float, int);
54+
typedef void (*em_func_vifff)(int, float, float, float);
55+
typedef void (*em_func_vffff)(float, float, float, float);
56+
typedef void (*em_func_viiiii)(int, int, int, int, int);
57+
typedef void (*em_func_viffff)(int, float, float, float, float);
58+
typedef void (*em_func_viiiiii)(int, int, int, int, int, int);
59+
typedef void (*em_func_viiiiiii)(int, int, int, int, int, int, int);
60+
typedef void (*em_func_viiiiiiii)(int, int, int, int, int, int, int, int);
61+
typedef void (*em_func_viiiiiiiii)(int, int, int, int, int, int, int, int, int);
62+
typedef void (*em_func_viiiiiiiiii)(int, int, int, int, int, int, int, int, int, int);
63+
typedef void (*em_func_viiiiiiiiiii)(int, int, int, int, int, int, int, int, int, int, int);
64+
typedef int (*em_func_i)(void);
65+
typedef int (*em_func_ii)(int);
66+
typedef int (*em_func_iii)(int, int);
67+
typedef int (*em_func_iiii)(int, int, int);
68+
typedef int (*em_func_iiiii)(int, int, int, int);
69+
typedef int (*em_func_iiiiii)(int, int, int, int, int);
70+
typedef int (*em_func_iiiiiii)(int, int, int, int, int, int);
71+
typedef int (*em_func_iiiiiiii)(int, int, int, int, int, int, int);
72+
typedef int (*em_func_iiiiiiiii)(int, int, int, int, int, int, int, int);
73+
typedef int (*em_func_iiiiiiiiii)(int, int, int, int, int, int, int, int, int);

tests/reference_struct_info.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
"EM_PROXIED_JS_FUNCTION": -2126512128,
187187
"EM_PROXIED_PTHREAD_CREATE": 687865856,
188188
"EM_PROXIED_RESIZE_OFFSCREENCANVAS": 657457152,
189-
"EM_QUEUED_CALL_MAX_ARGS": 11,
190189
"EM_QUEUED_JS_CALL_MAX_ARGS": 20,
191190
"EM_THREAD_NAME_MAX": 32,
192191
"EM_THREAD_STATUS_FINISHED": 6,

0 commit comments

Comments
 (0)