-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock_manager.h
146 lines (117 loc) · 2.91 KB
/
lock_manager.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef LOCK_MANAGER_H
#define LOCK_MANAGER_H
#define MAX_NAMESPACE_ID 32
/**
* @file
* @brief Lock Manager structures, macros and defines
**/
/**
*@brief Doubly Linked List definition
**/
typedef struct list_head{
/*
* pointer to the next entry in the list
*/
struct list_head *next;
/*
* pointer to the previous entry in the list
*/
struct list_head *prev;
}list_head_t;
/*
* @brief AVL tree node structure
*
*/
typedef struct tree_node_s{
union{
/**
* @brief List header for added nodes to the free list.
*/
list_head_t list;
/**
* @brief List header for pending locks
*/
list_head_t pendingList;
};
/**
* @brief Pointer to this nodes parent node
*/
struct tree_node_s *parent;
/**
* @brief Pointer to this node's children
*/
struct tree_node_s *child[2];
/*
* @brief start LBA
*/
unsigned int start_lba;
/*
* @brief end LBA
*/
unsigned int end_lba;
/*
*@brief the height of this node
*/
signed char height;
/*
* @brief ID of eventIndex
*/
unsigned int eventIndex;
/*
* @brief Lock type, set to 1 if this is a write lock
*/
unsigned char type;
}tree_node_t;
/**
* @brief Return the larger of two signed values
*
* @param[in] a Value to compare
* @param[in] b Value to compare
*
* @reval The greater of a or b
**/
#define MAX(a, b) ((a) >= (b) ? (a): (b))
/**
* @brief: Extra the height from the specified tree node
*
* @param[in] p Pointer to the tree node
*
* @reval -1 The node pointer is NULL
* @reval >=0 The height of the specified node
**/
#define height(p) ((p) != NULL ? (p)->height: -1)
/**
* @brief Maximum number of supported tree nodes
*
**/
#define MAX_NODES 150
/**
* @brief Array element index of the left child.
*/
#define LEFT 0
/**
* @brief Array element index of the right child.
*/
#define RIGHT 1
/**
* @brief definitions for return value of insertion
*
**/
enum NODE_INSERT_RESULT{
NODE_ADDED, //0 -- @brief The node was added to the tree successfully.
NODE_COLLISION, //1 -- @brief The node was not added to the tree due to a collision and the queue bit not being set.
NODE_QUEUED, //2 --@brief The node was queued beind an existing node.
NODE_FAILED //3 -- @brief The node was faied to insert
};
extern tree_node_t nodes[MAX_NODES];
extern list_head_t freeNodes;
void treeInit(void);
tree_node_t *allocNodes();
void freeNode(tree_node_t *node);
tree_node_t *rotateNode(tree_node_t **treeRoot, tree_node_t *subTreeRoot, int direction);
tree_node_t *rotateDouble(tree_node_t **treeRoot, tree_node_t *subTreeRoot, int direction);
void rebalance(tree_node_t **root, tree_node_t *newNode);
extern enum NODE_INSERT_RESULT insertNode(tree_node_t **root, tree_node_t *newNode, unsigned int canQueue);
void removeNode(tree_node_t **root, tree_node_t *node);
void obtainEventInexMarker(tree_node_t *root);
#endif//lock_manager.h