-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistributedMonitorBase.h
More file actions
40 lines (32 loc) · 880 Bytes
/
DistributedMonitorBase.h
File metadata and controls
40 lines (32 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _DISTRIBUTEDMONITORBASE_
#define _DISTRIBUTEDMONITORBASE_
#include "Communication/ICommunicationBase.h"
#include "ICondition.h"
#include <queue>
#include <pthread.h>
#define WaitWhile(a) while(a) { this->Unlock(); this->Lock(); }
namespace DistributedMonitor {
class DistributedMonitorBase {
private:
static int NextMonitorId;
int _monitorId;
ICommunicationBase* _communicationBase;
bool _locked;
std::queue<int> _unlockPeers;
void UpdateMonitorId();
pthread_t _messageHandlingThread;
static void* MessageHandlingThread(void*);
void HandleMessages();
bool _terminateMessageHandlingThread;
void CreateMessageHandlingThread();
public:
DistributedMonitorBase(ICommunicationBase*);
protected:
virtual char* Serialize() = 0;
virtual void Deserialize(char* serializedContent) = 0;
void Lock();
void Unlock();
ICondition *_currentCondition;
};
}
#endif