-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaekawaAlgorithm.h
More file actions
78 lines (68 loc) · 1.87 KB
/
MaekawaAlgorithm.h
File metadata and controls
78 lines (68 loc) · 1.87 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// MaekawaAlgorithm.h
// AOSProject
//
// Created by Antony on 11/10/13.
// Copyright (c) 2013 Antony. All rights reserved.
//
#ifndef __AOSProject__MaekawaAlgorithm__
#define __AOSProject__MaekawaAlgorithm__
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include "MessageFormat.h"
#include "communication.h"
#include "LexiQueue.h"
#include <pthread.h>
class MaekawaAlgorithm
{
protected:
long sequenceNo;
int ** quorum;
int quorumsize;
int NoOfnodes;
int NodesTotalNumber;
bool hasFailed;
bool hasCompletedCriticalSection;
bool hasSentLockedMessage;
bool hasSentLockedMessagetoItself;
bool hasReceivedFailedMessage;
int hasSentRequestMessage;
int lockedBy;
int hasReceivedLockedMessage;
vector< vector<int> > quorumVote;
// int hasLockedFor[16];
vector< vector<int> > hasLockedFor;
vector<int> relinquishList;
LexiQueue *queue;
pthread_mutex_t sharedLock;
public:
int processID;
communication com;
char CS_FILENAME[25];
int flagforCS;
static MaekawaAlgorithm* getInstance();
void receiveMessage(Packet msg);
void receiveMakeRequest(Packet makeRequest);
void initialization();
bool setProcessID(int pid);
bool getQuorumTable(int **quorumtable,int qsize,int nnodes);
bool requestCriticalSection();
bool receiveRequest(Packet request);
bool receiveInquire(Packet inquire);
bool receiveFailed(Packet failed);
bool receiveRelease(Packet release);
bool receiveRelinquish(Packet relinquish);
bool receiveLocked(Packet locked);
void enterCriticalSection();
bool sendRelease();
//bool sendRequest(Packet req);
private:
MaekawaAlgorithm(){};
MaekawaAlgorithm(MaekawaAlgorithm const& copy){};
//MaekawaAlgorithm& operator=(MaekawaAlgorithm const& copy){};
static MaekawaAlgorithm* instance;
void writeToFile(string filename,string line);
};
#endif;