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.
This commit is contained in:
parent
0c5cbafcd8
commit
168149ce9d
@ -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);
|
||||
|
@ -668,6 +668,13 @@ struct ALCdevice_struct
|
||||
ALIGN(16) ALfloat ClickRemoval[MaxChannels];
|
||||
ALIGN(16) ALfloat PendingClicks[MaxChannels];
|
||||
|
||||
/* Running count of the mixer invocations, in 31.1 fixed point. This
|
||||
* actually increments *twice* when mixing, first at the start and then at
|
||||
* the end, so the bottom bit indicates if the device is currently mixing
|
||||
* and the upper bits indicates how many mixes have been done.
|
||||
*/
|
||||
volatile RefCount MixCount;
|
||||
|
||||
/* Default effect slot */
|
||||
struct ALeffectslot *DefaultSlot;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user