8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks

Reviewed-by: dfuchs, bpb, martin
This commit is contained in:
Alan Bateman 2019-04-25 10:41:49 +01:00
parent 8322ce2e6b
commit 2998236d83
13 changed files with 1762 additions and 487 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,13 +23,15 @@
* questions.
*/
/*
*/
package java.nio.channels.spi;
import java.io.IOException;
import java.nio.channels.*;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.InterruptibleChannel;
import java.util.concurrent.locks.ReentrantLock;
import jdk.internal.access.SharedSecrets;
import sun.nio.ch.Interruptible;
@ -84,8 +86,7 @@ import sun.nio.ch.Interruptible;
public abstract class AbstractInterruptibleChannel
implements Channel, InterruptibleChannel
{
private final Object closeLock = new Object();
private final ReentrantLock closeLock = new ReentrantLock();
private volatile boolean closed;
/**
@ -105,11 +106,14 @@ public abstract class AbstractInterruptibleChannel
* If an I/O error occurs
*/
public final void close() throws IOException {
synchronized (closeLock) {
closeLock.lock();
try {
if (closed)
return;
closed = true;
implCloseChannel();
} finally {
closeLock.unlock();
}
}
@ -153,7 +157,8 @@ public abstract class AbstractInterruptibleChannel
if (interruptor == null) {
interruptor = new Interruptible() {
public void interrupt(Thread target) {
synchronized (closeLock) {
closeLock.lock();
try {
if (closed)
return;
closed = true;
@ -161,6 +166,8 @@ public abstract class AbstractInterruptibleChannel
try {
AbstractInterruptibleChannel.this.implCloseChannel();
} catch (IOException x) { }
} finally {
closeLock.unlock();
}
}};
}