< prev index next >

src/java.base/unix/native/libnio/ch/NativeThread.c

Print this page

55 JNIEXPORT void JNICALL
56 Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
57 {
58     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
59      * handler previously installed by <platform>_close.c, but that's okay
60      * since neither handler actually does anything.  We install our own
61      * handler here simply out of paranoia; ultimately the two mechanisms
62      * should somehow be unified, perhaps within the VM.
63      */
64 
65     sigset_t ss;
66     struct sigaction sa, osa;
67     sa.sa_handler = nullHandler;
68     sa.sa_flags = 0;
69     sigemptyset(&sa.sa_mask);
70     if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
71         JNU_ThrowIOExceptionWithLastError(env, "sigaction");
72 }
73 
74 JNIEXPORT jlong JNICALL
75 Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
76 {
77     return (jlong)pthread_self();
78 }
79 
80 JNIEXPORT void JNICALL
81 Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
82 {
83     int ret;
84     ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
85 #ifdef MACOSX
86     if (ret != 0 && ret != ESRCH)
87 #else
88     if (ret != 0)
89 #endif
90         JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
91 }

55 JNIEXPORT void JNICALL
56 Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
57 {
58     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
59      * handler previously installed by <platform>_close.c, but that's okay
60      * since neither handler actually does anything.  We install our own
61      * handler here simply out of paranoia; ultimately the two mechanisms
62      * should somehow be unified, perhaps within the VM.
63      */
64 
65     sigset_t ss;
66     struct sigaction sa, osa;
67     sa.sa_handler = nullHandler;
68     sa.sa_flags = 0;
69     sigemptyset(&sa.sa_mask);
70     if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
71         JNU_ThrowIOExceptionWithLastError(env, "sigaction");
72 }
73 
74 JNIEXPORT jlong JNICALL
75 Java_sun_nio_ch_NativeThread_current0(JNIEnv *env, jclass cl)
76 {
77     return (jlong)pthread_self();
78 }
79 
80 JNIEXPORT void JNICALL
81 Java_sun_nio_ch_NativeThread_signal0(JNIEnv *env, jclass cl, jlong thread)
82 {
83     int ret;
84     ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
85 #ifdef MACOSX
86     if (ret != 0 && ret != ESRCH)
87 #else
88     if (ret != 0)
89 #endif
90         JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
91 }
< prev index next >