summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-05 14:00:11 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-11-05 14:00:11 +0000
commitea03c3fc2c0bfcf6351c3bce9496fd4607f4594a (patch)
tree6c121bf51ead591584872b4674497d233f7b37b5 /eval.c
parent4dada1c8a20c0fab0e058d7cd934c1c011617049 (diff)
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
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c42
1 files changed, 42 insertions, 0 deletions
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 <pthread.h>
+#endif
+
#ifdef __APPLE__
#include <crt_externs.h>
#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);
}