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
This commit is contained in:
nagai 2003-11-05 14:00:11 +00:00
Родитель 4dada1c8a2
Коммит ea03c3fc2c
7 изменённых файлов: 140 добавлений и 0 удалений

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

@ -1,3 +1,16 @@
Wed Nov 5 22:55:16 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* 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
Wed Nov 5 19:08:47 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Nov 5 19:08:47 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser::Switch::PlacedArgument::parse): * lib/optparse.rb (OptionParser::Switch::PlacedArgument::parse):

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

@ -323,6 +323,7 @@ freebsd*) LIBS="-lm $LIBS"
if test "$rb_cv_supplementary_lib_c_r" = yes; then if test "$rb_cv_supplementary_lib_c_r" = yes; then
MAINLIBS="-lc_r $MAINLIBS" MAINLIBS="-lc_r $MAINLIBS"
else else
AC_DEFINE(HAVE_LIBPTHREAD)
MAINLIBS="-pthread $MAINLIBS" MAINLIBS="-pthread $MAINLIBS"
CFLAGS="-D_THREAD_SAFE $CFLAGS" CFLAGS="-D_THREAD_SAFE $CFLAGS"
fi fi
@ -664,6 +665,11 @@ AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $rb_cv_stack_grow_dir)
dnl default value for $KANJI dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE" DEFAULT_KCODE="KCODE_NONE"
AC_ARG_WITH(pthread-ext,
[ --with-pthread-ext use pthread library on external modules ],
[AC_CHECK_LIB(pthread, pthread_mutex_trylock)
AC_DEFINE(USE_PTHREAD_EXTLIB)])
AC_ARG_WITH(default-kcode, AC_ARG_WITH(default-kcode,
[ --with-default-kcode=CODE specify default value for \$KCODE (utf8|euc|sjis|none)], [ --with-default-kcode=CODE specify default value for \$KCODE (utf8|euc|sjis|none)],
[case $withval in [case $withval in

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

@ -33,6 +33,10 @@
#include "st.h" #include "st.h"
#include "dln.h" #include "dln.h"
#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB)
#include <pthread.h>
#endif
#ifdef __APPLE__ #ifdef __APPLE__
#include <crt_externs.h> #include <crt_externs.h>
#endif #endif
@ -8604,6 +8608,11 @@ find_bad_fds(dst, src, max)
return test; return test;
} }
#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB)
static pthread_t thid;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
#endif
void void
rb_thread_schedule() rb_thread_schedule()
{ {
@ -8620,6 +8629,9 @@ rb_thread_schedule()
int n, max; int n, max;
int need_select = 0; int need_select = 0;
int select_timeout = 0; int select_timeout = 0;
#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB)
int st;
#endif
rb_thread_pending = 0; rb_thread_pending = 0;
if (curr_thread == curr_thread->next if (curr_thread == curr_thread->next
@ -8629,6 +8641,16 @@ rb_thread_schedule()
next = 0; next = 0;
curr = curr_thread; /* starting thread */ 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) { while (curr->status == THREAD_KILLED) {
curr = curr->prev; curr = curr->prev;
} }
@ -8826,12 +8848,22 @@ rb_thread_schedule()
} }
next->wait_for = 0; next->wait_for = 0;
if (next->status == THREAD_RUNNABLE && next == curr_thread) { 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; return;
} }
/* context switch */ /* context switch */
if (curr == curr_thread) { if (curr == curr_thread) {
if (THREAD_SAVE_CONTEXT(curr)) { if (THREAD_SAVE_CONTEXT(curr)) {
#if defined(HAVE_LIBPTHREAD) && defined(USE_PTHREAD_EXTLIB)
if (st != EBUSY) {
pthread_mutex_unlock(& mtx);
}
#endif
return; return;
} }
} }
@ -8841,9 +8873,19 @@ rb_thread_schedule()
if (!(next->flags & THREAD_TERMINATING)) { if (!(next->flags & THREAD_TERMINATING)) {
next->flags |= THREAD_TERMINATING; next->flags |= THREAD_TERMINATING;
/* terminate; execute ensure-clause if any */ /* 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); 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); rb_thread_restore_context(next, RESTORE_NORMAL);
} }

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

@ -29,5 +29,12 @@ directry of Ruby sources, please try something like as the followings.
$ rm Makefile $ rm Makefile
$ CONFIGURE_ARGS='--with-tcl-include=/usr/local/include/tcl8.3/ --with-tcllib=tcl8.3 --with-tklib=tk8.3 --enable-tcltk_stubs' ruby extconf.rb $ CONFIGURE_ARGS='--with-tcl-include=/usr/local/include/tcl8.3/ --with-tcllib=tcl8.3 --with-tklib=tk8.3 --enable-tcltk_stubs' ruby extconf.rb
*** ATTENTION ***
If your Tcl/Tk libraries are compiled with "pthread support", Ruby/Tk
may cause "Hang-up" or "Segmentation Fault" frequently. To avoid this
trouble, please try to use the '--with-pthread-ext' option of the
'configure' command and re-compile Ruby sources.
========================================================== ==========================================================
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

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

@ -4289,6 +4289,10 @@ class TkWindow<TkObject
self self
end end
def caret(keys=nil)
TkXIM.caret(path, keys)
end
def destroy def destroy
super super
children = [] children = []
@ -5400,6 +5404,9 @@ class TkMenu<TkWindow
configure_cmd 'postcommand', cmd configure_cmd 'postcommand', cmd
self self
end end
def set_focus
tk_call('tk_menuSetFocus', path)
end
def tearoffcommand(cmd=Proc.new) def tearoffcommand(cmd=Proc.new)
configure_cmd 'tearoffcommand', cmd configure_cmd 'tearoffcommand', cmd
self self

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

@ -284,6 +284,21 @@ class TkText<TkTextWin
self self
end end
def text_copy
# Tk8.4 feature
tk_call('tk_textCopy', @path)
end
def text_cut
# Tk8.4 feature
tk_call('tk_textCut', @path)
end
def text_paste
# Tk8.4 feature
tk_call('tk_textPaste', @path)
end
def tag_add(tag, index1, index2=None) def tag_add(tag, index1, index2=None)
tk_send 'tag', 'add', tag, index1, index2 tk_send 'tag', 'add', tag, index1, index2
self self

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

@ -706,6 +706,48 @@ install_sighandler(signum, handler)
} }
} }
static void
init_sigchld(sig)
int sig;
{
sighandler_t oldfunc;
#ifndef _WIN32
# ifdef HAVE_SIGPROCMASK
sigset_t mask;
# else
int mask;
# endif
#endif
#ifndef _WIN32
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&mask);
sigprocmask(SIG_BLOCK, &mask, &mask);
# else
mask = sigblock(~0);
# endif
#endif
oldfunc = ruby_signal(sig, SIG_DFL);
if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
ruby_signal(sig, oldfunc);
} else {
trap_list[sig] = 0;
}
#ifndef _WIN32
#ifdef HAVE_SIGPROCMASK
sigdelset(&mask, sig);
sigprocmask(SIG_SETMASK, &mask, NULL);
#else
mask &= ~sigmask(sig);
sigsetmask(mask);
#endif
trap_last_mask = mask;
#endif
}
void void
Init_signal() Init_signal()
{ {
@ -742,5 +784,13 @@ Init_signal()
#ifdef SIGPIPE #ifdef SIGPIPE
install_sighandler(SIGPIPE, sigpipe); install_sighandler(SIGPIPE, sigpipe);
#endif #endif
#ifdef SIGCLD
init_sigchld(SIGCLD);
#endif
#ifdef SIGCHLD
init_sigchld(SIGCHLD);
#endif
#endif /* MACOS_UNUSE_SIGNAL */ #endif /* MACOS_UNUSE_SIGNAL */
} }