-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankData.hpp
More file actions
101 lines (76 loc) · 1.46 KB
/
BankData.hpp
File metadata and controls
101 lines (76 loc) · 1.46 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
#include <semaphore.h>
#define down sem_wait
#define up sem_post
using namespace std;
class Account
{
private:
int id;
int password;
int balance;
public:
int rd_count;
sem_t wrt_lock;
sem_t rd_lock;
// add write lock and read lock
Account(int id_=0, int password_=0, int balance_=0, int rd_count_ =0):
id(id_), password(password_), balance(balance_), rd_count(rd_count_)
{
if ( (sem_init(&wrt_lock, 0, 1) != 0) || (sem_init(&rd_lock, 0, 1) != 0) )
{
// Error: initialization failed
//TODO any last words?
}
};
/* Getters */
int getId();
int getPassword();
int getBalance();
/* Setters */
void setId(int id_);
void setPassword(int password_);
void setBalance(int balance_);
~Account(){};
};
class BankData
{
private:
int ATMcounter;
public:
/* Constructor */
BankData();
/* Variables */
map <int , Account> Accounts;
pthread_mutex_t log_lock;
Account Self;
sem_t wrt_lock;
sem_t rd_lock;
int rd_count;
/* Getters */
int get_ATMcounter();
int getSelfBalance();
/* Setters */
void promote_ATMcounter();
void setSelfBalance(int balance);
/* Destructor */
~BankData();
};
class ATM
{
private:
public:
/* Constructor */
ATM(char *argv,int id);
/* Variables */
int Id;
string command;
/* Destructor */
~ATM(){};
};