-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadGame.py
47 lines (39 loc) · 1.16 KB
/
ThreadGame.py
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
import threading
import time
_ThreadGameLocker=threading.Lock()
_isThreadGameLockerAcquired=False
class ThreadGame(object):
def __init__(self):
self.__lastOperationTime=time.time()
#
def threadGameAcquire(self):
global _ThreadGameLocker
global _isThreadGameLockerAcquired
_ThreadGameLocker.acquire()
_isThreadGameLockerAcquired=True
#
def threadGameRelease(self):
global _ThreadGameLocker
global _isThreadGameLockerAcquired
if _isThreadGameLockerAcquired:
_ThreadGameLocker.release()
_isThreadGameLockerAcquired=False
#
def threadGameIsAcquired(self):
global _ThreadGameLocker
global _isThreadGameLockerAcquired
return _isThreadGameLockerAcquired
#
def threadGameTryToAcquire(self):
global _ThreadGameLocker
global _isThreadGameLockerAcquired
if _isThreadGameLockerAcquired:
return False
else:
self.threadGameAcquire()
return True
#
def updateOperationTime(self):
self.threadGameAcquire()
self.__lastOperationTime=time.time()
self.threadGameRelease()