-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphSharedMutex.hpp
53 lines (39 loc) · 1.13 KB
/
GraphSharedMutex.hpp
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
//
// Created by naraujo on 20/08/17.
//
#ifndef GRAPHEVALUATION_GRAPHSHAREDMUTEX_HPP
#define GRAPHEVALUATION_GRAPHSHAREDMUTEX_HPP
#include "Graph.hpp"
#include <thread>
#include <mutex>
#include <shared_mutex>
struct shared_mutex_wrapper : std::shared_timed_mutex
{
shared_mutex_wrapper() = default;
shared_mutex_wrapper(shared_mutex_wrapper const&) noexcept : std::shared_timed_mutex() {}
bool operator==(shared_mutex_wrapper const&other) noexcept { return this==&other; }
};
class GraphSharedMutex : public Graph{
private:
//Normal
std::vector<shared_mutex_wrapper> nodesMutex;
//Insertion
std::shared_timed_mutex structureMutex;
public:
//Constutor
GraphSharedMutex();
//Insert Methods
bool insertNode();
bool insertEdge(int n1, int n2);
//Delete Methods
bool deleteNode(int n);
bool deleteEdge(int n1, int n2);
//Costs Methods
bool increaseEdge(int n1, int n2);
bool decreaseEdge(int n1, int n2);
//Acess Methods
bool getNode(int n, int& out);
bool getEdge(int n1, int n2, int& out);
void printEdges();
};
#endif //GRAPHEVALUATION_GRAPHSHAREDMUTEX_HPP