|
| 1 | +//===--- MutexWASI.h - -----------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// No-op implementation of locks for the WebAssembly System Interface. The |
| 14 | +// implementation does not need to perform locking, because as of January 2020 |
| 15 | +// WebAssembly does not support threads. |
| 16 | +// See the current status at https://github.com/WebAssembly/proposals and |
| 17 | +// https://github.com/webassembly/threads |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | + |
| 21 | +#ifndef SWIFT_RUNTIME_MUTEX_WASI_H |
| 22 | +#define SWIFT_RUNTIME_MUTEX_WASI_H |
| 23 | + |
| 24 | +namespace swift { |
| 25 | + |
| 26 | +typedef void* ConditionHandle; |
| 27 | +typedef void* MutexHandle; |
| 28 | +typedef void* ReadWriteLockHandle; |
| 29 | + |
| 30 | +#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 1 |
| 31 | +#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 1 |
| 32 | +#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 1 |
| 33 | + |
| 34 | +struct ConditionPlatformHelper { |
| 35 | + static constexpr ConditionHandle staticInit() { |
| 36 | + return nullptr; |
| 37 | + }; |
| 38 | + static void init(ConditionHandle &condition) {} |
| 39 | + static void destroy(ConditionHandle &condition) {} |
| 40 | + static void notifyOne(ConditionHandle &condition) {} |
| 41 | + static void notifyAll(ConditionHandle &condition) {} |
| 42 | + static void wait(ConditionHandle &condition, MutexHandle &mutex); |
| 43 | +}; |
| 44 | + |
| 45 | +struct MutexPlatformHelper { |
| 46 | + static constexpr MutexHandle staticInit() { return nullptr; } |
| 47 | + static void init(MutexHandle &mutex, bool checked = false) {} |
| 48 | + static void destroy(MutexHandle &mutex) {} |
| 49 | + static void lock(MutexHandle &mutex) {} |
| 50 | + static void unlock(MutexHandle &mutex) {} |
| 51 | + static bool try_lock(MutexHandle &mutex) { return true; } |
| 52 | + static void unsafeLock(MutexHandle &mutex) {} |
| 53 | + static void unsafeUnlock(MutexHandle &mutex) {} |
| 54 | +}; |
| 55 | + |
| 56 | +struct ReadWriteLockPlatformHelper { |
| 57 | + static constexpr ReadWriteLockHandle staticInit() { return nullptr; } |
| 58 | + static void init(ReadWriteLockHandle &rwlock) {} |
| 59 | + static void destroy(ReadWriteLockHandle &rwlock) {} |
| 60 | + static void readLock(ReadWriteLockHandle &rwlock) {} |
| 61 | + static bool try_readLock(ReadWriteLockHandle &rwlock) { return true; } |
| 62 | + static void readUnlock(ReadWriteLockHandle &rwlock) {} |
| 63 | + static void writeLock(ReadWriteLockHandle &rwlock) {} |
| 64 | + static bool try_writeLock(ReadWriteLockHandle &rwlock) { return true; } |
| 65 | + static void writeUnlock(ReadWriteLockHandle &rwlock) {} |
| 66 | +}; |
| 67 | +} |
| 68 | + |
| 69 | +#endif |
0 commit comments