Skip to content

Commit

Permalink
a little bit of thread safety, I hope
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 24, 2022
1 parent fa7dc2b commit 9924f1c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void wrapSleep(int changePriority, SleepRunnable sleep) throws Interrupte
}
}

public void enter() {
public synchronized void enter() {
try {
if (f.get(getContext()) != null) {
throw new IllegalStateException("Thread already set");
Expand All @@ -79,7 +79,7 @@ public void enter() {
}
}

public void leave() {
public synchronized void leave() {
try {
f.set(getContext(), null);
} catch (IllegalAccessException e) {
Expand All @@ -90,7 +90,12 @@ public void leave() {
@Override
public synchronized void closeContext() {
super.closeContext();
getContext().close();

// force on right thread to close
try {
f.set(getContext(), Thread.currentThread());
getContext().close();
} catch (Throwable ignored) {}
}

@Override
Expand Down

0 comments on commit 9924f1c

Please sign in to comment.