1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* configure.in: always check existence of the pthread library

* ruby.h: define macros for ruby's native thread check
* eval.c: add ruby's native thread check
* gc.c: ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-11-20 03:50:32 +00:00
parent 531022ace3
commit 340a511fdf
5 changed files with 93 additions and 83 deletions

View file

@ -1,3 +1,13 @@
Thu Nov 20 12:42:47 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* configure.in: always check existence of the pthread library
* ruby.h: define macros for ruby's native thread check
* eval.c: add ruby's native thread check
* gc.c: ditto
Wed Nov 19 14:45:18 2003 Minero Aoki <aamine@loveruby.net>
* lib/net/http.rb (to_ary): print more friendly warning message.

View file

@ -662,52 +662,58 @@ int main()
], rb_cv_stack_grow_dir=-1, rb_cv_stack_grow_dir=+1, rb_cv_stack_grow_dir=0)])
AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $rb_cv_stack_grow_dir)
dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE"
AC_ARG_WITH(pthread-ext,
[ --with-pthread-ext use pthread library on external modules ],
[AC_DEFINE(USE_PTHREAD_EXTLIB)
AC_CHECK_LIB(pthread, pthread_mutex_init,
rb_use_pthread_ext=yes, rb_use_pthread_ext=no)
if test "$rb_use_pthread_ext" = "no"; then
AC_CHECK_LIB(pthread, __pthread_mutex_init,
rb_use_pthread_ext=yes, rb_use_pthread_ext=no)
fi
if test "$rb_use_pthread_ext" = "yes"; then
LIBS="-lpthread $LIBS"
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
else
AC_CHECK_LIB(pthreads, pthread_mutex_init,
rb_use_pthread_ext=yes, rb_use_pthread_ext=no)
if test "$rb_use_pthread_ext" = "yes"; then
LIBS="-lpthreads $LIBS"
AC_CHECK_LIB(pthread, pthread_mutex_init,
rb_with_pthread=yes, rb_with_pthread=no)
if test "$rb_with_pthread" = "no"; then
AC_CHECK_LIB(pthread, __pthread_mutex_init,
rb_with_pthread=yes, rb_with_pthread=no)
fi
if test "$rb_with_pthread" = "yes"; then
LIBS="-lpthread $LIBS"
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
else
AC_CHECK_LIB(pthreads, pthread_mutex_init,
rb_with_pthread=yes, rb_with_pthread=no)
if test "$rb_with_pthread" = "yes"; then
LIBS="-lpthreads $LIBS"
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
else
AC_CHECK_LIB(c, pthread_mutex_init,
rb_with_pthread=yes, rb_with_pthread=no)
if test "$rb_with_pthread" = "yes"; then
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
else
AC_CHECK_LIB(c_r, pthread_mutex_init,
rb_with_pthread=yes, rb_with_pthread=no)
if test "$rb_with_pthread" = "yes"; then
if test "$with_libc_r" = "yes"; then
if test "$rb_cv_supplementary_lib_c_r" = "yes"; then
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
MAINLIBS="-pthread $MAINLIBS"
fi
else
MAINLIBS="-pthread $MAINLIBS"
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
else
AC_CHECK_LIB(c_r, pthread_mutex_init,
rb_use_pthread_ext=yes, rb_use_pthread_ext=no)
if test "$rb_use_pthread_ext" = "yes"; then
if test "$with_libc_r" = "yes"; then
if test "$rb_cv_supplementary_lib_c_r" = "yes"; then
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
MAINLIBS="-pthread $MAINLIBS"
fi
else
MAINLIBS="-pthread $MAINLIBS"
AC_DEFINE(_REENTRANT)
AC_DEFINE(_THREAD_SAFE)
AC_DEFINE(HAVE_LIBPTHREAD)
fi
fi
fi
else
AC_MSG_WARN("Don't know how to find pthread library on your system -- thread support disabled")
fi
])
fi
fi
fi
dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE"
AC_ARG_WITH(default-kcode,
[ --with-default-kcode=CODE specify default value for \$KCODE (utf8|euc|sjis|none)],

58
eval.c
View file

@ -33,10 +33,6 @@
#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
@ -1161,6 +1157,14 @@ void Init_stack _((void*));
void Init_heap _((void));
void Init_ext _((void));
#ifdef HAVE_NATIVETHREAD
static rb_nativethread_t ruby_thid;
int
is_ruby_native_thread() {
return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT());
}
#endif
void
ruby_init()
{
@ -1172,6 +1176,9 @@ ruby_init()
if (initialized)
return;
initialized = 1;
#ifdef HAVE_NATIVETHREAD
ruby_thid = NATIVETHREAD_CURRENT();
#endif
ruby_frame = top_frame = &frame;
ruby_iter = &iter;
@ -8647,11 +8654,6 @@ 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()
{
@ -8668,10 +8670,12 @@ 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
#ifdef HAVE_NATIVETHREAD
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on rb_thread_schedule()");
}
#endif
rb_thread_pending = 0;
if (curr_thread == curr_thread->next
&& curr_thread->status == THREAD_RUNNABLE)
@ -8680,16 +8684,6 @@ 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;
}
@ -8887,22 +8881,12 @@ 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;
}
}
@ -8912,19 +8896,9 @@ 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);
}

5
gc.c
View file

@ -1216,6 +1216,11 @@ rb_gc()
jmp_buf save_regs_gc_mark;
SET_STACK_END;
#ifdef HAVE_NATIVETHREAD
if (!is_ruby_native_thread()) {
rb_bug("cross-thread violation on rb_gc()");
}
#endif
if (dont_gc || during_gc) {
if (!freelist) {
add_heap();

15
ruby.h
View file

@ -671,6 +671,21 @@ rb_special_const_p(obj)
static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
#endif
#if defined(HAVE_LIBPTHREAD)
typedef pthread_t rb_nativethread_t;
# define NATIVETHREAD_CURRENT() pthread_self()
# define NATIVETHREAD_EQUAL(t1,t2) pthread_equal((t1),(t2))
# define HAVE_NATIVETHREAD
#elif defined(_WIN32) || defined(_WIN32_WCE) || defined(__CYGWIN__)
typedef DWORD rb_nativethread_t;
# define NATIVETHREAD_CURRENT() GetCurrentThreadId()
# define NATIVETHREAD_EQUAL(t1,t2) ((t1) == (t2))
# define HAVE_NATIVETHREAD
#endif
#ifdef HAVE_NATIVETHREAD
RUBY_EXTERN int is_ruby_native_thread();
#endif
#if defined(__cplusplus)
} /* extern "C" { */
#endif