提交 f2f6f927 编写于 作者: A alanb

7133499: (fc) FileChannel.read not preempted by asynchronous close on OS X

Reviewed-by: chegar
上级 6aff2fdc
...@@ -110,7 +110,7 @@ public class FileChannelImpl ...@@ -110,7 +110,7 @@ public class FileChannelImpl
} }
} }
nd.preClose(fd); // signal any threads blocked on this channel
threads.signalAndWait(); threads.signalAndWait();
if (parent != null) { if (parent != null) {
......
...@@ -82,8 +82,9 @@ class NativeThreadSet { ...@@ -82,8 +82,9 @@ class NativeThreadSet {
// Signals all threads in this set. // Signals all threads in this set.
// //
void signalAndWait() { synchronized void signalAndWait() {
synchronized (this) { boolean interrupted = false;
while (used > 0) {
int u = used; int u = used;
int n = elts.length; int n = elts.length;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
...@@ -96,16 +97,15 @@ class NativeThreadSet { ...@@ -96,16 +97,15 @@ class NativeThreadSet {
break; break;
} }
waitingToEmpty = true; waitingToEmpty = true;
boolean interrupted = false; try {
while (used > 0) { wait(50);
try { } catch (InterruptedException e) {
wait(); interrupted = true;
} catch (InterruptedException e) { } finally {
interrupted = true; waitingToEmpty = false;
}
} }
if (interrupted)
Thread.currentThread().interrupt();
} }
if (interrupted)
Thread.currentThread().interrupt();
} }
} }
...@@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl ...@@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl
invalidateAllLocks(); invalidateAllLocks();
// signal any threads blocked on this channel // signal any threads blocked on this channel
nd.preClose(fdObj);
threads.signalAndWait(); threads.signalAndWait();
// wait until all async I/O operations have completely gracefully // wait until all async I/O operations have completely gracefully
......
...@@ -32,27 +32,32 @@ ...@@ -32,27 +32,32 @@
#include "sun_nio_ch_NativeThread.h" #include "sun_nio_ch_NativeThread.h"
#include "nio_util.h" #include "nio_util.h"
#ifdef __linux__ #ifdef __linux__
#include <pthread.h> #include <pthread.h>
#include <sys/signal.h> #include <sys/signal.h>
/* Also defined in net/linux_close.c */
/* Also defined in src/solaris/native/java/net/linux_close.c */ #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
#define INTERRUPT_SIGNAL (__SIGRTMAX - 2) #elif __solaris__
#include <thread.h>
#include <signal.h>
#define INTERRUPT_SIGNAL (SIGRTMAX - 2)
#elif _ALLBSD_SOURCE
#include <pthread.h>
#include <signal.h>
/* Also defined in net/bsd_close.c */
#define INTERRUPT_SIGNAL SIGIO
#else
#error "missing platform-specific definition here"
#endif
static void static void
nullHandler(int sig) nullHandler(int sig)
{ {
} }
#endif
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
{ {
#ifdef __linux__
/* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the /* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
* handler previously installed by java/net/linux_close.c, but that's okay * handler previously installed by java/net/linux_close.c, but that's okay
* since neither handler actually does anything. We install our own * since neither handler actually does anything. We install our own
...@@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl) ...@@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0) if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
JNU_ThrowIOExceptionWithLastError(env, "sigaction"); JNU_ThrowIOExceptionWithLastError(env, "sigaction");
#endif
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl) Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
{ {
#ifdef __linux__ #ifdef __solaris__
return (long)pthread_self(); return (jlong)thr_self();
#else #else
return -1; return (jlong)pthread_self();
#endif #endif
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread) Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
{ {
#ifdef __linux__ int ret;
if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL)) #ifdef __solaris__
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed"); ret = thr_kill((thread_t)thread, INTERRUPT_SIGNAL);
#else
ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
#endif #endif
if (ret != 0)
JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
} }
...@@ -183,11 +183,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all ...@@ -183,11 +183,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all
# 6963118 # 6963118
java/nio/channels/Selector/Wakeup.java windows-all java/nio/channels/Selector/Wakeup.java windows-all
# 7133499, 7133497
java/nio/channels/AsyncCloseAndInterrupt.java macosx-all
java/nio/channels/AsynchronousFileChannel/Lock.java macosx-all
java/nio/channels/FileChannel/Transfer.java macosx-all
# 7141822 # 7141822
java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册