From ea03c3fc2c0bfcf6351c3bce9496fd4607f4594a Mon Sep 17 00:00:00 2001 From: nagai Date: Wed, 5 Nov 2003 14:00:11 +0000 Subject: configure.in, eval.c, signal.c: : add '--with-pthread-ext' option to fix the pthread trouble on 'tcltklib' ext/tcltklib/README.1st: add the description of '--with-pthread-ext' ext/tk/lib/tktext.rb : add TkText#text_copy, text_cut, text_paste to support Tcl/Tk8.4's tk_textCopy, tk_textCut, tk_textPaste ext/tk/lib/tk.rb : add TkMenu#set_focus support Tcl/Tk's tk_menuSetFocus git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- eval.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 98e75e933b..f8543a41f9 100644 --- a/eval.c +++ b/eval.c @@ -33,6 +33,10 @@ #include "st.h" #include "dln.h" +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) +#include +#endif + #ifdef __APPLE__ #include #endif @@ -8604,6 +8608,11 @@ find_bad_fds(dst, src, max) return test; } +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) +static pthread_t thid; +static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; +#endif + void rb_thread_schedule() { @@ -8620,6 +8629,9 @@ rb_thread_schedule() int n, max; int need_select = 0; int select_timeout = 0; +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + int st; +#endif rb_thread_pending = 0; if (curr_thread == curr_thread->next @@ -8629,6 +8641,16 @@ rb_thread_schedule() next = 0; curr = curr_thread; /* starting thread */ +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + if ((st = pthread_mutex_trylock(&mtx)) == EBUSY) { + if (pthread_self() != thid) { + return; + } + } else { + thid = pthread_self(); + } +#endif + while (curr->status == THREAD_KILLED) { curr = curr->prev; } @@ -8826,12 +8848,22 @@ rb_thread_schedule() } next->wait_for = 0; if (next->status == THREAD_RUNNABLE && next == curr_thread) { +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + if (st != EBUSY) { + pthread_mutex_unlock(& mtx); + } +#endif return; } /* context switch */ if (curr == curr_thread) { if (THREAD_SAVE_CONTEXT(curr)) { +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + if (st != EBUSY) { + pthread_mutex_unlock(& mtx); + } +#endif return; } } @@ -8841,9 +8873,19 @@ rb_thread_schedule() if (!(next->flags & THREAD_TERMINATING)) { next->flags |= THREAD_TERMINATING; /* terminate; execute ensure-clause if any */ +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + if (st != EBUSY) { + pthread_mutex_unlock(& mtx); + } +#endif rb_thread_restore_context(next, RESTORE_FATAL); } } +#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB) + if (st != EBUSY) { + pthread_mutex_unlock(& mtx); + } +#endif rb_thread_restore_context(next, RESTORE_NORMAL); } -- cgit v1.2.3