* eval.c (ruby_native_thread_kill): call pthread_kill() to send a

signal to ruby's native thread
* ruby.h: add definition of ruby_native_thread_kill()
* signal.c (sigsend_to_ruby_thread): send the signal to ruby's native
  thread ([ruby-dev:25744], [ruby-dev:25754]), and set signal mask to
  the current native thread


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2005-03-02 08:11:28 +00:00
Родитель 3124427ccb
Коммит 9815949157
4 изменённых файлов: 60 добавлений и 10 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Wed Mar 2 16:59:50 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* eval.c (ruby_native_thread_kill): call pthread_kill() to send a
signal to ruby's native thread
* ruby.h: add definition of ruby_native_thread_kill()
* signal.c (sigsend_to_ruby_thread): send the signal to ruby's
native thread ([ruby-dev:25744], [ruby-dev:25754]), and set
signal mask to the current native thread
Wed Mar 2 16:03:08 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Wed Mar 2 16:03:08 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c: enforce thread-check and exception-handling to * ext/tk/tcltklib.c: enforce thread-check and exception-handling to

12
eval.c
Просмотреть файл

@ -1238,9 +1238,19 @@ void Init_ext _((void));
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
static rb_nativethread_t ruby_thid; static rb_nativethread_t ruby_thid;
int int
is_ruby_native_thread() { is_ruby_native_thread()
{
return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT()); return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT());
} }
# ifdef HAVE_NATIVETHREAD_KILL
void
ruby_native_thread_kill(sig)
int sig;
{
NATIVETHREAD_KILL(ruby_thid, sig);
}
# endif
#endif #endif
NORETURN(static void rb_thread_start_1 _((void))); NORETURN(static void rb_thread_start_1 _((void)));

8
ruby.h
Просмотреть файл

@ -694,6 +694,9 @@ typedef pthread_t rb_nativethread_t;
# define NATIVETHREAD_CURRENT() pthread_self() # define NATIVETHREAD_CURRENT() pthread_self()
# define NATIVETHREAD_EQUAL(t1,t2) pthread_equal((t1),(t2)) # define NATIVETHREAD_EQUAL(t1,t2) pthread_equal((t1),(t2))
# define HAVE_NATIVETHREAD # define HAVE_NATIVETHREAD
# define NATIVETHREAD_KILL(th,sig) pthread_kill((th),(sig))
# define HAVE_NATIVETHREAD_KILL
#elif defined(_WIN32) || defined(_WIN32_WCE) #elif defined(_WIN32) || defined(_WIN32_WCE)
typedef DWORD rb_nativethread_t; typedef DWORD rb_nativethread_t;
# define NATIVETHREAD_CURRENT() GetCurrentThreadId() # define NATIVETHREAD_CURRENT() GetCurrentThreadId()
@ -701,10 +704,13 @@ typedef DWORD rb_nativethread_t;
# define HAVE_NATIVETHREAD # define HAVE_NATIVETHREAD
#endif #endif
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
RUBY_EXTERN int is_ruby_native_thread(); int is_ruby_native_thread _((void));
#else #else
#define is_ruby_native_thread() (1) #define is_ruby_native_thread() (1)
#endif #endif
#ifdef HAVE_NATIVETHREAD_KILL
void ruby_native_thread_kill _((int));
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
} /* extern "C" { */ } /* extern "C" { */

Просмотреть файл

@ -436,6 +436,29 @@ signal_exec(sig)
} }
} }
static void
sigsend_to_ruby_thread(sig)
int sig;
{
#ifdef HAVE_NATIVETHREAD_KILL
# ifdef HAVE_SIGPROCMASK
sigset_t mask, old_mask;
# else
int mask, old_mask;
# endif
#ifdef HAVE_SIGPROCMASK
sigfillset(&mask);
sigprocmask(SIG_BLOCK, &mask, &old_mask);
#else
mask = sigblock(~0);
sigsetmask(mask);
#endif
ruby_native_thread_kill(sig);
#endif
}
static RETSIGTYPE sighandler _((int)); static RETSIGTYPE sighandler _((int));
static RETSIGTYPE static RETSIGTYPE
sighandler(sig) sighandler(sig)
@ -450,9 +473,9 @@ sighandler(sig)
rb_bug("trap_handler: Bad signal %d", sig); rb_bug("trap_handler: Bad signal %d", sig);
} }
#ifdef HAVE_NATIVETHREAD #if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) { if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
/* ignore signals on non-Ruby native thread */ sigsend_to_ruby_thread(sig);
return; return;
} }
#endif #endif
@ -481,9 +504,9 @@ static RETSIGTYPE
sigbus(sig) sigbus(sig)
int sig; int sig;
{ {
#ifdef HAVE_NATIVETHREAD #if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) { if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
/* ignore signals on non-Ruby native thread */ sigsend_to_ruby_thread(sig);
return; return;
} }
#endif #endif
@ -498,9 +521,9 @@ static RETSIGTYPE
sigsegv(sig) sigsegv(sig)
int sig; int sig;
{ {
#ifdef HAVE_NATIVETHREAD #if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) { if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
/* ignore signals on non-Ruby native thread */ sigsend_to_ruby_thread(sig);
return; return;
} }
#endif #endif
@ -570,9 +593,9 @@ static RETSIGTYPE
sigexit(sig) sigexit(sig)
int sig; int sig;
{ {
#ifdef HAVE_NATIVETHREAD #if defined(HAVE_NATIVETHREAD) && defined(HAVE_NATIVETHREAD_KILL)
if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) { if (!is_ruby_native_thread() && !rb_trap_accept_nativethreads[sig]) {
/* ignore signals on non-Ruby native thread */ sigsend_to_ruby_thread(sig);
return; return;
} }
#endif #endif