Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F622806
lock.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
lock.h
View Options
#pragma once
#include
"threads.h"
#include
"obj/object.h"
#include
<set>
#include
<queue>
#define OBJECT_LOCK_NAGGING
struct
ObjectMessage
;
struct
LockGroup
{
int
id
;
threads
::
Mutex
mutex
;
threads
::
atomic_int
priorityLocks
;
std
::
vector
<
Object
*>
objects
;
unsigned
tickIndex
;
bool
hasLock
();
bool
hasWriteLock
();
std
::
vector
<
Object
*>
addQueue
;
threads
::
Mutex
addMutex
;
std
::
deque
<
ObjectMessage
*>
messages
;
std
::
unordered_map
<
Object
*
,
std
::
vector
<
ObjectMessage
*>*>
deferredMessages
;
threads
::
Mutex
messageLock
;
threads
::
atomic_int
badLocks
;
threads
::
atomic_int
goodLocks
;
threads
::
atomic_int
lostObjects
;
threads
::
atomic_int
gainedObjects
;
LockGroup
();
void
addMessage
(
ObjectMessage
*
message
);
void
add
(
Object
*
obj
);
bool
process
(
double
time
,
int
limit
=
1000
);
void
acquireChildren
();
void
processMessages
(
int
limit
=
100
);
};
struct
ObjectMessage
{
Object
*
object
;
ObjectMessage
(
Object
*
obj
)
:
object
(
obj
)
{}
virtual
void
process
()
=
0
;
virtual
~
ObjectMessage
()
{}
void
*
operator
new
(
size_t
bytes
);
void
operator
delete
(
void
*
p
);
};
LockGroup
*
getRandomLock
();
void
initLocks
(
unsigned
lockCount
);
void
destroyLocks
();
unsigned
getLockCount
();
LockGroup
*
getLock
(
unsigned
index
);
void
printLockStats
();
void
acquireRandomChildren
();
bool
tickRandomLock
(
double
time
,
int
limit
=
1000
);
void
tickRandomMessages
(
int
limit
=
100
);
//Attempts to process the messages in a particular group, with no guarantee of any success
void
tickLockMessages
(
LockGroup
*
lock
,
int
limit
=
8
);
//If a message can't be processed yet (the object has no lock group), it must be queued for later execution
void
queueDeferredMessage
(
ObjectMessage
*
msg
);
LockGroup
*
getActiveLockGroup
();
Object
*
getActiveObject
();
void
setActiveObject
(
Object
*
obj
);
void
queueObjectClear
(
Object
*
obj
);
void
delayObjectRelease
(
Object
*
obj
);
LockGroup
*
lockObject
(
Object
*
obj
,
bool
priority
=
false
);
void
unlockObject
(
LockGroup
*
lock
);
void
lockGroup
(
LockGroup
*
group
,
bool
priority
=
false
);
void
unlockGroup
(
LockGroup
*
lock
);
bool
hasQueuedChildren
();
bool
hasRemainingMessages
();
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 14, 8:33 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
129941
Default Alt Text
lock.h (2 KB)
Attached To
Mode
R80 StarRuler2-Source
Attached
Detach File
Event Timeline