mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <rpressler@openjdk.org> Co-authored-by: Alan Bateman <alanb@openjdk.org> Co-authored-by: Erik Österlund <eosterlund@openjdk.org> Co-authored-by: Andrew Haley <aph@openjdk.org> Co-authored-by: Rickard Bäckman <rbackman@openjdk.org> Co-authored-by: Markus Grönlund <mgronlun@openjdk.org> Co-authored-by: Leonid Mesnik <lmesnik@openjdk.org> Co-authored-by: Serguei Spitsyn <sspitsyn@openjdk.org> Co-authored-by: Chris Plummer <cjplummer@openjdk.org> Co-authored-by: Coleen Phillimore <coleenp@openjdk.org> Co-authored-by: Robbin Ehn <rehn@openjdk.org> Co-authored-by: Stefan Karlsson <stefank@openjdk.org> Co-authored-by: Thomas Schatzl <tschatzl@openjdk.org> Co-authored-by: Sergey Kuksenko <skuksenko@openjdk.org> Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
This commit is contained in:
parent
5212535a27
commit
9583e3657e
1133 changed files with 95935 additions and 8335 deletions
|
@ -26,6 +26,7 @@
|
|||
package java.io;
|
||||
|
||||
import java.util.Objects;
|
||||
import jdk.internal.misc.InternalLock;
|
||||
|
||||
/**
|
||||
* A {@code PushbackInputStream} adds
|
||||
|
@ -52,6 +53,8 @@ import java.util.Objects;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class PushbackInputStream extends FilterInputStream {
|
||||
private final InternalLock closeLock;
|
||||
|
||||
/**
|
||||
* The pushback buffer.
|
||||
* @since 1.1
|
||||
|
@ -95,6 +98,13 @@ public class PushbackInputStream extends FilterInputStream {
|
|||
}
|
||||
this.buf = new byte[size];
|
||||
this.pos = size;
|
||||
|
||||
// use monitors when PushbackInputStream is sub-classed
|
||||
if (getClass() == PushbackInputStream.class) {
|
||||
closeLock = InternalLock.newLockOrNull();
|
||||
} else {
|
||||
closeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -373,11 +383,26 @@ public class PushbackInputStream extends FilterInputStream {
|
|||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public synchronized void close() throws IOException {
|
||||
if (in == null)
|
||||
return;
|
||||
in.close();
|
||||
in = null;
|
||||
buf = null;
|
||||
public void close() throws IOException {
|
||||
if (closeLock != null) {
|
||||
closeLock.lock();
|
||||
try {
|
||||
implClose();
|
||||
} finally {
|
||||
closeLock.unlock();
|
||||
}
|
||||
} else {
|
||||
synchronized (this) {
|
||||
implClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void implClose() throws IOException {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
in = null;
|
||||
buf = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue