File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
uasyncio.synchro/uasyncio Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ from uasyncio import core
2
+
3
+ class Lock :
4
+
5
+ def __init__ (self ):
6
+ self .locked = False
7
+ self .wlist = []
8
+
9
+ def release (self ):
10
+ assert self .locked
11
+ self .locked = False
12
+ if self .wlist :
13
+ #print(self.wlist)
14
+ coro = self .wlist .pop (0 )
15
+ core .get_event_loop ().call_soon (coro )
16
+
17
+ def acquire (self ):
18
+ # As release() is not coro, assume we just released and going to acquire again
19
+ # so, yield first to let someone else to acquire it first
20
+ yield
21
+ #print("acquire:", self.locked)
22
+ while 1 :
23
+ if not self .locked :
24
+ self .locked = True
25
+ return True
26
+ #print("putting", core.get_event_loop().cur_coro, "on waiting list")
27
+ self .wlist .append (core .get_event_loop ().cur_coro )
28
+ yield False
You can’t perform that action at this time.
0 commit comments