The Pedigree Project
0.1
|
#include <Semaphore.h>
Classes | |
class | SemaphoreEvent |
Public Types | |
enum | SemaphoreError { TimedOut, Interrupted } |
typedef Result< bool, SemaphoreError > | SemaphoreResult |
Public Member Functions | |
Semaphore (size_t nInitialValue, bool canInterrupt=true) | |
virtual | ~Semaphore () |
SemaphoreResult | acquireWithResult (size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0) |
bool | acquire (size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0) |
bool | tryAcquire (size_t n=1) |
void | release (size_t n=1) |
ssize_t | getValue () |
Private Member Functions | |
Semaphore (const Semaphore &) | |
void | operator= (const Semaphore &) |
void | removeThread (class Thread *pThread) |
Private Attributes | |
size_t | magic |
Atomic< ssize_t > | m_Counter |
Spinlock | m_BeingModified |
List< class Thread * > | m_Queue |
bool | m_bCanInterrupt |
A counting semaphore.
Definition at line 35 of file Semaphore.h.
Semaphore::Semaphore | ( | size_t | nInitialValue, |
bool | canInterrupt = true |
||
) |
Constructor
nInitialValue | The initial value of the semaphore. |
canInterrupt | If false, acquire() retries after interrupt rather than returning a failure status. |
Definition at line 70 of file Semaphore.cc.
References assert.
|
virtual |
Destructor
Definition at line 77 of file Semaphore.cc.
References assert, and List< T, nodePoolSize >::clear().
|
private |
Private copy constructor
|
inline |
Convenience wrapper for acquire().
Definition at line 62 of file Semaphore.h.
Referenced by RequestQueue::addRequest(), ProducerConsumer::consumerThread(), Pipe::decreaseRefCount(), RequestQueue::destroy(), UsbHub::doSync(), RequestQueue::halt(), CdiIrqHandler::irq(), LockedFile::lock(), LockedFile::LockedFile(), InputManager::mainThread(), LwipSocketSyscalls::netconnCallback(), Nic3C90x::Nic3C90x(), AsidManager::obtainAsid(), PerProcessorScheduler::processorAddThread(), AsidManager::returnAsid(), Nic3C90x::send(), Ne2k::send(), sys_arch_sem_wait(), sys_mutex_lock(), WaitCleanup::terminated(), ConditionVariable::wait(), KernelElf::waitForModulesToLoad(), RequestQueue::work(), and Pipe::~Pipe().
Semaphore::SemaphoreResult Semaphore::acquireWithResult | ( | size_t | n = 1 , |
size_t | timeoutSecs = 0 , |
||
size_t | timeoutUsecs = 0 |
||
) |
Attempts to acquire n items from the semaphore. This will block until the semaphore is non-zero.
n | The number of semaphore items required. Must be non-zero. |
timeoutSecs | Timeout value in seconds - if zero, no timeout. |
Definition at line 99 of file Semaphore.cc.
References Spinlock::acquire(), Timer::addAlarm(), Thread::addWakeupWatcher(), assert, Thread::Continue, Machine::getTimer(), Processor::information(), NOTICE, List< T, nodePoolSize >::pushBack(), Spinlock::release(), Timer::removeAlarm(), removeThread(), Thread::removeWakeupWatcher(), Thread::setDebugState(), Thread::setInterrupted(), Processor::setInterrupts(), Thread::setUnwindState(), tryAcquire(), and Thread::wasInterrupted().
ssize_t Semaphore::getValue | ( | ) |
Gets the current value of the semaphore
Definition at line 318 of file Semaphore.cc.
Referenced by RequestQueue::getNextRequest(), ConditionVariable::wait(), and PosixSubsystem::~PosixSubsystem().
|
private |
Private operator=
void Semaphore::release | ( | size_t | n = 1 | ) |
Releases n items from the semaphore.
n | The number of semaphore items to release. Must be non-zero. |
Definition at line 239 of file Semaphore.cc.
References Spinlock::acquire(), assert, List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::count(), List< T, nodePoolSize >::end(), Thread::getLock(), Thread::getStatus(), Scheduler::instance(), List< T, nodePoolSize >::popFront(), List< T, nodePoolSize >::pushBack(), Spinlock::release(), Thread::setStatus(), and WARNING.
Referenced by RequestQueue::addRequest(), ProducerConsumer::consumerThread(), RequestQueue::destroy(), ConsoleFile::eventComplete(), RequestQueue::halt(), CdiIrqHandler::irq(), Nic3C90x::irq(), Pipe::isFifo(), LwipSocketSyscalls::netconnCallback(), Buffer< T, allowShortOperation >::notifyMonitors(), AsidManager::obtainAsid(), PollEvent::PollEvent(), InputManager::putNotification(), AsidManager::returnAsid(), Ne2k::send(), InputManager::shutdown(), Thread::shutdown(), UsbHub::syncCallback(), sys_mutex_unlock(), sys_sem_signal(), PosixSubsystem::threadRemoved(), LockedFile::unlock(), KernelElf::updateModuleStatus(), ConditionVariable::wait(), RequestQueue::work(), Pipe::~Pipe(), and PosixSubsystem::~PosixSubsystem().
|
private |
Removes the given pointer from the thread queue.
Definition at line 83 of file Semaphore.cc.
References Spinlock::acquire(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), and Spinlock::release().
Referenced by acquireWithResult().
bool Semaphore::tryAcquire | ( | size_t | n = 1 | ) |
Attempts to acquire n items from the semaphore. This will not block.
n | The number of semaphore items required. Must be non-zero. |
Definition at line 223 of file Semaphore.cc.
Referenced by acquireWithResult(), LockedFile::lock(), RequestQueue::work(), and PosixSubsystem::~PosixSubsystem().