Lock the OBR mutex in head-tracking and limiter setters - #25
Merged
Conversation
SetHeadRotation(), EnableHeadTracking() and EnableLimiter() wrote world_rotation_, head_tracking_enabled_ and limiter_enabled_ without acquiring mutex_, while Process() reads all three under the lock for the duration of each rendered block. Head rotation in particular is typically updated from a sensor thread while audio renders, so the unsynchronized quaternion write could be observed torn mid-block, and all three are data races regardless. Every other ObrImpl mutator already takes the mutex; make these three do the same.
Contributor
|
Is OAR intended to support multithreading and be thread safe? |
Collaborator
Author
I can only confirm that OBR is safe to be configured on one thread and render audio on another one. Hence this PR. |
trsonic
requested review from
felicialim,
jingbo-marquis,
trevorknight and
yeroro
July 31, 2026 06:30
Contributor
Hi @trevorknight , |
yilun-zhangs
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SetHeadRotation(),EnableHeadTracking()andEnableLimiter()wroteworld_rotation_,head_tracking_enabled_andlimiter_enabled_without acquiringmutex_, whileProcess()reads all three under the lock for the duration of each rendered block. Head rotation in particular is typically updated from a sensor thread while the audio thread renders, so the unsynchronized 4-float quaternion write could be observed torn mid-block — and all three writes are data races regardless.Every other
ObrImplmutator already takes the mutex; this makes the remaining three do the same. The setters are only called from the C API wrappers (obr_capi.cpp), so no caller holds the lock and there is no deadlock path.No functional change on a single thread; existing tests pass unchanged.