This repository was archived by the owner on Mar 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +28
-11
lines changed
src/main/java/com/badlogic/gdx Expand file tree Collapse file tree 4 files changed +28
-11
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,6 @@ public int await(Consumer<V> consumeAfterCompletion) throws InterruptedException
102
102
} catch (BrokenBarrierException e ) {
103
103
throw new InterruptedException (e .getMessage ());
104
104
} catch (ExecutionException e ) {
105
- e .printStackTrace (System .err );
106
105
throw new RuntimeException ("Exception thrown during execution of asynchronous task!" , e );
107
106
}
108
107
}
Original file line number Diff line number Diff line change
1
+ package com .badlogic .gdx .concurrent ;
2
+
3
+ import com .badlogic .gdx .function .Supplier ;
4
+
5
+ /**
6
+ * Substitute for {@link ThreadLocal#withInitial(Supplier)}
7
+ */
8
+ public class ThreadLocalInstance <T > extends ThreadLocal <T > {
9
+
10
+ private final Supplier <? extends T > supplier ;
11
+
12
+ public ThreadLocalInstance (Supplier <? extends T > supplier ) {
13
+ this .supplier = supplier ;
14
+ }
15
+
16
+ @ Override
17
+ protected T initialValue () {
18
+ return supplier .get ();
19
+ }
20
+ }
Original file line number Diff line number Diff line change 1
1
package com .badlogic .gdx .json ;
2
2
3
+ import com .badlogic .gdx .concurrent .ThreadLocalInstance ;
3
4
import com .badlogic .gdx .utils .GdxRuntimeException ;
4
5
import com .badlogic .gdx .utils .StringBuilder ;
5
6
8
9
9
10
/**
10
11
* Utility functions to (optionally) store floats and doubles using a IEEE-754 bit masks.
11
- *
12
+ * <p>
12
13
* Reference: http://the-witness.net/news/2011/12/engine-tech-concurrent-world-editing/
13
14
*/
14
15
public class JsonFloatSerializer {
@@ -17,12 +18,8 @@ public class JsonFloatSerializer {
17
18
private static final Pattern purePattern = Pattern .compile ("^" + fpRegEx + "$" );
18
19
private static final Pattern ieeePattern = Pattern .compile ("^0x([a-fA-F0-9]+)\\ |" + fpRegEx + "$" );
19
20
20
- private static final ThreadLocal <StringBuilder > stringBuilder = new ThreadLocal <StringBuilder >() {
21
- @ Override
22
- protected StringBuilder initialValue () {
23
- return new StringBuilder (32 );
24
- }
25
- };
21
+ private static final ThreadLocal <StringBuilder > stringBuilder =
22
+ new ThreadLocalInstance <>(() -> new StringBuilder (32 ));
26
23
27
24
public static String encodeFloatBits (float value ) {
28
25
Original file line number Diff line number Diff line change 1
1
package com .badlogic .gdx .lang ;
2
2
3
+ import com .badlogic .gdx .concurrent .ThreadLocalInstance ;
3
4
import com .badlogic .gdx .function .Consumer ;
4
5
5
6
import java .lang .reflect .Array ;
@@ -193,13 +194,13 @@ public void close() {
193
194
}
194
195
195
196
private static final ThreadLocal <BorrowChecker <Boolean >> tlsBoolean =
196
- ThreadLocal . withInitial (() -> new BorrowChecker <>(Boolean .class ));
197
+ new ThreadLocalInstance <> (() -> new BorrowChecker <>(Boolean .class ));
197
198
198
199
private static final ThreadLocal <BorrowChecker <Integer >> tlsInteger =
199
- ThreadLocal . withInitial (() -> new BorrowChecker <>(Integer .class ));
200
+ new ThreadLocalInstance <> (() -> new BorrowChecker <>(Integer .class ));
200
201
201
202
private static final ThreadLocal <BorrowChecker <Float >> tlsFloat =
202
- ThreadLocal . withInitial (() -> new BorrowChecker <>(Float .class ));
203
+ new ThreadLocalInstance <> (() -> new BorrowChecker <>(Float .class ));
203
204
204
205
public static Boolean borrowBoolean () {
205
206
return tlsBoolean .get ().borrow ().reference ();
You can’t perform that action at this time.
0 commit comments