@@ -69,17 +69,16 @@ def empty(self):
6969 put = deque .append
7070
7171
72- class HSCondition (object ):
72+ class HSCondition (deque ):
7373 """Cleaned up code of the original condition object in order
7474 to make it run and respond faster."""
75- __slots__ = ("_lock" , '_waiters' )
75+ __slots__ = ("_lock" )
7676 delay = 0.0002 # reduces wait times, but increases overhead
7777
7878 def __init__ (self , lock = None ):
7979 if lock is None :
8080 lock = Lock ()
8181 self ._lock = lock
82- self ._waiters = deque ()
8382
8483 def release (self ):
8584 self ._lock .release ()
@@ -93,7 +92,7 @@ def acquire(self, block=None):
9392 def wait (self , timeout = None ):
9493 waiter = _allocate_lock ()
9594 waiter .acquire () # get it the first time, no blocking
96- self ._waiters . append (waiter )
95+ self .append (waiter )
9796
9897 # in the momemnt we release our lock, someone else might actually resume
9998 self .release ()
@@ -124,7 +123,7 @@ def wait(self, timeout=None):
124123 # END endless loop
125124 if not gotit :
126125 try :
127- self ._waiters . remove (waiter )
126+ self .remove (waiter )
128127 except ValueError :
129128 pass
130129 # END didn't ever get it
@@ -140,13 +139,13 @@ def notify(self, n=1):
140139 In the multi-notify case, we acquire a lock just for safety, as otherwise
141140 we might pop too much of someone else notifies n waiters as well, which
142141 would in the worst case lead to double-releases of locks."""
143- if not self . _waiters :
142+ if not self :
144143 return
145144 if n == 1 :
146145 # so here we assume this is thead-safe ! It wouldn't be in any other
147146 # language, but python it is.
148147 try :
149- self ._waiters . popleft ().release ()
148+ self .popleft ().release ()
150149 except IndexError :
151150 pass
152151 else :
@@ -155,16 +154,16 @@ def notify(self, n=1):
155154 # and waits again, but only until we are done, which is important
156155 # to do that in a thread-safe fashion
157156 try :
158- for i in range (min (n , len (self . _waiters ))):
159- self ._waiters . popleft ().release ()
157+ for i in range (min (n , len (self ))):
158+ self .popleft ().release ()
160159 # END for each waiter to resume
161160 finally :
162161 self .release ()
163162 # END assure we release our lock
164163 # END handle n = 1 case faster
165164
166165 def notify_all (self ):
167- self .notify (len (self . _waiters ))
166+ self .notify (len (self ))
168167
169168
170169class ReadOnly (Exception ):
0 commit comments