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

21
LINES

< > BotCompany Repo | #1031845 // tempExternalMutexFor

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

Libraryless. Click here for Pure Java version (3296L/18K).

1  
// TODO: either put ExternalMutex in JavaX
2  
// or make externalMutexMap local
3  
static IAutoCloseableF0 tempExternalMutexFor(O o) {
4  
  var map = externalMutexMap();
5  
  synchronized(map) {
6  
    ExternalMutex mutex = map.get(o);
7  
    if (mutex == null)
8  
      map.put(o, mutex = new ExternalMutex);
9  
    var _mutex = mutex;
10  
    mutex.incRefCount();
11  
    ret new IAutoCloseableF0 {
12  
      public O get() { ret _mutex; }
13  
      public void close {
14  
        synchronized(map) {
15  
          if (_mutex.decRefCount() == 0)
16  
            map.remove(o);
17  
        }
18  
      }
19  
    };
20  
  }
21  
}

Author comment

Began life as a copy of #1031844

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031845
Snippet name: tempExternalMutexFor
Eternal ID of this version: #1031845/9
Text MD5: 28324940aa39091510c5b31dc6bf5c7e
Transpilation MD5: 106e4b5a388dc99f87e3bc457eeccfd9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-16 06:02:51
Source code size: 578 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 109 / 167
Version history: 8 change(s)
Referenced in: [show references]