* thread.c, vm_core.h: add manual priority support
using time slice. if you enable USE_NATIVE_THREAD_PRIORITY macro, this mechanism is ignored. [ruby-dev:33124] * thread_pthread.c, thread_win32.c: ditto. * test/ruby/test_thread.rb: fix test parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81719aff65
commit
16612b360b
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Wed Aug 13 16:40:57 2008 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* thread.c, vm_core.h: add manual priority support
|
||||||
|
using time slice. if you enable USE_NATIVE_THREAD_PRIORITY
|
||||||
|
macro, this mechanism is ignored. [ruby-dev:33124]
|
||||||
|
|
||||||
|
* thread_pthread.c, thread_win32.c: ditto.
|
||||||
|
|
||||||
|
* test/ruby/test_thread.rb: fix test parameter.
|
||||||
|
|
||||||
Wed Aug 13 16:02:14 2008 Shugo Maeda <shugo@ruby-lang.org>
|
Wed Aug 13 16:02:14 2008 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* object.c (rb_obj_untrusted): new method Object#untrusted?.
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
|
||||||
|
@ -126,7 +126,7 @@ class TestThread < Test::Unit::TestCase
|
|||||||
sleep 0.5
|
sleep 0.5
|
||||||
t1.kill
|
t1.kill
|
||||||
t2.kill
|
t2.kill
|
||||||
assert(c1 > c2 * 2, "[ruby-dev:33124]")
|
assert(c1 > c2 * 1.5, "[ruby-dev:33124]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new
|
def test_new
|
||||||
|
39
thread.c
39
thread.c
@ -48,6 +48,12 @@
|
|||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
|
||||||
|
#ifndef USE_NATIVE_THREAD_PRIORITY
|
||||||
|
#define USE_NATIVE_THREAD_PRIORITY 0
|
||||||
|
#define RUBY_THREAD_PRIORITY_MAX 3
|
||||||
|
#define RUBY_THREAD_PRIORITY_MIN -3
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef THREAD_DEBUG
|
#ifndef THREAD_DEBUG
|
||||||
#define THREAD_DEBUG 0
|
#define THREAD_DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
@ -996,8 +1002,26 @@ rb_thread_execute_interrupts(rb_thread_t *th)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (timer_interrupt) {
|
if (timer_interrupt) {
|
||||||
|
#if USE_NATIVE_THREAD_PRIORITY
|
||||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
||||||
rb_thread_schedule();
|
rb_thread_schedule();
|
||||||
|
#else
|
||||||
|
if (th->slice > 0) {
|
||||||
|
th->slice--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reschedule:
|
||||||
|
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
||||||
|
rb_thread_schedule();
|
||||||
|
if (th->slice < 0) {
|
||||||
|
th->slice++;
|
||||||
|
goto reschedule;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
th->slice = th->priority;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1847,12 +1871,25 @@ rb_thread_priority_set(VALUE thread, VALUE prio)
|
|||||||
{
|
{
|
||||||
rb_thread_t *th;
|
rb_thread_t *th;
|
||||||
GetThreadPtr(thread, th);
|
GetThreadPtr(thread, th);
|
||||||
|
int priority;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
|
||||||
|
#if USE_NATIVE_THREAD_PRIORITY
|
||||||
th->priority = NUM2INT(prio);
|
th->priority = NUM2INT(prio);
|
||||||
native_thread_apply_priority(th);
|
native_thread_apply_priority(th);
|
||||||
return prio;
|
#else
|
||||||
|
priority = NUM2INT(prio);
|
||||||
|
if (priority > RUBY_THREAD_PRIORITY_MAX) {
|
||||||
|
priority = RUBY_THREAD_PRIORITY_MAX;
|
||||||
|
}
|
||||||
|
else if (priority < RUBY_THREAD_PRIORITY_MIN) {
|
||||||
|
priority = RUBY_THREAD_PRIORITY_MIN;
|
||||||
|
}
|
||||||
|
th->priority = priority;
|
||||||
|
th->slice = priority;
|
||||||
|
#endif
|
||||||
|
return INT2NUM(th->priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for IO */
|
/* for IO */
|
||||||
|
@ -443,6 +443,9 @@ native_thread_join(pthread_t th)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if USE_NATIVE_THREAD_PRIORITY
|
||||||
|
|
||||||
static void
|
static void
|
||||||
native_thread_apply_priority(rb_thread_t *th)
|
native_thread_apply_priority(rb_thread_t *th)
|
||||||
{
|
{
|
||||||
@ -469,6 +472,8 @@ native_thread_apply_priority(rb_thread_t *th)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_NATIVE_THREAD_PRIORITY */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ubf_pthread_cond_signal(void *ptr)
|
ubf_pthread_cond_signal(void *ptr)
|
||||||
{
|
{
|
||||||
|
@ -499,6 +499,8 @@ native_thread_join(HANDLE th)
|
|||||||
w32_wait_events(&th, 1, 0, 0);
|
w32_wait_events(&th, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_NATIVE_THREAD_PRIORITY
|
||||||
|
|
||||||
static void
|
static void
|
||||||
native_thread_apply_priority(rb_thread_t *th)
|
native_thread_apply_priority(rb_thread_t *th)
|
||||||
{
|
{
|
||||||
@ -516,6 +518,8 @@ native_thread_apply_priority(rb_thread_t *th)
|
|||||||
SetThreadPriority(th->thread_id, priority);
|
SetThreadPriority(th->thread_id, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_NATIVE_THREAD_PRIORITY */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ubf_handle(void *ptr)
|
ubf_handle(void *ptr)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user