forked from openjdk/jdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25313ba
commit 2bcc2e3
Showing
4 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/java.base/share/classes/jdk/internal/foreign/StructuredSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package jdk.internal.foreign; | ||
|
||
import jdk.internal.foreign.ConfinedSession.ConfinedResourceList; | ||
import jdk.internal.vm.StackableScope; | ||
import jdk.internal.vm.annotation.ForceInline; | ||
|
||
import java.util.Objects; | ||
|
||
public final class StructuredSession extends MemorySessionImpl { | ||
|
||
private final StackableScope stackableScope = new StackableScope() { }; | ||
|
||
public StructuredSession(Thread owner) { | ||
super(owner, new ConfinedResourceList()); | ||
stackableScope.push(); | ||
} | ||
|
||
public boolean isAccessibleBy(Thread thread) { | ||
Objects.requireNonNull(thread); | ||
return StackableScope.contains(stackableScope); | ||
} | ||
|
||
@Override | ||
@ForceInline | ||
public void acquire0() { | ||
checkValidState(); | ||
// do nothing | ||
} | ||
|
||
@Override | ||
@ForceInline | ||
public void release0() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
@ForceInline | ||
void checkThreadRaw() { | ||
if (Thread.currentThread() != owner && | ||
!StackableScope.contains(stackableScope)) { | ||
throw WRONG_THREAD; | ||
} | ||
} | ||
|
||
void justClose() { | ||
checkValidState(); | ||
if (!stackableScope.tryPop()) { | ||
throw new IllegalStateException("Cannot close"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters