Skip to content

Commit

Permalink
* eval.c (thread_timer): use timer by sub-thread and nanosleep.
Browse files Browse the repository at this point in the history
  [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
  • Loading branch information
matz committed Dec 13, 2003
1 parent fe7c38c commit 6a3f682
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 20 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Sat Dec 13 18:09:42 2003 Yukihiro Matsumoto <[email protected]>

* 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 <[email protected]>

* eval.c (proc_alloc): cache the created object at first time.
Expand Down
82 changes: 67 additions & 15 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6a3f682

Please sign in to comment.