Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

17
LINES

< > BotCompany Repo | #1031638 // tempSetThreadLocalIfNecessary - compares with existing value first

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (54L/1K).

static <A> AutoCloseable tempSetThreadLocalIfNecessary(ThreadLocal<A> tl, A a) {
  if (tl == null) null;
  A prev = tl.get();
  if (eq(prev, a)) null;
  tl.set(a);
  ret autoCloseable { tl.set(prev); };
}

ifclass BetterThreadLocal
static <A> AutoCloseable tempSetThreadLocalIfNecessary(BetterThreadLocal<A> tl, A a) {
  if (tl == null) null;
  A prev = tl.get();
  if (eq(prev, a)) null;
  tl.set(a);
  ret autoCloseable { tl.set(prev); };
}
endif

Author comment

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: 68 / 133
Version history: 4 change(s)
Referenced in: [show references]