Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
SemaphoreManager Class Reference#include <SemaphoreManager.h>
Detailed Descriptioninitializes, manages, and releases a set of System V style semaphoresShould be initialized pre-fork into a shared region Definition at line 21 of file SemaphoreManager.h.
Member Typedef Documentation
Member Enumeration Documentationspecify options for how to handle EINTR (signal occurred) error condition during a semaphore operation, see setInterruptPolicy()
Definition at line 32 of file SemaphoreManager.h.
Constructor & Destructor Documentation
Creates a SemaphoreManager with room for sems_t::MAX_ENTRIES entries. 2 of these entries are reserved for internal use, so user code will actually only have access to sems_t::MAX_ENTRIES-2 entries. Use available() to determine this value at runtime. Definition at line 30 of file SemaphoreManager.cc.
Creates a SemaphoreManager with room for numRequest entries. adds 2 for SemaphoreManager's own reference count and mutex lock, so you'll actually have numRequest semaphores available Definition at line 34 of file SemaphoreManager.cc.
Member Function Documentation
call this on semaphores in shared memory regions if a fork is about to occur so reference counts can be updated for the other process
Definition at line 214 of file SemaphoreManager.cc. Referenced by MutexLockBase::aboutToFork().
call this if semaphores need to be released during an emergency shutdown (otherwise semaphore sets can leak past process shutdown -- bad system design IMHO!)
Definition at line 218 of file SemaphoreManager.cc.
returns true if semid is invalid, indicating further semaphore operations are bogus
Definition at line 62 of file SemaphoreManager.h. Referenced by MutexLock< MAX_ACCESS >::get_lock_level(), MutexLock< MAX_ACCESS >::lock(), MutexLock< MAX_ACCESS >::releaseAll(), MutexLock< MAX_ACCESS >::try_lock(), MutexLock< MAX_ACCESS >::unlock(), and MutexLock< MAX_ACCESS >::~MutexLock().
returns a new semaphore id, or invalid() if none are available
Definition at line 224 of file SemaphoreManager.cc. Referenced by MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReceiver(), and WorldStatePool::WorldStatePool().
marks a semaphore as available for reassignment
Definition at line 233 of file SemaphoreManager.cc. Referenced by MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReceiver(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), and MutexLock< MAX_ACCESS >::~MutexLock().
return the semaphore's interrupt policy (doesn't check id validity)
Definition at line 70 of file SemaphoreManager.h.
set the semaphore's interrupt policy (doesn't check id validity)
Definition at line 72 of file SemaphoreManager.h.
lowers a semaphore's value by x, optionally blocking if the value would go negative until it is raised enough to succeed returns true if the semaphore was successfully lowered. Definition at line 239 of file SemaphoreManager.cc. Referenced by getSemaphore(), operator=(), MessageQueueStatusThread::run(), MessageReceiver::runloop(), SemaphoreManager(), MutexLock< MAX_ACCESS >::unlock(), MessageReceiver::waitNextMessage(), and ~SemaphoreManager().
raises a semaphore's value by x
Definition at line 282 of file SemaphoreManager.cc. Referenced by MutexLock< MAX_ACCESS >::lock(), MessageReceiver::markRead(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::markRead(), operator=(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::readMessage(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::removeReceiver(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::sendMessage(), MessageReceiver::stop(), MessageQueueStatusThread::stop(), and MutexLock< MAX_ACCESS >::try_lock().
returns the semaphore's value
Definition at line 288 of file SemaphoreManager.cc. Referenced by MutexLock< MAX_ACCESS >::get_lock_level(), MessageQueueStatusThread::run(), and MutexLock< MAX_ACCESS >::unlock().
sets the semaphore's value
Definition at line 294 of file SemaphoreManager.cc. Referenced by WorldStatePool::doneWritingState(), WorldStatePool::getCurrentWriteState(), getSemaphore(), init(), MutexLock< MAX_ACCESS >::MutexLock(), MutexLock< MAX_ACCESS >::releaseAll(), and WorldStatePool::WorldStatePool().
tests if the semaphore's value is zero, optionally blocking until it is returns true if the semaphore's value is zero.
Definition at line 302 of file SemaphoreManager.cc. Referenced by WorldStatePool::getCurrentReadState(), and WorldStatePool::isComplete().
tests if the semaphore's value is zero, optionally blocking until it is, and then adding x If x is negative, then addblock will cause it to block again until someone else raises the semaphore. Otherwise, the add should be performed as an atomic unit with the test. If x is non-negative, then the add should never block.
Definition at line 346 of file SemaphoreManager.cc. Referenced by MutexLock< MAX_ACCESS >::lock(), and MutexLock< MAX_ACCESS >::try_lock().
adds x to the semaphore's value, optionally blocking in the case that x is negative and larger than the semaphore's value. After adding, test whether the semaphore is zero, optionally blocking again until it is. If no blocking is required (e.g. x is positive) then the add and test should be an atomic pair.
Definition at line 394 of file SemaphoreManager.cc.
returns the number of semaphores currently available in the set
Definition at line 101 of file SemaphoreManager.h.
returns the number of semaphores which have been used the SemaphoreManager requires 2 semaphores from the set, one for reference counting and one for mutual exclusion during function calls Definition at line 106 of file SemaphoreManager.h.
returns the "invalid" id value, for testing against getSemaphore
Definition at line 108 of file SemaphoreManager.h. Referenced by MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReadStatusListener(), MessageQueue< MAX_UNREAD, MAX_RECEIVERS, MAX_SENDERS >::addReceiver(), MessageQueueStatusThread::addStatusListener(), MessageQueueStatusThread::cancelled(), MessageReceiver::finish(), MessageReceiver::launched(), MessageReceiver::MessageReceiver(), MutexLock< MAX_ACCESS >::MutexLock(), MessageQueueStatusThread::stop(), and MessageReceiver::~MessageReceiver().
basic initialization called by the constructor -- don't call twice
Definition at line 38 of file SemaphoreManager.cc. Referenced by SemaphoreManager().
Member Data Documentation
wouldn't want to claim the entire system's worth, even if we could
Definition at line 27 of file SemaphoreManager.h.
tracks which semaphores have been handed out; the bool value isn't actually used
Definition at line 113 of file SemaphoreManager.h. Referenced by available(), getSemaphore(), init(), invalid(), operator=(), SemaphoreManager(), and used().
number of real semaphores in the set obtained from the system
Definition at line 114 of file SemaphoreManager.h. Referenced by init(), operator=(), and used().
the system's identifier for the set
Definition at line 115 of file SemaphoreManager.h. Referenced by faultShutdown(), hadFault(), init(), lower(), operator=(), SemaphoreManager(), and ~SemaphoreManager().
a lock semaphore for management operations on the set (handing out or taking back semaphores from clients)
Definition at line 116 of file SemaphoreManager.h. Referenced by getSemaphore(), init(), operator=(), SemaphoreManager(), and ~SemaphoreManager().
a reference count of this semaphore set -- when it goes back to 0, the set is released from the system
Definition at line 117 of file SemaphoreManager.h. Referenced by aboutToFork(), init(), operator=(), SemaphoreManager(), and ~SemaphoreManager().
interrupt policy for each semaphore
Definition at line 118 of file SemaphoreManager.h. Referenced by getInterruptPolicy(), getSemaphore(), lower(), and setInterruptPolicy().
The documentation for this class was generated from the following files: |
Tekkotsu v4.0 |
Generated Thu Nov 22 00:58:41 2007 by Doxygen 1.5.4 |