File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 24
24
#include " swift/Basic/Malloc.h"
25
25
#include " swift/Basic/type_traits.h"
26
26
27
+ #if defined(__wasi__)
28
+ // Temporary single-threaded stub. Should be replaced with a thread-safe version
29
+ // as soon as the WASI SDK allows it. See https://bugs.swift.org/browse/SR-12766.
30
+ inline void wasi_call_once (int *flag, void *context, void (*func)(void *)) {
31
+ switch (*flag) {
32
+ case 0 :
33
+ *flag = 1 ;
34
+ func (context);
35
+ return ;
36
+ case 1 :
37
+ return ;
38
+ default :
39
+ assert (false && " wasi_call_once got invalid flag" );
40
+ abort ();
41
+ }
42
+ }
43
+ #endif
44
+
27
45
namespace swift {
28
46
29
47
#ifdef __APPLE__
@@ -38,6 +56,10 @@ namespace swift {
38
56
using OnceToken_t = unsigned long ;
39
57
# define SWIFT_ONCE_F (TOKEN, FUNC, CONTEXT ) \
40
58
_swift_once_f (&TOKEN, CONTEXT, FUNC)
59
+ #elif defined(__wasi__)
60
+ using OnceToken_t = int ;
61
+ # define SWIFT_ONCE_F (TOKEN, FUNC, CONTEXT ) \
62
+ ::wasi_call_once (&TOKEN, CONTEXT, FUNC)
41
63
#else
42
64
using OnceToken_t = std::once_flag;
43
65
# define SWIFT_ONCE_F (TOKEN, FUNC, CONTEXT ) \
You can’t perform that action at this time.
0 commit comments