From 186b54aa3d5f1398a384fa318aa000210d82437e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 11 May 2016 18:40:17 -0700 Subject: Use a lockless method for updating listener and context properties This uses a separate container to provide the relevant properties to the internal update method, using atomic pointer swaps. A free-list is used to avoid having too many individual containers. This allows the mixer to update the internal listener properties without requiring the lock to protect against async updates. It also allows concurrent read access to the user-facing property values, even the multi-value ones (e.g. the vectors). --- OpenAL32/Include/alListener.h | 30 ++++++++++++++++++++++++++++-- OpenAL32/Include/alMain.h | 7 +++---- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'OpenAL32/Include') diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h index f28561fa..75a3fb46 100644 --- a/OpenAL32/Include/alListener.h +++ b/OpenAL32/Include/alListener.h @@ -8,14 +8,38 @@ extern "C" { #endif +struct ALlistenerProps { + ATOMIC(ALfloat) Position[3]; + ATOMIC(ALfloat) Velocity[3]; + ATOMIC(ALfloat) Forward[3]; + ATOMIC(ALfloat) Up[3]; + ATOMIC(ALfloat) Gain; + ATOMIC(ALfloat) MetersPerUnit; + + ATOMIC(ALfloat) DopplerFactor; + ATOMIC(ALfloat) DopplerVelocity; + ATOMIC(ALfloat) SpeedOfSound; + + ATOMIC(struct ALlistenerProps*) next; +}; + typedef struct ALlistener { - aluVector Position; - aluVector Velocity; + volatile ALfloat Position[3]; + volatile ALfloat Velocity[3]; volatile ALfloat Forward[3]; volatile ALfloat Up[3]; volatile ALfloat Gain; volatile ALfloat MetersPerUnit; + /* Pointer to the most recent property values that are awaiting an update. + */ + ATOMIC(struct ALlistenerProps*) Update; + + /* A linked list of unused property containers, free to use for future + * updates. + */ + ATOMIC(struct ALlistenerProps*) FreeList; + struct { aluMatrixd Matrix; aluVector Velocity; @@ -28,6 +52,8 @@ typedef struct ALlistener { } Params; } ALlistener; +void UpdateListenerProps(ALCcontext *context); + #ifdef __cplusplus } #endif diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index e818245b..44ce4fe0 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -679,8 +679,7 @@ struct ALCdevice_struct #define RECORD_THREAD_NAME "alsoft-record" -struct ALCcontext_struct -{ +struct ALCcontext_struct { RefCount ref; struct ALlistener *Listener; @@ -690,8 +689,6 @@ struct ALCcontext_struct ATOMIC(ALenum) LastError; - ATOMIC(ALenum) UpdateSources; - volatile enum DistanceModel DistanceModel; volatile ALboolean SourceDistanceModel; @@ -700,6 +697,8 @@ struct ALCcontext_struct volatile ALfloat SpeedOfSound; volatile ALenum DeferUpdates; + RWLock PropLock; + struct ALvoice *Voices; ALsizei VoiceCount; ALsizei MaxVoices; -- cgit v1.2.3