< prev index next >

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

Print this page
rev 59105 : imported patch corelibs


  24  */
  25 
  26 #include <sys/types.h>
  27 #include <string.h>
  28 #include "jni.h"
  29 #include "jni_util.h"
  30 #include "jvm.h"
  31 #include "jlong.h"
  32 #include "sun_nio_ch_NativeThread.h"
  33 #include "nio_util.h"
  34 #include <signal.h>
  35 
  36 #ifdef __linux__
  37   #include <pthread.h>
  38   /* Also defined in net/linux_close.c */
  39   #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
  40 #elif defined(_AIX)
  41   #include <pthread.h>
  42   /* Also defined in net/aix_close.c */
  43   #define INTERRUPT_SIGNAL (SIGRTMAX - 1)
  44 #elif defined(__solaris__)
  45   #include <thread.h>
  46   #define INTERRUPT_SIGNAL (SIGRTMAX - 2)
  47 #elif defined(_ALLBSD_SOURCE)
  48   #include <pthread.h>
  49   /* Also defined in net/bsd_close.c */
  50   #define INTERRUPT_SIGNAL SIGIO
  51 #else
  52   #error "missing platform-specific definition here"
  53 #endif
  54 
  55 static void
  56 nullHandler(int sig)
  57 {
  58 }
  59 
  60 JNIEXPORT void JNICALL
  61 Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
  62 {
  63     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
  64      * handler previously installed by <platform>_close.c, but that's okay
  65      * since neither handler actually does anything.  We install our own
  66      * handler here simply out of paranoia; ultimately the two mechanisms
  67      * should somehow be unified, perhaps within the VM.
  68      */
  69 
  70     sigset_t ss;
  71     struct sigaction sa, osa;
  72     sa.sa_handler = nullHandler;
  73     sa.sa_flags = 0;
  74     sigemptyset(&sa.sa_mask);
  75     if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
  76         JNU_ThrowIOExceptionWithLastError(env, "sigaction");
  77 }
  78 
  79 JNIEXPORT jlong JNICALL
  80 Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
  81 {
  82 #ifdef __solaris__
  83     return (jlong)thr_self();
  84 #else
  85     return (jlong)pthread_self();
  86 #endif
  87 }
  88 
  89 JNIEXPORT void JNICALL
  90 Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
  91 {
  92     int ret;
  93 #ifdef __solaris__
  94     ret = thr_kill((thread_t)thread, INTERRUPT_SIGNAL);
  95 #else
  96     ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);
  97 #endif
  98 #ifdef MACOSX
  99     if (ret != 0 && ret != ESRCH)
 100 #else
 101     if (ret != 0)
 102 #endif
 103         JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
 104 }


  24  */
  25 
  26 #include <sys/types.h>
  27 #include <string.h>
  28 #include "jni.h"
  29 #include "jni_util.h"
  30 #include "jvm.h"
  31 #include "jlong.h"
  32 #include "sun_nio_ch_NativeThread.h"
  33 #include "nio_util.h"
  34 #include <signal.h>
  35 
  36 #ifdef __linux__
  37   #include <pthread.h>
  38   /* Also defined in net/linux_close.c */
  39   #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
  40 #elif defined(_AIX)
  41   #include <pthread.h>
  42   /* Also defined in net/aix_close.c */
  43   #define INTERRUPT_SIGNAL (SIGRTMAX - 1)



  44 #elif defined(_ALLBSD_SOURCE)
  45   #include <pthread.h>
  46   /* Also defined in net/bsd_close.c */
  47   #define INTERRUPT_SIGNAL SIGIO
  48 #else
  49   #error "missing platform-specific definition here"
  50 #endif
  51 
  52 static void
  53 nullHandler(int sig)
  54 {
  55 }
  56 
  57 JNIEXPORT void JNICALL
  58 Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
  59 {
  60     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
  61      * handler previously installed by <platform>_close.c, but that's okay
  62      * since neither handler actually does anything.  We install our own
  63      * handler here simply out of paranoia; ultimately the two mechanisms
  64      * should somehow be unified, perhaps within the VM.
  65      */
  66 
  67     sigset_t ss;
  68     struct sigaction sa, osa;
  69     sa.sa_handler = nullHandler;
  70     sa.sa_flags = 0;
  71     sigemptyset(&sa.sa_mask);
  72     if (sigaction(INTERRUPT_SIGNAL, &sa, &osa) < 0)
  73         JNU_ThrowIOExceptionWithLastError(env, "sigaction");
  74 }
  75 
  76 JNIEXPORT jlong JNICALL
  77 Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
  78 {



  79     return (jlong)pthread_self();

  80 }
  81 
  82 JNIEXPORT void JNICALL
  83 Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
  84 {
  85     int ret;



  86     ret = pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL);

  87 #ifdef MACOSX
  88     if (ret != 0 && ret != ESRCH)
  89 #else
  90     if (ret != 0)
  91 #endif
  92         JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
  93 }
< prev index next >