Top Up Prev Next Bottom Contents Index Search

2.3 Class GateKeeper

The GateKeeper class provides a means of registering a number of PtGate pointers in a list, together with a way of creating or deleting a series of PtGate objects all at once. The motivation for this is that most Ptolemy applications do not use multithreading, and we do not wish to pay the overhead of locking and unlocking where it is not needed. We also want to have the ability to create a number of fine-grain locks all at once. GateKeeper objects should be declared only at file scope (never as automatic variables or on the heap). The constructor takes the form

GateKeeper(PtGate *& gateToKeep); 
The argument is a reference to a pointer to a GateKeeper, and the function of the constructor is to add this reference to a master list. It will later be possible to "enable" the pointer, by setting it to point to a newly created PtGate of the appropriate type, or "disable" it, by deleting the PtGate object and setting the pointer to null. The GateKeeper destructor deletes the reference from the master list and also deletes any PtGate object that may be pointed to by the PtGate pointer. The public method

int enabled() const; 
returns 1 if the GateKeeper's PtGate pointer is enabled (points to a PtGate) and 0 otherwise (the pointer is null). There are two public static functions:

static void enableAll(const PtGate& master); 
This function creates a PtGate object for each GateKeeper on the list, by calling makeNew() on the master object.

static void disableAll(); 
This function destroys all the PtGate objects and sets the pointers to be null. This function must never be called from within a block controlled by a CriticalSection, or while multithreading operation is in progress. A GateKeeper may be used as the argument to a CriticalSection constructor call; the effect is the same as if the PtGate pointer were passed to the constructor directly.

Top Up Prev Next Bottom Contents Index Search
Copyright © 1990-1997, University of California. All rights reserved.