aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorathomas <[email protected]>2003-06-28 03:11:07 +0000
committerathomas <[email protected]>2003-06-28 03:11:07 +0000
commit5e630e1a8060732234b291f4f19ab8c4e2d58d0d (patch)
tree330a830f35c23bf64d6528db4815607b44f8d581
parentab28a11b32eaccf5c958cee5aeaf21918d4d534c (diff)
mutex to provide thread safety
git-svn-id: file:///home/mbien/NetBeansProjects/JOGAMP/joal-sync/git-svn/../svn-server-sync/joal/trunk@42 03bf7f67-59de-4072-a415-9a990d468a3f
-rw-r--r--src/java/net/java/games/joal/ALC.java2
-rw-r--r--src/java/net/java/games/joal/ALCImpl.java52
2 files changed, 37 insertions, 17 deletions
diff --git a/src/java/net/java/games/joal/ALC.java b/src/java/net/java/games/joal/ALC.java
index bb53bc5..2da7f2d 100644
--- a/src/java/net/java/games/joal/ALC.java
+++ b/src/java/net/java/games/joal/ALC.java
@@ -91,6 +91,8 @@ public interface ALC extends ALCConstants {
*/
public int alcMakeContextCurrent(Context context);
+ public void alcFreeCurrentContext();
+
/**
* This method tells a context to begin processing. <br>
* <br>
diff --git a/src/java/net/java/games/joal/ALCImpl.java b/src/java/net/java/games/joal/ALCImpl.java
index d621a0a..6e7ccc5 100644
--- a/src/java/net/java/games/joal/ALCImpl.java
+++ b/src/java/net/java/games/joal/ALCImpl.java
@@ -37,16 +37,16 @@ import java.util.HashMap;
final class ALCImpl implements ALC {
private final HashMap contextMap = new HashMap();
- private static Object lock = new Object();
+ private static Mutex lock = new Mutex();
ALCImpl() {
System.loadLibrary("joal");
-
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
exit();
}
}));
+
}
public Device alcOpenDevice(String deviceName) {
@@ -84,26 +84,18 @@ final class ALCImpl implements ALC {
public int alcMakeContextCurrent(Context context) {
int result = 0;
- synchronized(lock) {
- int pointer = 0;
- if (context != null) {
- pointer = context.pointer;
- }
- result = makeContextCurrentNative(pointer);
- try {
- lock.wait();
- } catch (InterruptedException e) {
- result = 0;
- }
+ int pointer = 0;
+ if (context != null) {
+ pointer = context.pointer;
}
+ lock.acquire();
+ result = makeContextCurrentNative(pointer);
return result;
}
public void alcFreeCurrentContext() {
- synchronized(lock) {
- makeContextCurrentNative(0);
- lock.notifyAll();
- }
+ makeContextCurrentNative(0);
+ lock.release();
}
private native int makeContextCurrentNative(int pointer);
@@ -204,4 +196,30 @@ final class ALCImpl implements ALC {
alcCloseDevice(alcDevice);
}
}
+
+ private static class Mutex {
+ Thread owner = null;
+ public synchronized void acquire() {
+ boolean interrupted = false;
+ while(owner != null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+ owner = Thread.currentThread();
+ if(interrupted) {
+ owner.interrupt();
+ }
+ }
+
+ public synchronized void release() {
+ if(!owner.equals(Thread.currentThread())) {
+ throw new IllegalMonitorStateException("Not Owner");
+ }
+ owner = null;
+ notify();
+ }
+ }
}