mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
add wait-if for waiter
This commit is contained in:
parent
f7f06ab052
commit
52302cc007
@ -10,7 +10,7 @@ public:
|
||||
explicit waiter(char const * name);
|
||||
waiter(waiter&& rhs);
|
||||
|
||||
~waiter();
|
||||
virtual ~waiter();
|
||||
|
||||
void swap(waiter& rhs);
|
||||
waiter& operator=(waiter rhs);
|
||||
@ -22,9 +22,14 @@ public:
|
||||
void close();
|
||||
|
||||
bool wait();
|
||||
bool wait_if_pred();
|
||||
|
||||
bool notify();
|
||||
bool broadcast();
|
||||
|
||||
protected:
|
||||
virtual bool pred();
|
||||
|
||||
private:
|
||||
class waiter_;
|
||||
waiter_* p_;
|
||||
|
||||
@ -199,7 +199,9 @@ public:
|
||||
|
||||
void broadcast(handle_t h) {
|
||||
if (h == invalid()) return;
|
||||
sem_.post([this] { return counter_.load(std::memory_order_relaxed); });
|
||||
sem_.post([this] {
|
||||
return counter_.load(std::memory_order_relaxed);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -67,6 +67,14 @@ bool waiter::wait() {
|
||||
return impl(p_)->w_.wait_if([] { return true; });
|
||||
}
|
||||
|
||||
bool waiter::pred() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool waiter::wait_if_pred() {
|
||||
return impl(p_)->w_.wait_if([this] { return pred(); });
|
||||
}
|
||||
|
||||
bool waiter::notify() {
|
||||
return impl(p_)->w_.notify();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user