Skip to content

Commit f679ae9

Browse files
committed
[Syntax] Use no-op PlatformMutex implemtation for wasm32-unknown-wasi
Can be detected with `defined(__wasi__) && !defined(_REENTRANT)`
1 parent fd232f9 commit f679ae9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sources/_SwiftSyntaxCShims/PlatformMutex.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include "PlatformMutex.h"
1414
#include <stdlib.h>
1515

16+
#if defined(__wasi__) && !defined(_REENTRANT)
17+
#define SWIFTSYNTAX_HAS_THREAD 0
18+
#else
19+
#define SWIFTSYNTAX_HAS_THREAD 1
20+
#endif
21+
22+
#if SWIFTSYNTAX_HAS_THREAD
1623
#if defined(__APPLE__)
1724
#include <os/lock.h>
1825

@@ -81,5 +88,20 @@ void swiftsyntax_platform_mutex_destroy(PlatformMutex m) {
8188
}
8289

8390
#else
84-
#error "platfrom mutex implementation is not available"
91+
#error "platform mutex implementation is not available"
92+
// Add platform specific implementation above, or set SWIFTSYNTAX_HAS_THREAD to 0.
8593
#endif
94+
95+
#else // SWIFTSYNTAX_HAS_THREAD
96+
97+
PlatformMutex swiftsyntax_platform_mutex_create() {
98+
PlatformMutex m;
99+
m.opaque = 0;
100+
return m;
101+
}
102+
103+
void swiftsyntax_platform_mutex_lock(PlatformMutex m) {}
104+
void swiftsyntax_platform_mutex_unlock(PlatformMutex m) {}
105+
void swiftsyntax_platform_mutex_destroy(PlatformMutex m) {}
106+
107+
#endif // SWIFTSYNTAX_HAS_THREAD

0 commit comments

Comments
 (0)