|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /proc/21573/task/21573/root/proc/21572/root/usr/lib64/python2.4/ |
Upload File : |
mò
‚=5Dc @ s* d Z d k l Z d f d „ ƒ YZ d S( sJ Mutual exclusion -- for use with module sched
A mutex has two pieces of state -- a 'locked' bit and a queue.
When the mutex is not locked, the queue is empty.
Otherwise, the queue contains 0 or more (function, argument) pairs
representing functions (or methods) waiting to acquire the lock.
When the mutex is unlocked while the queue is not empty,
the first queue entry is removed and its function(argument) pair called,
implying it now has the lock.
Of course, no multi-threading is implied -- hence the funny interface
for lock, where a function is called once the lock is aquired.
( s dequet mutexc B s5 t Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( Nc C s d | _ t ƒ | _ d S( s) Create a new mutex -- initially unlocked.i N( t selft lockedt dequet queue( R ( ( t /usr/lib64/python2.4/mutex.pyt __init__ s c C s | i S( s! Test the locked bit of the mutex.N( R R ( R ( ( R t test s c C s# | i p d | _ t Sn t Sd S( s[ Atomic test-and-set -- grab the lock if it is not set,
return True if it succeeded.i N( R R t Truet False( R ( ( R t
testandset s
c C s5 | i ƒ o | | ƒ n | i i | | f ƒ d S( s¦ Lock a mutex, call the function with supplied argument
when it is acquired. If the mutex is already locked, place
function and argument in the queue.N( R R
t functiont argumentR t append( R R R ( ( R t lock$ s
c C s: | i o# | i i ƒ \ } } | | ƒ n
d | _ d S( s] Unlock a mutex. If the queue is not empty, call the next
function with its argument.i N( R R t popleftR R R ( R R R ( ( R t unlock- s
( t __name__t
__module__R R R
R R ( ( ( R R s
N( t __doc__t collectionsR R ( R R ( ( R t ?
s