aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-05-17 16:40:50 +0200
committerSven Gothel <[email protected]>2023-05-17 16:40:50 +0200
commite7f6807d42d9821e42ee4f8ae3ce9fd8ef2d4e31 (patch)
tree835398fa389089341c5f7fc5152d309d8c4a3259
parent1e9e8d108467902b7753c6910f5d1390dbf32edb (diff)
ALAudioSink: Add exclusive locking allowing less context management overhead
-rw-r--r--src/java/jogamp/openal/util/ALAudioSink.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/java/jogamp/openal/util/ALAudioSink.java b/src/java/jogamp/openal/util/ALAudioSink.java
index d2e5e39..bd8c4ae 100644
--- a/src/java/jogamp/openal/util/ALAudioSink.java
+++ b/src/java/jogamp/openal/util/ALAudioSink.java
@@ -71,6 +71,7 @@ public class ALAudioSink implements AudioSink {
private AudioFormat preferredAudioFormat;
private ALCcontext context;
private final RecursiveLock lock = LockFactory.createRecursiveLock();
+ private volatile Thread exclusiveThread = null;
/** Playback speed, range [0.5 - 2.0], default 1.0. */
private float playSpeed;
@@ -265,7 +266,23 @@ public class ALAudioSink implements AudioSink {
return sampleRate;
}
+ @Override
+ public final void lockExclusive() {
+ lockContext();
+ exclusiveThread = Thread.currentThread();
+ }
+ @Override
+ public final void unlockExclusive() {
+ exclusiveThread = null;
+ unlockContext();
+ }
private final void lockContext() {
+ if( null != exclusiveThread ) {
+ if( Thread.currentThread() == exclusiveThread ) {
+ return;
+ }
+ throw new IllegalStateException("Exclusive lock by "+exclusiveThread+", but current is "+Thread.currentThread());
+ }
lock.lock();
if( hasALC_thread_local_context ) {
alExt.alcSetThreadContext(context);
@@ -289,6 +306,12 @@ public class ALAudioSink implements AudioSink {
}
}
private final void unlockContext() {
+ if( null != exclusiveThread ) {
+ if( Thread.currentThread() == exclusiveThread ) {
+ return;
+ }
+ throw new IllegalStateException("Exclusive lock by "+exclusiveThread+", but current is "+Thread.currentThread());
+ }
if( hasALC_thread_local_context ) {
alExt.alcSetThreadContext(null);
} else {