Tryag File Manager
Home
-
Turbo Force
Current Path :
/
usr
/
lib
/
python2.4
/
Upload File :
New :
File
Dir
//usr/lib/python2.4/mutex.pyo
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/lib/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