network_condition_variable.h
1
2#pragma once
3
4#include <memory>
5#include <vector>
6#include <mutex>
7
8namespace clan
9{
10 class SocketHandle;
11 class NetworkConditionVariableImpl;
12
15 {
16 protected:
17 virtual SocketHandle *get_socket_handle() = 0;
18
20 };
21
24 {
25 public:
27
29 template<typename Lock>
30 bool wait(Lock &lock, int count, NetworkEvent **events, int timeout = -1)
31 {
32 lock.unlock();
33 try
34 {
35 bool result = wait_impl(count, events, timeout);
36 lock.lock();
37 return result;
38 }
39 catch (...)
40 {
41 lock.lock();
42 throw;
43 }
44 }
45
47 void notify();
48
49 private:
50 bool wait_impl(int count, NetworkEvent **events, int timeout);
51
52 std::shared_ptr<NetworkConditionVariableImpl> impl;
53 };
54}
Condition variable that also awaken on network events.
Definition network_condition_variable.h:24
void notify()
Awakens any thread waiting for event changes.
bool wait(Lock &lock, int count, NetworkEvent **events, int timeout=-1)
Waits for event changes or until notify is called.
Definition network_condition_variable.h:30
Base class for all classes that generate network events.
Definition network_condition_variable.h:15
virtual SocketHandle * get_socket_handle()=0
Definition clanapp.h:36