Libraryless. Click here for Pure Java version (112L/1K).
1 | sclass FasterFlag is Runnable { |
2 | private volatile boolean up; |
3 | |
4 | /** returns true if flag was down before (i.e. flag was actually raised right now) */ |
5 | public bool raise() { |
6 | if (up) false; |
7 | synchronized { |
8 | if (up) false; |
9 | up = true; |
10 | notifyAll(); |
11 | true; |
12 | } |
13 | } |
14 | |
15 | run { raise(); } |
16 | |
17 | public void waitUntilUp() ctex { |
18 | if (up) ret; |
19 | synchronized { |
20 | while (!up) wait(); |
21 | } |
22 | } |
23 | |
24 | public bool waitUntilUp(double timeout) { |
25 | if (timeout == infinity()) { |
26 | waitUntilUp(); |
27 | ret isUp(); |
28 | } else |
29 | ret waitUntilUp(toMS(timeout)); |
30 | } |
31 | |
32 | public bool waitUntilUp(long timeout) ctex { |
33 | if (up) ret true; |
34 | synchronized { |
35 | if (!up) |
36 | wait(timeout); |
37 | } |
38 | ret isUp(); |
39 | } |
40 | |
41 | public bool isUp aka get() { ret up; } |
42 | |
43 | toString { ret isUp() ? "up" : "down"; } |
44 | } |
Began life as a copy of #1000915
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035583 |
Snippet name: | FasterFlag - Flag using double-checked locking (now merged into Flag) |
Eternal ID of this version: | #1035583/4 |
Text MD5: | 9cb52b784b350ceb7685e19fe5c6b6a3 |
Transpilation MD5: | 723c32b1803240b6fe871ecaf4b617cc |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-20 21:37:13 |
Source code size: | 878 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 127 / 193 |
Version history: | 3 change(s) |
Referenced in: | [show references] |