diff options
Diffstat (limited to 'src/support/threads.h')
-rw-r--r-- | src/support/threads.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/support/threads.h b/src/support/threads.h index ea9e53c13..45c09e602 100644 --- a/src/support/threads.h +++ b/src/support/threads.h @@ -105,6 +105,24 @@ private: bool areThreadsReady(); }; +// Verify a code segment is only entered once. Usage: +// static OnlyOnce onlyOnce; +// onlyOnce.verify(); + +class OnlyOnce { + std::atomic<int> created; + +public: + OnlyOnce() { + created.store(0); + } + + void verify() { + auto before = created.fetch_add(1); + assert(before == 0); + } +}; + } // namespace wasm #endif // wasm_support_threads_h |