home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_653 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.3 KB  |  42 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  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 = 0
  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 = 1
  23.             return True
  24.         return False
  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 = 0
  40.  
  41.  
  42.