COAR
1.0
COAR - DMS system
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
locktable.h
Go to the documentation of this file.
1
#ifndef LOCKTABLE_H
2
#define LOCKTABLE_H
3
4
#include <string>
5
#include "
coartypes.h
"
6
7
#define POSIX_SEM
8
#undef SYSV_SEM
9
10
#define NUM_ENTITIES 1000
11
#define LOCK_WAIT_TIME_UNRESTRICTED 0
12
#define LOCK_WAIT_TIME_NOWAIT 2
13
#define LOCK_WAIT_TIME_60S 1
14
15
typedef
struct
16
{
17
entity_id_t
id
;
18
pid_t
pid
;
19
}
lockEntry
;
20
21
22
// Riziko pri locktable je v tom ze aj po uvolneni zostavaju semafory a shared memory v systeme co moze sposobit ze casom bude ich
23
// nedostatok. Mozno bude treba riesit synchronizaciu inak napr. pomocou mutexov z pthread
24
25
27
#ifdef DEBUG
28
class
DLL_PUBLIC
locktable
29
#else
30
class
locktable
31
#endif
32
{
33
34
public
:
35
38
55
locktable
(
coar
* _coarInstance,
std::string
fName,
const
char
key,
int
numEntities=
NUM_ENTITIES
);
56
59
~
locktable
();
60
63
78
int
lockEntity(
entity_id_t
id
);
79
82
97
int
unlockEntity(
entity_id_t
id
,
bool
wait=
false
);
98
99
102
118
void
setLockWaitTime(
int
value);
119
122
128
int
getLockWaitTime();
129
130
133
bool
haveLock(
entity_id_t
id
);
134
135
136
void
dumpLocktable();
137
138
private
:
139
140
int
openSHM();
141
int
openSemaphore();
142
143
144
147
159
int
writeEntityLockToSHM(
entity_id_t
id
,
bool
clear=
false
);
160
161
164
169
int
lockSHM();
170
int
unlockSHM();
171
int
_lockEntity(
entity_id_t
id
);
172
int
_unlockEntity(
entity_id_t
id
);
175
bool
isEntityLocked(
entity_id_t
id
);
176
int
clearEntityLockIfNotOwned(
entity_id_t
id
);
177
178
179
#ifdef SYSV_SEM
180
int
key;
181
int
semSetHandle;
182
#endif
183
#ifdef POSIX_SEM
184
sem_t* mutex;
185
#endif
186
187
std::string
name
;
188
std::string
semName;
189
int
numEntities;
190
key_t k;
191
int
shmHandle;
192
void
* shmPtr;
193
int
waitTime;
194
int
haveSHMLock;
195
entity_id_t
lockedEntityID;
196
coar
* coarInstance;
197
198
199
char
filler[100];
200
201
202
};
203
204
#endif // LOCKTABLE_H
coarlib
locktable.h
Generated on Fri Sep 25 2015 14:53:56 for COAR by
1.8.1.1