home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / mutex.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  1.3 KB  |  42 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. from warnings import warnpy3k
  5. warnpy3k('the mutex module has been removed in Python 3.0', stacklevel = 2)
  6. del warnpy3k
  7. from collections import deque
  8.  
  9. class mutex:
  10.     
  11.     def __init__(self):
  12.         self.locked = False
  13.         self.queue = deque()
  14.  
  15.     
  16.     def test(self):
  17.         return self.locked
  18.  
  19.     
  20.     def testandset(self):
  21.         if not self.locked:
  22.             self.locked = True
  23.             return True
  24.         return None
  25.  
  26.     
  27.     def lock(self, function, argument):
  28.         if self.testandset():
  29.             function(argument)
  30.         else:
  31.             self.queue.append((function, argument))
  32.  
  33.     
  34.     def unlock(self):
  35.         if self.queue:
  36.             (function, argument) = self.queue.popleft()
  37.             function(argument)
  38.         else:
  39.             self.locked = False
  40.  
  41.  
  42.