Libraryless. Click here for Pure Java version (54L/1K).
1 | static <A> AutoCloseable tempSetThreadLocalIfNecessary(ThreadLocal<A> tl, A a) { |
2 | if (tl == null) null; |
3 | A prev = tl.get(); |
4 | if (eq(prev, a)) null; |
5 | tl.set(a); |
6 | ret autoCloseable { tl.set(prev); }; |
7 | } |
8 | |
9 | ifclass BetterThreadLocal |
10 | static <A> AutoCloseable tempSetThreadLocalIfNecessary(BetterThreadLocal<A> tl, A a) { |
11 | if (tl == null) null; |
12 | A prev = tl.get(); |
13 | if (eq(prev, a)) null; |
14 | tl.set(a); |
15 | ret autoCloseable { tl.set(prev); }; |
16 | } |
17 | endif |
Began life as a copy of #1012933
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031638 |
Snippet name: | tempSetThreadLocalIfNecessary - compares with existing value first |
Eternal ID of this version: | #1031638/5 |
Text MD5: | 37813ec326533b5934ba01eec4af343c |
Transpilation MD5: | 2b5e4f52301f81a4ff342a73f38f6f5b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-11-02 01:55:19 |
Source code size: | 464 bytes / 17 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 184 / 292 |
Version history: | 4 change(s) |
Referenced in: | [show references] |