Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
All Data Structures Namespaces Files Functions Variables
mutex Class Reference

Public Member Functions

def __init__
 
def test
 
def testandset
 
def lock
 
def unlock
 

Data Fields

 locked
 
 queue
 

Detailed Description

Definition at line 15 of file mutex.py.

Constructor & Destructor Documentation

def __init__ (   self)
Create a new mutex -- initially unlocked.

Definition at line 16 of file mutex.py.

16 
17  def __init__(self):
18  """Create a new mutex -- initially unlocked."""
19  self.locked = 0
20  self.queue = []

Member Function Documentation

def lock (   self,
  function,
  argument 
)
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.

Definition at line 34 of file mutex.py.

References mutex.testandset().

34 
35  def lock(self, function, argument):
36  """Lock a mutex, call the function with supplied argument
37  when it is acquired. If the mutex is already locked, place
38  function and argument in the queue."""
39  if self.testandset():
40  function(argument)
41  else:
42  self.queue.append((function, argument))
def test (   self)
Test the locked bit of the mutex.

Definition at line 21 of file mutex.py.

References mutex.locked.

21 
22  def test(self):
23  """Test the locked bit of the mutex."""
24  return self.locked
def testandset (   self)
Atomic test-and-set -- grab the lock if it is not set,
return true if it succeeded.

Definition at line 25 of file mutex.py.

References mutex.locked.

25 
26  def testandset(self):
27  """Atomic test-and-set -- grab the lock if it is not set,
28  return true if it succeeded."""
29  if not self.locked:
30  self.locked = 1
31  return 1
32  else:
33  return 0
def unlock (   self)
Unlock a mutex.  If the queue is not empty, call the next
function with its argument.

Definition at line 43 of file mutex.py.

References mutex.locked, and mutex.queue.

43 
44  def unlock(self):
45  """Unlock a mutex. If the queue is not empty, call the next
46  function with its argument."""
47  if self.queue:
48  function, argument = self.queue[0]
49  del self.queue[0]
50  function(argument)
51  else:
52  self.locked = 0

Field Documentation

locked

Definition at line 18 of file mutex.py.

queue

Definition at line 19 of file mutex.py.


The documentation for this class was generated from the following file: