Krotos Modules 3
Loading...
Searching...
No Matches
krotos::ResourceLock Class Reference

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>

Inheritance diagram for krotos::ResourceLock:
krotos::KrotosSampleOscillatorSound krotos::Kwidget krotos::Kwidget_Adsr krotos::Kwidget_AudioOut krotos::Kwidget_ConvolutionReverb krotos::Kwidget_CoreEngine krotos::Kwidget_Filter krotos::Kwidget_Lfo krotos::Kwidget_MacroControls krotos::Kwidget_MacroSlider krotos::Kwidget_MoogVcf krotos::Kwidget_OfflineAnalyser krotos::Kwidget_Pan krotos::Kwidget_PhaseVocoder krotos::Kwidget_Recorder krotos::Kwidget_Reformer krotos::Kwidget_SAFilter krotos::Kwidget_Saturation krotos::Kwidget_Sawtooth krotos::Kwidget_Scaledadsr krotos::Kwidget_Sine krotos::Kwidget_Template krotos::Kwidget_TriggerButton krotos::Kwidget_XyPad

Public Member Functions

 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.
 

Private Attributes

CriticalSection objectLock
 
StringArray m_clientList
 
volatile std::atomic< bool > m_isAccessible {false}
 
WaitableEvent m_waitForZeroUsers
 

Static Private Attributes

static const int DSP_THREAD_WAIT_MAX_MS {3000}
 

Detailed Description

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 ?

Constructor & Destructor Documentation

◆ ResourceLock()

krotos::ResourceLock::ResourceLock ( )
inline

Member Function Documentation

◆ finishedAccessing()

void krotos::ResourceLock::finishedAccessing ( const StringRef id)

Called by a client to inform the resource that it no longer needs access.

Parameters
idSupply 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
idSupply 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
idSupply 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

Member Data Documentation

◆ 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: