Skip to content

[Syntax] Use no-op PlatformMutex implemtation for wasm32-unknown-wasi #2944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
24 changes: 23 additions & 1 deletion Sources/_SwiftSyntaxCShims/PlatformMutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
#include "PlatformMutex.h"
#include <stdlib.h>

#if defined(__wasi__) && !defined(_REENTRANT)
#define SWIFTSYNTAX_HAS_THREAD 0
#else
#define SWIFTSYNTAX_HAS_THREAD 1
#endif

#if SWIFTSYNTAX_HAS_THREAD
#if defined(__APPLE__)
#include <os/lock.h>

Expand Down Expand Up @@ -81,5 +88,20 @@ void swiftsyntax_platform_mutex_destroy(PlatformMutex m) {
}

#else
#error "platfrom mutex implementation is not available"
#error "platform mutex implementation is not available"
// Add platform specific implementation above, or set SWIFTSYNTAX_HAS_THREAD to 0.
#endif

#else // SWIFTSYNTAX_HAS_THREAD

PlatformMutex swiftsyntax_platform_mutex_create() {
PlatformMutex m;
m.opaque = 0;
return m;
}

void swiftsyntax_platform_mutex_lock(PlatformMutex m) {}
void swiftsyntax_platform_mutex_unlock(PlatformMutex m) {}
void swiftsyntax_platform_mutex_destroy(PlatformMutex m) {}

#endif // SWIFTSYNTAX_HAS_THREAD