mirror of
https://github.com/YosysHQ/yosys
synced 2026-02-14 12:51:48 +00:00
Add MonotonicFlag
We'll use this later in the PR.
This commit is contained in:
parent
b18ca8710e
commit
d5950a6c03
1 changed files with 16 additions and 0 deletions
|
|
@ -668,6 +668,22 @@ private:
|
|||
int num_waiters = 0;
|
||||
};
|
||||
|
||||
// A monotonic flag. Starts false, and can be set to true in a thread-safe way.
|
||||
// Once `load()` returns true, it will always return true.
|
||||
// Uses relaxed atomics so there are no memory ordering guarantees. Do not use this
|
||||
// to guard access to shared memory.
|
||||
class MonotonicFlag {
|
||||
public:
|
||||
MonotonicFlag() : value(false) {}
|
||||
bool load() const { return value.load(std::memory_order_relaxed); }
|
||||
void set() { value.store(true, std::memory_order_relaxed); }
|
||||
bool set_and_return_old() {
|
||||
return value.exchange(true, std::memory_order_relaxed);
|
||||
}
|
||||
private:
|
||||
std::atomic<bool> value;
|
||||
};
|
||||
|
||||
YOSYS_NAMESPACE_END
|
||||
|
||||
#endif // YOSYS_THREADING_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue