Class used to manage access to a resource from multiple users / threads In this version, requests must pass in a unique identifier ID. Doing so allows keeping track of access requests seperately. This is necessary because it can happen that the same caller can request access many times, even after it has been granted access. Conversely a caller may call finishedAccessing() many times after access finished has already been registered. This ID could in fact be simply a unique integer, however, using a human readable String is a boon to debugging when sent to the logger, and the CPU overhead should not be high as these requests are not prohibitively frequent ... about 25 Hz in the case of the grain display redraw, and audio block rate in the case of access to audio data. TODO: perhaps some profiling if in doubt ?
More...
#include <ResourceLock.h>
|
| | ResourceLock () |
| |
| bool | requestAccess (const StringRef id) |
| | Called by a client to request access to the resource.
|
| |
| bool | hasAccess (const StringRef id) const |
| | Called by a client to enquire whether it has access to the resource.
|
| |
| void | finishedAccessing (const StringRef id) |
| | Called by a client to inform the resource that it no longer needs access.
|
| |
| void | setAccessible (bool isAccessible) |
| | Called by the resource to grant or deny access to clients.
|
| |
Class used to manage access to a resource from multiple users / threads In this version, requests must pass in a unique identifier ID. Doing so allows keeping track of access requests seperately. This is necessary because it can happen that the same caller can request access many times, even after it has been granted access. Conversely a caller may call finishedAccessing() many times after access finished has already been registered. This ID could in fact be simply a unique integer, however, using a human readable String is a boon to debugging when sent to the logger, and the CPU overhead should not be high as these requests are not prohibitively frequent ... about 25 Hz in the case of the grain display redraw, and audio block rate in the case of access to audio data. TODO: perhaps some profiling if in doubt ?
◆ ResourceLock()
| krotos::ResourceLock::ResourceLock |
( |
| ) |
|
|
inline |
◆ finishedAccessing()
| void krotos::ResourceLock::finishedAccessing |
( |
const StringRef | id | ) |
|
Called by a client to inform the resource that it no longer needs access.
- Parameters
-
| id | Supply the same unique identifying string as when you requested access |
- Returns
- Returns true if access granted, false if access denied
◆ hasAccess()
| bool krotos::ResourceLock::hasAccess |
( |
const StringRef | id | ) |
const |
Called by a client to enquire whether it has access to the resource.
- Parameters
-
| id | Supply a unique identifying string when you request access Supply the same string used when calling requestAccess() |
- Returns
- Returns true if has access, false if not
◆ requestAccess()
| bool krotos::ResourceLock::requestAccess |
( |
const StringRef | id | ) |
|
Called by a client to request access to the resource.
- Parameters
-
| id | Supply a unique identifying string when you request access Supply the same string when you call finishedAccessing() |
- Returns
- Returns true if access granted, false if access denied
◆ setAccessible()
| void krotos::ResourceLock::setAccessible |
( |
bool | isAccessible | ) |
|
Called by the resource to grant or deny access to clients.
- Parameters
-
| isAccessible | - set true to grant access, false to deny access |
◆ DSP_THREAD_WAIT_MAX_MS
| const int krotos::ResourceLock::DSP_THREAD_WAIT_MAX_MS {3000} |
|
staticprivate |
◆ m_clientList
| StringArray krotos::ResourceLock::m_clientList |
|
private |
◆ m_isAccessible
| volatile std::atomic<bool> krotos::ResourceLock::m_isAccessible {false} |
|
private |
◆ m_waitForZeroUsers
| WaitableEvent krotos::ResourceLock::m_waitForZeroUsers |
|
private |
◆ objectLock
| CriticalSection krotos::ResourceLock::objectLock |
|
private |
The documentation for this class was generated from the following files: