diff options
author | Chris Robinson <[email protected]> | 2014-03-19 19:00:54 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-03-19 19:00:54 -0700 |
commit | 168149ce9daedb2e3d9a11b7fee2b22b2e4daf7a (patch) | |
tree | 53df1cd7169aa870f93d7cb72e641815a67133aa /OpenAL32/Include | |
parent | 0c5cbafcd84df288c7f41e0ef06c9e3109b03365 (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 'OpenAL32/Include')
-rw-r--r-- | OpenAL32/Include/alMain.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 1d5eb888..b62ad9c7 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -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; |