Removed unnecessary (and deadlock prone) synchronized modifiers from methods in Keyboard and Mouse

This commit is contained in:
Elias Naur 2007-05-30 20:33:40 +00:00
parent 6939f9170a
commit 8f2da1dea5
2 changed files with 51 additions and 49 deletions

View File

@ -303,7 +303,7 @@ public class Keyboard {
* *
* @throws LWJGLException if the keyboard could not be created for any reason * @throws LWJGLException if the keyboard could not be created for any reason
*/ */
public static synchronized void create() throws LWJGLException { public static void create() throws LWJGLException {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); if (!Display.isCreated()) throw new IllegalStateException("Display must be created.");
@ -321,7 +321,7 @@ public class Keyboard {
/** /**
* @return true if the keyboard has been created * @return true if the keyboard has been created
*/ */
public static synchronized boolean isCreated() { public static boolean isCreated() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return created; return created;
} }
@ -330,7 +330,7 @@ public class Keyboard {
/** /**
* "Destroy" the keyboard * "Destroy" the keyboard
*/ */
public static synchronized void destroy() { public static void destroy() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) if (!created)
return; return;
@ -358,7 +358,7 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#getEventKeyState() * @see org.lwjgl.input.Keyboard#getEventKeyState()
* @see org.lwjgl.input.Keyboard#getEventCharacter() * @see org.lwjgl.input.Keyboard#getEventCharacter()
*/ */
public static synchronized void poll() { public static void poll() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) if (!created)
throw new IllegalStateException("Keyboard must be created before you can poll the device"); throw new IllegalStateException("Keyboard must be created before you can poll the device");
@ -378,7 +378,7 @@ public class Keyboard {
* @param key Keycode to check * @param key Keycode to check
* @return true if the key is down according to the last poll() * @return true if the key is down according to the last poll()
*/ */
public static synchronized boolean isKeyDown(int key) { public static boolean isKeyDown(int key) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) if (!created)
throw new IllegalStateException("Keyboard must be created before you can query key state"); throw new IllegalStateException("Keyboard must be created before you can query key state");
@ -423,7 +423,7 @@ public class Keyboard {
* Gets the number of keyboard events waiting after doing a buffer enabled poll(). * Gets the number of keyboard events waiting after doing a buffer enabled poll().
* @return the number of keyboard events * @return the number of keyboard events
*/ */
public static synchronized int getNumKeyboardEvents() { public static int getNumKeyboardEvents() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events"); throw new IllegalStateException("Keyboard must be created before you can read events");
@ -447,7 +447,7 @@ public class Keyboard {
* @see org.lwjgl.input.Keyboard#getEventCharacter() * @see org.lwjgl.input.Keyboard#getEventCharacter()
* @return true if a keyboard event was read, false otherwise * @return true if a keyboard event was read, false otherwise
*/ */
public static synchronized boolean next() { public static boolean next() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) if (!created)
throw new IllegalStateException("Keyboard must be created before you can read events"); throw new IllegalStateException("Keyboard must be created before you can read events");
@ -467,8 +467,10 @@ public class Keyboard {
* *
* @see org.lwjgl.input.Keyboard#getEventKey() * @see org.lwjgl.input.Keyboard#getEventKey()
*/ */
public static synchronized void enableRepeatEvents(boolean enable) { public static void enableRepeatEvents(boolean enable) {
repeat_enabled = enable; synchronized (OpenGLPackageAccess.global_lock) {
repeat_enabled = enable;
}
} }
/** /**
@ -477,8 +479,10 @@ public class Keyboard {
* @return true is repeat events are reported, false if not. * @return true is repeat events are reported, false if not.
* @see org.lwjgl.input.Keyboard#getEventKey() * @see org.lwjgl.input.Keyboard#getEventKey()
*/ */
public static synchronized boolean areRepeatEventsEnabled() { public static boolean areRepeatEventsEnabled() {
return repeat_enabled; synchronized (OpenGLPackageAccess.global_lock) {
return repeat_enabled;
}
} }
private static boolean readNext(KeyEvent event) { private static boolean readNext(KeyEvent event) {
@ -496,16 +500,14 @@ public class Keyboard {
/** /**
* @return Number of keys on this keyboard * @return Number of keys on this keyboard
*/ */
public static synchronized int getKeyCount() { public static int getKeyCount() {
synchronized (OpenGLPackageAccess.global_lock) { return keyCount;
return keyCount;
}
} }
/** /**
* @return The character from the current event * @return The character from the current event
*/ */
public static synchronized char getEventCharacter() { public static char getEventCharacter() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return (char)current_event.character; return (char)current_event.character;
} }
@ -518,7 +520,7 @@ public class Keyboard {
* *
* @return The key from the current event * @return The key from the current event
*/ */
public static synchronized int getEventKey() { public static int getEventKey() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return current_event.key; return current_event.key;
} }
@ -530,7 +532,7 @@ public class Keyboard {
* *
* @return True if key was down, or false if released * @return True if key was down, or false if released
*/ */
public static synchronized boolean getEventKeyState() { public static boolean getEventKeyState() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return current_event.state; return current_event.state;
} }
@ -543,7 +545,7 @@ public class Keyboard {
* origin. * origin.
* @return The time in nanoseconds of the current event * @return The time in nanoseconds of the current event
*/ */
public static synchronized long getEventNanoseconds() { public static long getEventNanoseconds() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return current_event.nanos; return current_event.nanos;
} }
@ -554,7 +556,7 @@ public class Keyboard {
* @return true if the current event is a repeat event, false if * @return true if the current event is a repeat event, false if
* the current event is not a repeat even or if repeat events are disabled. * the current event is not a repeat even or if repeat events are disabled.
*/ */
public static synchronized boolean isRepeatEvent() { public static boolean isRepeatEvent() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return current_event.repeat; return current_event.repeat;
} }

View File

@ -146,7 +146,7 @@ public class Mouse {
* *
* @return the currently bound native cursor, if any. * @return the currently bound native cursor, if any.
*/ */
public static synchronized Cursor getNativeCursor() { public static Cursor getNativeCursor() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return currentCursor; return currentCursor;
} }
@ -163,7 +163,7 @@ public class Mouse {
* @return The previous Cursor object set, or null. * @return The previous Cursor object set, or null.
* @throws LWJGLException if the cursor could not be set for any reason * @throws LWJGLException if the cursor could not be set for any reason
*/ */
public static synchronized Cursor setNativeCursor(Cursor cursor) throws LWJGLException { public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0) if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0)
throw new IllegalStateException("Mouse doesn't support native cursors"); throw new IllegalStateException("Mouse doesn't support native cursors");
@ -190,7 +190,7 @@ public class Mouse {
* @param y The y coordinate of the new cursor position in OpenGL coordinates relative * @param y The y coordinate of the new cursor position in OpenGL coordinates relative
* to the window origin. * to the window origin.
*/ */
public static synchronized void setCursorPosition(int new_x, int new_y) { public static void setCursorPosition(int new_x, int new_y) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!isCreated()) if (!isCreated())
throw new IllegalStateException("Mouse is not created"); throw new IllegalStateException("Mouse is not created");
@ -260,7 +260,7 @@ public class Mouse {
* *
* @throws LWJGLException if the mouse could not be created for any reason * @throws LWJGLException if the mouse could not be created for any reason
*/ */
public static synchronized void create() throws LWJGLException { public static void create() throws LWJGLException {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); if (!Display.isCreated()) throw new IllegalStateException("Display must be created.");
@ -271,7 +271,7 @@ public class Mouse {
/** /**
* @return true if the mouse has been created * @return true if the mouse has been created
*/ */
public static synchronized boolean isCreated() { public static boolean isCreated() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return created; return created;
} }
@ -280,7 +280,7 @@ public class Mouse {
/** /**
* "Destroy" the mouse. * "Destroy" the mouse.
*/ */
public static synchronized void destroy() { public static void destroy() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) return; if (!created) return;
created = false; created = false;
@ -312,7 +312,7 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#getDY() * @see org.lwjgl.input.Mouse#getDY()
* @see org.lwjgl.input.Mouse#getDWheel() * @see org.lwjgl.input.Mouse#getDWheel()
*/ */
public static synchronized void poll() { public static void poll() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) throw new IllegalStateException("Mouse must be created before you can poll it"); if (!created) throw new IllegalStateException("Mouse must be created before you can poll it");
implementation.pollMouse(coord_buffer, buttons); implementation.pollMouse(coord_buffer, buttons);
@ -353,7 +353,7 @@ public class Mouse {
* @param button The index of the button you wish to test (0..getButtonCount-1) * @param button The index of the button you wish to test (0..getButtonCount-1)
* @return true if the specified button is down * @return true if the specified button is down
*/ */
public static synchronized boolean isButtonDown(int button) { public static boolean isButtonDown(int button) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) throw new IllegalStateException("Mouse must be created before you can poll the button state"); if (!created) throw new IllegalStateException("Mouse must be created before you can poll the button state");
if (button >= buttonCount || button < 0) if (button >= buttonCount || button < 0)
@ -368,7 +368,7 @@ public class Mouse {
* @param button The button * @param button The button
* @return a String with the button's human readable name in it or null if the button is unnamed * @return a String with the button's human readable name in it or null if the button is unnamed
*/ */
public static synchronized String getButtonName(int button) { public static String getButtonName(int button) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (button >= buttonName.length || button < 0) if (button >= buttonName.length || button < 0)
return null; return null;
@ -381,7 +381,7 @@ public class Mouse {
* Get's a button's index. If the button is unrecognised then -1 is returned. * Get's a button's index. If the button is unrecognised then -1 is returned.
* @param buttonName The button name * @param buttonName The button name
*/ */
public static synchronized int getButtonIndex(String buttonName) { public static int getButtonIndex(String buttonName) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
Integer ret = (Integer) buttonMap.get(buttonName); Integer ret = (Integer) buttonMap.get(buttonName);
if (ret == null) if (ret == null)
@ -400,7 +400,7 @@ public class Mouse {
* @see org.lwjgl.input.Mouse#getEventButtonState() * @see org.lwjgl.input.Mouse#getEventButtonState()
* @return true if a mouse event was read, false otherwise * @return true if a mouse event was read, false otherwise
*/ */
public static synchronized boolean next() { public static boolean next() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (!created) throw new IllegalStateException("Mouse must be created before you can read events"); if (!created) throw new IllegalStateException("Mouse must be created before you can read events");
if (readBuffer.hasRemaining()) { if (readBuffer.hasRemaining()) {
@ -432,7 +432,7 @@ public class Mouse {
/** /**
* @return Current events button. Returns -1 if no button state was changed * @return Current events button. Returns -1 if no button state was changed
*/ */
public static synchronized int getEventButton() { public static int getEventButton() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return eventButton; return eventButton;
} }
@ -442,7 +442,7 @@ public class Mouse {
* Get the current events button state. * Get the current events button state.
* @return Current events button state. * @return Current events button state.
*/ */
public static synchronized boolean getEventButtonState() { public static boolean getEventButtonState() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return eventState; return eventState;
} }
@ -451,7 +451,7 @@ public class Mouse {
/** /**
* @return Current events delta x. Only valid when the mouse is grabbed. * @return Current events delta x. Only valid when the mouse is grabbed.
*/ */
public static synchronized int getEventDX() { public static int getEventDX() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_dx; return event_dx;
} }
@ -460,7 +460,7 @@ public class Mouse {
/** /**
* @return Current events delta y. Only valid when the mouse is grabbed. * @return Current events delta y. Only valid when the mouse is grabbed.
*/ */
public static synchronized int getEventDY() { public static int getEventDY() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_dy; return event_dy;
} }
@ -469,7 +469,7 @@ public class Mouse {
/** /**
* @return Current events absolute x. Only valid when the mouse is not grabbed. * @return Current events absolute x. Only valid when the mouse is not grabbed.
*/ */
public static synchronized int getEventX() { public static int getEventX() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_x; return event_x;
} }
@ -478,7 +478,7 @@ public class Mouse {
/** /**
* @return Current events absolute y. Only valid when the mouse is not grabbed. * @return Current events absolute y. Only valid when the mouse is not grabbed.
*/ */
public static synchronized int getEventY() { public static int getEventY() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_y; return event_y;
} }
@ -487,7 +487,7 @@ public class Mouse {
/** /**
* @return Current events delta z * @return Current events delta z
*/ */
public static synchronized int getEventDWheel() { public static int getEventDWheel() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_dwheel; return event_dwheel;
} }
@ -501,7 +501,7 @@ public class Mouse {
* *
* @return The time in nanoseconds of the current event * @return The time in nanoseconds of the current event
*/ */
public static synchronized long getEventNanoseconds() { public static long getEventNanoseconds() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return event_nanos; return event_nanos;
} }
@ -513,7 +513,7 @@ public class Mouse {
* *
* @return Absolute x axis position of mouse * @return Absolute x axis position of mouse
*/ */
public static synchronized int getX() { public static int getX() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return x; return x;
} }
@ -525,7 +525,7 @@ public class Mouse {
* *
* @return Absolute y axis position of mouse * @return Absolute y axis position of mouse
*/ */
public static synchronized int getY() { public static int getY() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return y; return y;
} }
@ -534,7 +534,7 @@ public class Mouse {
/** /**
* @return Movement on the x axis since last time getDX() was called. Only valid when the mouse is grabbed. * @return Movement on the x axis since last time getDX() was called. Only valid when the mouse is grabbed.
*/ */
public static synchronized int getDX() { public static int getDX() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
int result = dx; int result = dx;
dx = 0; dx = 0;
@ -545,7 +545,7 @@ public class Mouse {
/** /**
* @return Movement on the y axis since last time getDY() was called. Only valid when the mouse is grabbed. * @return Movement on the y axis since last time getDY() was called. Only valid when the mouse is grabbed.
*/ */
public static synchronized int getDY() { public static int getDY() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
int result = dy; int result = dy;
dy = 0; dy = 0;
@ -556,7 +556,7 @@ public class Mouse {
/** /**
* @return Movement of the wheel since last time getDWheel() was called * @return Movement of the wheel since last time getDWheel() was called
*/ */
public static synchronized int getDWheel() { public static int getDWheel() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
int result = dwheel; int result = dwheel;
dwheel = 0; dwheel = 0;
@ -567,7 +567,7 @@ public class Mouse {
/** /**
* @return Number of buttons on this mouse * @return Number of buttons on this mouse
*/ */
public static synchronized int getButtonCount() { public static int getButtonCount() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return buttonCount; return buttonCount;
} }
@ -576,7 +576,7 @@ public class Mouse {
/** /**
* @return Whether or not this mouse has wheel support * @return Whether or not this mouse has wheel support
*/ */
public static synchronized boolean hasWheel() { public static boolean hasWheel() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return hasWheel; return hasWheel;
} }
@ -585,7 +585,7 @@ public class Mouse {
/** /**
* @return whether or not the mouse has grabbed the cursor * @return whether or not the mouse has grabbed the cursor
*/ */
public static synchronized boolean isGrabbed() { public static boolean isGrabbed() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
return isGrabbed; return isGrabbed;
} }
@ -599,7 +599,7 @@ public class Mouse {
* *
* @param grab whether the mouse should be grabbed * @param grab whether the mouse should be grabbed
*/ */
public static synchronized void setGrabbed(boolean grab) { public static void setGrabbed(boolean grab) {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
isGrabbed = grab; isGrabbed = grab;
if (isCreated()) { if (isCreated()) {
@ -618,7 +618,7 @@ public class Mouse {
* This method is called automatically by the window on its update, and * This method is called automatically by the window on its update, and
* shouldn't be called otherwise * shouldn't be called otherwise
*/ */
public static synchronized void updateCursor() { public static void updateCursor() {
synchronized (OpenGLPackageAccess.global_lock) { synchronized (OpenGLPackageAccess.global_lock) {
if (emulateCursorAnimation && currentCursor != null && currentCursor.hasTimedOut()) { if (emulateCursorAnimation && currentCursor != null && currentCursor.hasTimedOut()) {
currentCursor.nextCursor(); currentCursor.nextCursor();