|
The Pedigree Project 0.1
|
#include <Semaphore.h>
Inheritance diagram for Semaphore:
Collaboration diagram for Semaphore:Classes | |
| class | SemaphoreEvent |
Public Types | |
| enum | SemaphoreError { TimedOut , Interrupted , NoError } |
Public Member Functions | |
| Semaphore (size_t nInitialValue, bool canInterrupt=true) | |
| virtual | ~Semaphore () |
| MUST_USE_RESULT bool | acquireWithError (size_t n, size_t timeoutSecs, size_t timeoutUsecs, SemaphoreError &error) |
| MUST_USE_RESULT bool | acquireForCompletion (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) |
| MUST_USE_RESULT size_t | drainAvailable () |
| void | release (size_t n=1) |
| ssize_t | getValue () |
| const void * | getDebugMutexOwner () const |
Protected Member Functions | |
| void | initialiseMutex (bool locked) |
| void | destroyMutex () |
| bool | mutexOwnedByCurrentThread () const |
Private Types | |
| typedef Result< bool, SemaphoreError > | SemaphoreResult |
Private Member Functions | |
| MUST_USE_RESULT SemaphoreResult | acquireWithResult (size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0, bool deferTerminal=false) |
| Semaphore (const Semaphore &) | |
| void | operator= (const Semaphore &) |
Private Attributes | |
| size_t | magic |
| Atomic< ssize_t > | m_Counter |
| WaitQueue | m_Waiters |
| bool | m_bCanInterrupt |
A counting semaphore.
Definition at line 36 of file Semaphore.h.
|
private |
Definition at line 123 of file Semaphore.h.
| enum Semaphore::SemaphoreError |
Definition at line 38 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 151 of file Semaphore.cc.
|
virtual |
Destructor
Definition at line 156 of file Semaphore.cc.
|
private |
Private copy constructor
| bool Semaphore::acquire | ( | size_t | n = 1, |
| size_t | timeoutSecs = 0, |
||
| size_t | timeoutUsecs = 0 |
||
| ) |
Convenience wrapper for acquire().
Definition at line 352 of file Semaphore.cc.
Referenced by acquireForCompletion(), PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), NetworkStack::deRegisterDevice(), ProducerConsumer::destroy(), LockedFile::lock(), LockedFile::LockedFile(), InputManager::mainThread(), EventFd::readValue(), Directory::reserveDirectoryEntry(), GraphicsService::serve(), sys_mutex_lock(), Pipe::waitForReader(), EventFd::writeValue(), and Pipe::~Pipe().
Here is the caller graph for this function:| bool Semaphore::acquireForCompletion | ( | size_t | n = 1, |
| size_t | timeoutSecs = 0, |
||
| size_t | timeoutUsecs = 0 |
||
| ) |
Acquires a semaphore used as an internal completion barrier.
Signal events are delivered while blocked, but do not complete the barrier. The signal interruption marker is restored after the semaphore is acquired (or the original timeout expires), allowing an outer syscall boundary to report EINTR without abandoning storage still owned by the asynchronous operation.
Definition at line 369 of file Semaphore.cc.
References acquire(), EMIT_IF, ProcessorBase::guardDeviceHardIrqOperation(), ProcessorBase::information(), and tryAcquire().
Referenced by AtaDisk::doRead(), UsbHub::doSync(), Nic3C90x::send(), sys_arch_sem_wait(), and AtaDisk::writePageBuffer().
Here is the caller graph for this function:| bool Semaphore::acquireWithError | ( | size_t | n, |
| size_t | timeoutSecs, | ||
| size_t | timeoutUsecs, | ||
| SemaphoreError & | error | ||
| ) |
Acquires n items and reports the exact failure in error.
Definition at line 357 of file Semaphore.cc.
Referenced by UsbHub::doSync(), and EpollInstance::wait().
Here is the caller graph for this function:
|
private |
Definition at line 160 of file Semaphore.cc.
|
protected |
Definition at line 616 of file Semaphore.cc.
| size_t Semaphore::drainAvailable | ( | ) |
Atomically removes and returns every currently available item.
Definition at line 528 of file Semaphore.cc.
Referenced by Nic3C90x::send().
Here is the caller graph for this function:| const void * Semaphore::getDebugMutexOwner | ( | ) | const |
Returns the owning thread address when this is a locked Mutex.
This is a read-only, best-effort debugger snapshot. A plain Semaphore or unlocked Mutex returns nullptr.
Definition at line 602 of file Semaphore.cc.
| ssize_t Semaphore::getValue | ( | ) |
Gets the current value of the semaphore
Definition at line 598 of file Semaphore.cc.
|
protected |
Reuses this semaphore's storage for Mutex ownership state. These hooks keep Mutex layout-compatible with its historical empty subclass while ensuring calls through either the Mutex or Semaphore interface enforce mutex ownership.
Definition at line 611 of file Semaphore.cc.
Referenced by Mutex::Mutex().
Here is the caller graph for this function:
|
protected |
Definition at line 624 of file Semaphore.cc.
|
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 546 of file Semaphore.cc.
References EMIT_IF, ProcessorBase::guardDeviceHardIrqOperation(), and WaitQueue::wakeAllIfWaiting().
Referenced by PosixSubsystem::acquireFileDescriptor(), PosixSubsystem::acquireNextFileDescriptor(), PosixSubsystem::addFileDescriptor(), PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), PosixSubsystem::allocateFd(), PosixSubsystem::closeFileDescriptor(), MemoryMappedFile::compact(), PosixSubsystem::copyDescriptors(), NetworkStack::deRegisterDevice(), PosixSubsystem::descriptorMatchesOpenDescription(), ProducerConsumer::destroy(), PosixSubsystem::duplicateFileDescriptor(), Uhci::enqueueCompletedTransfer(), PosixSubsystem::freeFd(), PosixSubsystem::freeMultipleFds(), PosixSubsystem::getFd(), TextIO::initialise(), PosixSubsystem::installFileDescriptor(), Nic3C90x::irq(), CdiIrqHandler::irq(), AtaDisk::irqReceived(), RingBuffer< T, preallocatedSize >::monitor(), Buffer< T, allowShortOperation >::notifyMonitorsLocked(), InputManager::putNotification(), File::readIntoCache(), EventFd::readValue(), PosixSubsystem::release(), Directory::reserveDirectoryEntry(), GraphicsService::serve(), VmwareGraphics::setScreenMode(), InputManager::shutdown(), UsbHub::syncCallback(), sys_mutex_unlock(), sys_sem_signal(), MemoryPool::trim(), Ext2File::tryBeginMappingRelease(), LockedFile::unlock(), Pipe::waitForReader(), EventFd::writeValue(), and Pipe::~Pipe().
Here is the caller graph for this function:| 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 481 of file Semaphore.cc.
References EMIT_IF.
Referenced by acquireForCompletion(), MemoryMappedFile::compact(), TextIO::initialise(), LockedFile::lock(), GraphicsService::serve(), VmwareGraphics::setScreenMode(), MemoryPool::trim(), File::tryBeginMappingRelease(), Ext2File::tryBeginMappingRelease(), and EpollInstance::wait().
Here is the caller graph for this function:
|
private |
Definition at line 151 of file Semaphore.h.
|
private |
Definition at line 149 of file Semaphore.h.
|
private |
Definition at line 150 of file Semaphore.h.
|
private |
Definition at line 147 of file Semaphore.h.