aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-02-24 05:33:58 +0100
committerSven Gothel <[email protected]>2020-02-24 05:33:58 +0100
commit0fc0b0d5da38bc3a73689b95626861ca9d70e5de (patch)
tree1ca1afc93d226a65cf6459bb3299dc5fde6b13cd
parent77ae1b75f3c6feab97a4fffea44aadbd6e1d0b15 (diff)
IOSUtil.IsMainThread(): Utilize caching ThreadLocal<Boolean> like OSXUtil's variant.
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java b/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java
index 4790f21da..66669d664 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java
@@ -44,6 +44,8 @@ public class IOSUtil implements ToolkitProperties {
private static boolean isInit = false;
private static final boolean DEBUG = Debug.debug("IOSUtil");
+ private static final ThreadLocal<Boolean> tlsIsMainThread = new ThreadLocal<Boolean>();
+
/** FIXME HiDPI: OSX unique and maximum value {@value} */
public static final int MAX_PIXELSCALE = 2;
@@ -290,8 +292,22 @@ public class IOSUtil implements ToolkitProperties {
}
}
+ /**
+ * Returns true if the current is the UIApplication main-thread.
+ * <p>
+ * Implementation utilizes a {@link ThreadLocal} storage boolean holding the answer,
+ * which only gets set at the first call from each individual thread.
+ * This minimizes unnecessary native callbacks.
+ * </p>
+ * @return {@code true} if current thread is the UIApplication main-thread, otherwise false.
+ */
public static boolean IsMainThread() {
- return IsMainThread0();
+ Boolean isMainThread = tlsIsMainThread.get();
+ if( null == isMainThread ) {
+ isMainThread = new Boolean(IsMainThread0());
+ tlsIsMainThread.set(isMainThread);
+ }
+ return isMainThread.booleanValue();
}
/** Returns the screen refresh rate in Hz. If unavailable, returns 60Hz. */