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);
|
explicit waiter(char const * name);
|
||||||
waiter(waiter&& rhs);
|
waiter(waiter&& rhs);
|
||||||
|
|
||||||
~waiter();
|
virtual ~waiter();
|
||||||
|
|
||||||
void swap(waiter& rhs);
|
void swap(waiter& rhs);
|
||||||
waiter& operator=(waiter rhs);
|
waiter& operator=(waiter rhs);
|
||||||
@ -22,9 +22,14 @@ public:
|
|||||||
void close();
|
void close();
|
||||||
|
|
||||||
bool wait();
|
bool wait();
|
||||||
|
bool wait_if_pred();
|
||||||
|
|
||||||
bool notify();
|
bool notify();
|
||||||
bool broadcast();
|
bool broadcast();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool pred();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class waiter_;
|
class waiter_;
|
||||||
waiter_* p_;
|
waiter_* p_;
|
||||||
|
|||||||
@ -199,7 +199,9 @@ public:
|
|||||||
|
|
||||||
void broadcast(handle_t h) {
|
void broadcast(handle_t h) {
|
||||||
if (h == invalid()) return;
|
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; });
|
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() {
|
bool waiter::notify() {
|
||||||
return impl(p_)->w_.notify();
|
return impl(p_)->w_.notify();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user