aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALu.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-19 19:00:54 -0700
committerChris Robinson <[email protected]>2014-03-19 19:00:54 -0700
commit168149ce9daedb2e3d9a11b7fee2b22b2e4daf7a (patch)
tree53df1cd7169aa870f93d7cb72e641815a67133aa /Alc/ALu.c
parent0c5cbafcd84df288c7f41e0ef06c9e3109b03365 (diff)
Keep track of the mix count
The purpose of this is to provide a safe way to be able to "swap" resources used by the mixer from other threads without the need to block the mixer, as well as a way to track when mixes have occurred. The idea is two-fold: It provides a way to safely swap resources. If the mixer were to (atomically) get a reference to an object to access it from, another thread would be able allocate and prepare a new object then swap the reference to it with the stored one. The other thread would then be able to wait until (count&1) is clear, indicating the mixer is not running, before safely freeing the old object for the mixer to use the new one. It also provides a way to tell if the mixer has run. With this, a thread would be able to read multiple values, which could be altered by the mixer, without requiring a mixer lock. Comparing the before and after counts for inequality would signify if the mixer has (started to) run, indicating the values may be out of sync and should try getting them again. Of course, it will still need something like a RWLock to ensure another (non-mixer) thread doesn't try to write to the values at the same time. Note that because of the possibility of overflow, the counter is not reliable as an absolute count.
Diffstat (limited to 'Alc/ALu.c')
-rw-r--r--Alc/ALu.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/Alc/ALu.c b/Alc/ALu.c
index ca38e737..85cb6332 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -1039,6 +1039,8 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
while(size > 0)
{
+ IncrementRef(&device->MixCount);
+
SamplesToDo = minu(size, BUFFERSIZE);
for(c = 0;c < MaxChannels;c++)
memset(device->DryBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
@@ -1228,6 +1230,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
}
size -= SamplesToDo;
+ IncrementRef(&device->MixCount);
}
RestoreFPUMode(&oldMode);