* eval.c (thread_timer): use timer by sub-thread and nanosleep.

[ruby-talk:87519]

* gc.c (Init_stack): no stack adjustment for THREAD_SAFE.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-12-13 09:13:39 +00:00
Родитель fe7c38c862
Коммит 6a3f682ff7
3 изменённых файлов: 76 добавлений и 20 удалений

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

@ -1,3 +1,10 @@
Sat Dec 13 18:09:42 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (thread_timer): use timer by sub-thread and nanosleep.
[ruby-talk:87519]
* gc.c (Init_stack): no stack adjustment for THREAD_SAFE.
Sat Dec 13 17:17:59 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (proc_alloc): cache the created object at first time.

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

@ -9486,7 +9486,63 @@ rb_thread_alloc(klass)
return th;
}
#if defined(HAVE_SETITIMER)
static int thread_init = 0;
#if defined(HAVE_LIBPTHREAD) && defined(_REENTRANT)
# define PTHREAD_TIMER
#endif
#if defined(POSIX_SIGNAL)
# define ruby_signal(x,y) posix_signal((x), (y))
#else
# define ruby_signal(x,y) signal((x), (y))
#endif
#if defined(PTHREAD_TIMER)
static pthread_t time_thread;
static void
catch_timer(sig)
int sig;
{
#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
signal(sig, catch_timer);
#endif
rb_thread_schedule();
}
static void*
thread_timer(dummy)
void *dummy;
{
struct timespec req, rem;
for (;;) {
if (!rb_thread_critical) {
if (rb_trap_immediate) {
pthread_kill(ruby_thid, SIGVTALRM);
}
else {
rb_thread_pending = 1;
}
req.tv_sec = 0;
req.tv_nsec = 10000000;
nanosleep(&req, &rem);
}
}
}
void
rb_thread_start_timer()
{
}
void
rb_thread_stop_timer()
{
}
#elif defined(HAVE_SETITIMER)
static void
catch_timer(sig)
int sig;
@ -9501,12 +9557,6 @@ catch_timer(sig)
else rb_thread_pending = 1;
}
}
#else
int rb_thread_tick = THREAD_TICK;
#endif
#if defined(HAVE_SETITIMER)
static int thread_init = 0;
void
rb_thread_start_timer()
@ -9531,6 +9581,8 @@ rb_thread_stop_timer()
tval.it_value = tval.it_interval;
setitimer(ITIMER_VIRTUAL, &tval, NULL);
}
#else
int rb_thread_tick = THREAD_TICK;
#endif
static VALUE
@ -9550,18 +9602,18 @@ rb_thread_start_0(fn, arg, th)
"can't start a new thread (frozen ThreadGroup)");
}
#if defined(HAVE_SETITIMER)
if (!thread_init) {
#ifdef POSIX_SIGNAL
posix_signal(SIGVTALRM, catch_timer);
#else
signal(SIGVTALRM, catch_timer);
#endif
thread_init = 1;
#if defined(HAVE_SETITIMER) || defined(PTHREAD_TIMER)
ruby_signal(SIGVTALRM, catch_timer);
#ifdef PTHREAD_TIMER
pthread_create(&time_thread, 0, thread_timer, 0);
#else
rb_thread_start_timer();
}
#endif
#endif
}
if (THREAD_SAVE_CONTEXT(curr_thread)) {
return thread;

7
gc.c
Просмотреть файл

@ -423,11 +423,11 @@ stack_growup_p(addr)
# define STACK_UPPER(x, a, b) (stack_growup_p(x) ? a : b)
#endif
#define GC_WARTER_MARK 512
#define GC_WATER_MARK 512
#define CHECK_STACK(ret) do {\
SET_STACK_END;\
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WARTER_MARK);\
(ret) = (STACK_LENGTH > STACK_LEVEL_MAX + GC_WATER_MARK);\
} while (0)
int
@ -1393,9 +1393,6 @@ Init_stack(addr)
if (STACK_LEVEL_MAX > IA64_MAGIC_STACK_LIMIT)
STACK_LEVEL_MAX = IA64_MAGIC_STACK_LIMIT;
#endif
#ifdef _THREAD_SAFE
STACK_LEVEL_MAX /= 4;
#endif
#endif
}