2006-12-31 10:02:22 -05:00
|
|
|
/* -*-c-*- */
|
|
|
|
/**********************************************************************
|
|
|
|
|
2007-12-20 04:29:46 -05:00
|
|
|
thread_pthread.c -
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
|
* blockinlining.c, compile.c, compile.h, debug.c, debug.h,
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci,
thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h,
vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and
copyright year.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 17:13:04 -05:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
|
|
|
|
|
2007-02-08 15:24:55 -05:00
|
|
|
void
|
|
|
|
native_mutex_lock(pthread_mutex_t *lock)
|
|
|
|
{
|
|
|
|
int r;
|
2007-02-22 20:56:43 -05:00
|
|
|
if ((r = pthread_mutex_lock(lock)) != 0) {
|
|
|
|
rb_bug("pthread_mutex_lock: %d", r);
|
2007-02-08 15:24:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_mutex_unlock(pthread_mutex_t *lock)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
if ((r = pthread_mutex_unlock(lock)) != 0) {
|
|
|
|
rb_bug("native_mutex_unlock return non-zero: %d", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
native_mutex_trylock(pthread_mutex_t *lock)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
if ((r = pthread_mutex_trylock(lock)) != 0) {
|
|
|
|
if (r == EBUSY) {
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
else {
|
2007-08-27 12:48:14 -04:00
|
|
|
rb_bug("native_mutex_trylock return non-zero: %d", r);
|
2007-02-08 15:24:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_mutex_initialize(pthread_mutex_t *lock)
|
|
|
|
{
|
2007-04-12 04:14:54 -04:00
|
|
|
int r = pthread_mutex_init(lock, 0);
|
|
|
|
if (r != 0) {
|
|
|
|
rb_bug("native_mutex_initialize return non-zero: %d", r);
|
2007-02-08 15:24:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_mutex_destroy(pthread_mutex_t *lock)
|
|
|
|
{
|
2007-04-12 04:14:54 -04:00
|
|
|
int r = pthread_mutex_destroy(lock);
|
|
|
|
if (r != 0) {
|
|
|
|
rb_bug("native_mutex_destroy return non-zero: %d", r);
|
2007-02-08 15:24:55 -05:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-08-27 12:48:14 -04:00
|
|
|
void
|
|
|
|
native_cond_initialize(pthread_cond_t *cond)
|
|
|
|
{
|
|
|
|
int r = pthread_cond_init(cond, 0);
|
|
|
|
if (r != 0) {
|
|
|
|
rb_bug("native_cond_initialize return non-zero: %d", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_cond_destroy(pthread_cond_t *cond)
|
|
|
|
{
|
|
|
|
int r = pthread_cond_destroy(cond);
|
|
|
|
if (r != 0) {
|
|
|
|
rb_bug("native_cond_destroy return non-zero: %d", r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_cond_signal(pthread_cond_t *cond)
|
|
|
|
{
|
|
|
|
pthread_cond_signal(cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_cond_broadcast(pthread_cond_t *cond)
|
|
|
|
{
|
|
|
|
pthread_cond_broadcast(cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
native_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
|
|
|
{
|
|
|
|
pthread_cond_wait(cond, mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define native_cleanup_push pthread_cleanup_push
|
|
|
|
#define native_cleanup_pop pthread_cleanup_pop
|
|
|
|
#define native_thread_yield() sched_yield()
|
|
|
|
|
2007-02-08 06:51:40 -05:00
|
|
|
static void add_signal_thread_list(rb_thread_t *th);
|
|
|
|
static void remove_signal_thread_list(rb_thread_t *th);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
static rb_thread_lock_t signal_thread_list_lock;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-08-18 04:40:13 -04:00
|
|
|
static pthread_key_t ruby_native_thread_key;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
2007-12-21 03:13:39 -05:00
|
|
|
null_func(int i)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-02-08 06:51:40 -05:00
|
|
|
/* null */
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2007-08-18 04:40:13 -04:00
|
|
|
static rb_thread_t *
|
|
|
|
ruby_thread_from_native(void)
|
|
|
|
{
|
|
|
|
return pthread_getspecific(ruby_native_thread_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ruby_thread_set_native(rb_thread_t *th)
|
|
|
|
{
|
|
|
|
return pthread_setspecific(ruby_native_thread_key, th) == 0;
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
2007-08-18 04:40:13 -04:00
|
|
|
Init_native_thread(void)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-08-18 04:40:13 -04:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
|
|
|
|
pthread_key_create(&ruby_native_thread_key, NULL);
|
|
|
|
th->thread_id = pthread_self();
|
|
|
|
ruby_thread_set_native(th);
|
2006-12-31 10:02:22 -05:00
|
|
|
native_mutex_initialize(&signal_thread_list_lock);
|
|
|
|
posix_signal(SIGVTALRM, null_func);
|
|
|
|
}
|
|
|
|
|
2007-02-08 15:24:55 -05:00
|
|
|
static void
|
|
|
|
native_thread_destroy(rb_thread_t *th)
|
|
|
|
{
|
|
|
|
pthread_cond_destroy(&th->native_thread_data.sleep_cond);
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#define USE_THREAD_CACHE 0
|
|
|
|
|
|
|
|
static void *
|
|
|
|
thread_start_func_1(void *th_ptr)
|
|
|
|
{
|
|
|
|
#if USE_THREAD_CACHE
|
|
|
|
thread_start:
|
|
|
|
#endif
|
|
|
|
{
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
rb_thread_t *th = th_ptr;
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE stack_start;
|
|
|
|
|
|
|
|
/* run */
|
2007-07-11 21:19:18 -04:00
|
|
|
thread_start_func_2(th, &stack_start, rb_ia64_bsp());
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
#if USE_THREAD_CACHE
|
|
|
|
if (1) {
|
|
|
|
/* cache thread */
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
rb_thread_t *th;
|
|
|
|
static rb_thread_t *register_cached_thread_and_wait(void);
|
2006-12-31 10:02:22 -05:00
|
|
|
if ((th = register_cached_thread_and_wait()) != 0) {
|
|
|
|
th_ptr = (void *)th;
|
|
|
|
th->thread_id = pthread_self();
|
|
|
|
goto thread_start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rb_thread_create_control_thread(void);
|
|
|
|
|
|
|
|
struct cached_thread_entry {
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
volatile rb_thread_t **th_area;
|
2006-12-31 10:02:22 -05:00
|
|
|
pthread_cond_t *cond;
|
|
|
|
struct cached_thread_entry *next;
|
|
|
|
};
|
|
|
|
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
|
|
|
#if USE_THREAD_CACHE
|
|
|
|
static pthread_mutex_t thread_cache_lock = PTHREAD_MUTEX_INITIALIZER;
|
2006-12-31 10:02:22 -05:00
|
|
|
struct cached_thread_entry *cached_thread_root;
|
|
|
|
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
static rb_thread_t *
|
2006-12-31 10:02:22 -05:00
|
|
|
register_cached_thread_and_wait(void)
|
|
|
|
{
|
|
|
|
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
volatile rb_thread_t *th_area = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
struct cached_thread_entry *entry =
|
|
|
|
(struct cached_thread_entry *)malloc(sizeof(struct cached_thread_entry));
|
|
|
|
|
|
|
|
struct timeval tv;
|
|
|
|
struct timespec ts;
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
ts.tv_sec = tv.tv_sec + 60;
|
|
|
|
ts.tv_nsec = tv.tv_usec * 1000;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
pthread_mutex_lock(&thread_cache_lock);
|
|
|
|
{
|
|
|
|
entry->th_area = &th_area;
|
|
|
|
entry->cond = &cond;
|
|
|
|
entry->next = cached_thread_root;
|
|
|
|
cached_thread_root = entry;
|
|
|
|
|
|
|
|
pthread_cond_timedwait(&cond, &thread_cache_lock, &ts);
|
|
|
|
|
|
|
|
{
|
|
|
|
struct cached_thread_entry *e = cached_thread_root;
|
|
|
|
struct cached_thread_entry *prev = cached_thread_root;
|
|
|
|
|
|
|
|
while (e) {
|
|
|
|
if (e == entry) {
|
|
|
|
if (prev == cached_thread_root) {
|
|
|
|
cached_thread_root = e->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prev->next = e->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = e;
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(entry);
|
|
|
|
pthread_cond_destroy(&cond);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&thread_cache_lock);
|
|
|
|
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
return (rb_thread_t *)th_area;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
static int
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
use_cached_thread(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
#if USE_THREAD_CACHE
|
|
|
|
struct cached_thread_entry *entry;
|
|
|
|
|
|
|
|
if (cached_thread_root) {
|
|
|
|
pthread_mutex_lock(&thread_cache_lock);
|
|
|
|
entry = cached_thread_root;
|
|
|
|
{
|
|
|
|
if (cached_thread_root) {
|
|
|
|
cached_thread_root = entry->next;
|
|
|
|
*entry->th_area = th;
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
pthread_cond_signal(entry->cond);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&thread_cache_lock);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-02-08 15:24:55 -05:00
|
|
|
#define CHECK_ERR(expr) \
|
2007-02-14 07:15:39 -05:00
|
|
|
{ int err; if ((err = (expr)) != 0) { rb_bug("err: %d - %s", err, #expr); }}
|
2007-02-08 15:24:55 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
native_thread_create(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (use_cached_thread(th)) {
|
2007-02-19 11:16:12 -05:00
|
|
|
thread_debug("create (use cached thread): %p\n", th);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pthread_attr_t attr;
|
2007-12-14 23:09:24 -05:00
|
|
|
size_t stack_size = 512 * 1024; /* 512KB */
|
|
|
|
size_t space;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-01-03 20:38:01 -05:00
|
|
|
#ifdef PTHREAD_STACK_MIN
|
2006-12-31 10:02:22 -05:00
|
|
|
if (stack_size < PTHREAD_STACK_MIN) {
|
|
|
|
stack_size = PTHREAD_STACK_MIN * 2;
|
|
|
|
}
|
2007-01-03 20:38:01 -05:00
|
|
|
#endif
|
2007-12-14 23:09:24 -05:00
|
|
|
space = stack_size/5;
|
|
|
|
if (space > 1024*1024) space = 1024*1024;
|
|
|
|
th->machine_stack_maxsize = stack_size - space;
|
|
|
|
#ifdef __ia64
|
|
|
|
th->machine_stack_maxsize /= 2;
|
|
|
|
th->machine_register_stack_maxsize = th->machine_stack_maxsize;
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-02-08 15:24:55 -05:00
|
|
|
CHECK_ERR(pthread_attr_init(&attr));
|
|
|
|
|
2007-01-03 20:38:01 -05:00
|
|
|
#ifdef PTHREAD_STACK_MIN
|
2007-03-07 19:23:14 -05:00
|
|
|
thread_debug("create - stack size: %lu\n", (unsigned long)stack_size);
|
2007-02-08 15:24:55 -05:00
|
|
|
CHECK_ERR(pthread_attr_setstacksize(&attr, stack_size));
|
2007-01-03 20:38:01 -05:00
|
|
|
#endif
|
2007-02-08 15:24:55 -05:00
|
|
|
|
|
|
|
CHECK_ERR(pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED));
|
|
|
|
CHECK_ERR(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
err = pthread_create(&th->thread_id, &attr, thread_start_func_1, th);
|
2007-02-14 07:15:39 -05:00
|
|
|
thread_debug("create: %p (%d)", th, err);
|
2007-02-08 15:24:55 -05:00
|
|
|
CHECK_ERR(pthread_attr_destroy(&attr));
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-04-10 02:53:39 -04:00
|
|
|
if (!err) {
|
|
|
|
pthread_cond_init(&th->native_thread_data.sleep_cond, 0);
|
|
|
|
}
|
|
|
|
else {
|
2007-02-08 15:24:55 -05:00
|
|
|
st_delete_wrap(th->vm->living_threads, th->self);
|
2006-12-31 10:02:22 -05:00
|
|
|
th->status = THREAD_KILLED;
|
|
|
|
rb_raise(rb_eThreadError, "can't create Thread (%d)", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-01-07 04:47:52 -05:00
|
|
|
static void
|
|
|
|
native_thread_join(pthread_t th)
|
|
|
|
{
|
|
|
|
int err = pthread_join(th, 0);
|
|
|
|
if (err) {
|
|
|
|
rb_raise(rb_eThreadError, "native_thread_join() failed (%d)", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
native_thread_apply_priority(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-12-20 05:14:16 -05:00
|
|
|
#if defined(_POSIX_PRIORITY_SCHEDULING) && (_POSIX_PRIORITY_SCHEDULING > 0)
|
2006-12-31 10:02:22 -05:00
|
|
|
struct sched_param sp;
|
|
|
|
int policy;
|
|
|
|
int priority = 0 - th->priority;
|
|
|
|
int max, min;
|
|
|
|
pthread_getschedparam(th->thread_id, &policy, &sp);
|
|
|
|
max = sched_get_priority_max(policy);
|
|
|
|
min = sched_get_priority_min(policy);
|
|
|
|
|
|
|
|
if (min < priority) {
|
|
|
|
priority = max;
|
|
|
|
}
|
|
|
|
else if (max > priority) {
|
|
|
|
priority = min;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp.sched_priority = priority;
|
|
|
|
pthread_setschedparam(th->thread_id, policy, &sp);
|
2007-12-20 05:14:16 -05:00
|
|
|
#else
|
|
|
|
/* not touched */
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-20 05:47:53 -05:00
|
|
|
ubf_pthread_cond_signal(void *ptr)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-11-20 05:47:53 -05:00
|
|
|
rb_thread_t *th = (rb_thread_t *)ptr;
|
2007-02-08 06:51:40 -05:00
|
|
|
thread_debug("ubf_pthread_cond_signal (%p)\n", th);
|
2006-12-31 10:02:22 -05:00
|
|
|
pthread_cond_signal(&th->native_thread_data.sleep_cond);
|
|
|
|
}
|
|
|
|
|
2007-02-08 06:51:40 -05:00
|
|
|
#ifndef __CYGWIN__
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
2007-02-08 06:51:40 -05:00
|
|
|
ubf_select_each(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
thread_debug("ubf_select_each (%p)\n", (void *)th->thread_id);
|
2006-12-31 10:02:22 -05:00
|
|
|
if (th) {
|
|
|
|
pthread_kill(th->thread_id, SIGVTALRM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 06:51:40 -05:00
|
|
|
static void
|
2007-11-20 05:47:53 -05:00
|
|
|
ubf_select(void *ptr)
|
2007-02-08 06:51:40 -05:00
|
|
|
{
|
2007-11-20 05:47:53 -05:00
|
|
|
rb_thread_t *th = (rb_thread_t *)ptr;
|
2007-02-08 06:51:40 -05:00
|
|
|
add_signal_thread_list(th);
|
|
|
|
ubf_select_each(th);
|
|
|
|
}
|
2007-02-24 04:41:41 -05:00
|
|
|
#else
|
|
|
|
#define ubf_select 0
|
2007-02-08 06:51:40 -05:00
|
|
|
#endif
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
native_sleep(rb_thread_t *th, struct timeval *tv)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int prev_status = th->status;
|
|
|
|
struct timespec ts;
|
|
|
|
struct timeval tvn;
|
|
|
|
|
|
|
|
if (tv) {
|
|
|
|
gettimeofday(&tvn, NULL);
|
|
|
|
ts.tv_sec = tvn.tv_sec + tv->tv_sec;
|
|
|
|
ts.tv_nsec = (tvn.tv_usec + tv->tv_usec) * 1000;
|
2007-01-04 22:33:40 -05:00
|
|
|
if (ts.tv_nsec >= 1000000000){
|
|
|
|
ts.tv_sec += 1;
|
|
|
|
ts.tv_nsec -= 1000000000;
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
th->status = THREAD_STOPPED;
|
|
|
|
pthread_cond_init(&th->native_thread_data.sleep_cond, 0);
|
|
|
|
|
2007-02-19 11:16:12 -05:00
|
|
|
thread_debug("native_sleep %ld\n", tv ? tv->tv_sec : -1);
|
2006-12-31 10:02:22 -05:00
|
|
|
GVL_UNLOCK_BEGIN();
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&th->interrupt_lock);
|
2007-06-05 00:49:54 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
if (th->interrupt_flag) {
|
|
|
|
/* interrupted. return immediate */
|
|
|
|
thread_debug("native_sleep: interrupted before sleep\n");
|
|
|
|
}
|
|
|
|
else {
|
2007-02-08 06:51:40 -05:00
|
|
|
th->unblock_function = ubf_pthread_cond_signal;
|
2007-11-20 05:47:53 -05:00
|
|
|
th->unblock_function_arg = th;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
if (tv == 0) {
|
|
|
|
thread_debug("native_sleep: pthread_cond_wait start\n");
|
|
|
|
pthread_cond_wait(&th->native_thread_data.sleep_cond,
|
|
|
|
&th->interrupt_lock);
|
|
|
|
thread_debug("native_sleep: pthread_cond_wait end\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int r;
|
2007-03-07 19:23:14 -05:00
|
|
|
thread_debug("native_sleep: pthread_cond_timedwait start (%ld, %ld)\n",
|
|
|
|
(unsigned long)ts.tv_sec, ts.tv_nsec);
|
2006-12-31 10:02:22 -05:00
|
|
|
r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
|
|
|
|
&th->interrupt_lock, &ts);
|
|
|
|
thread_debug("native_sleep: pthread_cond_timedwait end (%d)\n", r);
|
|
|
|
}
|
2007-02-08 06:51:40 -05:00
|
|
|
th->unblock_function = 0;
|
2007-11-20 05:47:53 -05:00
|
|
|
th->unblock_function_arg = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&th->interrupt_lock);
|
|
|
|
|
|
|
|
th->status = prev_status;
|
|
|
|
}
|
|
|
|
GVL_UNLOCK_END();
|
|
|
|
thread_debug("native_sleep done\n");
|
|
|
|
}
|
|
|
|
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list {
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
rb_thread_t *th;
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list *prev;
|
|
|
|
struct signal_thread_list *next;
|
2006-12-31 10:02:22 -05:00
|
|
|
};
|
|
|
|
|
2007-02-08 06:51:40 -05:00
|
|
|
static struct signal_thread_list signal_thread_list_anchor = {
|
2006-12-31 10:02:22 -05:00
|
|
|
0, 0, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FGLOCK(lock, body) do { \
|
|
|
|
native_mutex_lock(lock); \
|
|
|
|
{ \
|
|
|
|
body; \
|
|
|
|
} \
|
|
|
|
native_mutex_unlock(lock); \
|
|
|
|
} while (0)
|
|
|
|
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
#if 0 /* for debug */
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
|
|
|
print_signal_list(char *str)
|
|
|
|
{
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list *list =
|
2006-12-31 10:02:22 -05:00
|
|
|
signal_thread_list_anchor.next;
|
|
|
|
thread_debug("list (%s)> ", str);
|
|
|
|
while(list){
|
|
|
|
thread_debug("%p (%p), ", list->th, list->th->thread_id);
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
thread_debug("\n");
|
|
|
|
}
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
static void
|
2007-02-08 06:51:40 -05:00
|
|
|
add_signal_thread_list(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
if (!th->native_thread_data.signal_thread_list) {
|
|
|
|
FGLOCK(&signal_thread_list_lock, {
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list *list =
|
|
|
|
malloc(sizeof(struct signal_thread_list));
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
if (list == 0) {
|
|
|
|
fprintf(stderr, "[FATAL] failed to allocate memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
list->th = th;
|
|
|
|
|
|
|
|
list->prev = &signal_thread_list_anchor;
|
|
|
|
list->next = signal_thread_list_anchor.next;
|
|
|
|
if (list->next) {
|
|
|
|
list->next->prev = list;
|
|
|
|
}
|
|
|
|
signal_thread_list_anchor.next = list;
|
|
|
|
th->native_thread_data.signal_thread_list = list;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-02-08 06:51:40 -05:00
|
|
|
remove_signal_thread_list(rb_thread_t *th)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
if (th->native_thread_data.signal_thread_list) {
|
|
|
|
FGLOCK(&signal_thread_list_lock, {
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list *list =
|
|
|
|
(struct signal_thread_list *)
|
2006-12-31 10:02:22 -05:00
|
|
|
th->native_thread_data.signal_thread_list;
|
|
|
|
|
|
|
|
list->prev->next = list->next;
|
|
|
|
if (list->next) {
|
|
|
|
list->next->prev = list->prev;
|
|
|
|
}
|
|
|
|
th->native_thread_data.signal_thread_list = 0;
|
|
|
|
list->th = 0;
|
|
|
|
free(list);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static pthread_t timer_thread_id;
|
|
|
|
static void timer_thread_function(void);
|
|
|
|
|
|
|
|
static void *
|
|
|
|
thread_timer(void *dummy)
|
|
|
|
{
|
|
|
|
while (system_working) {
|
|
|
|
#ifdef HAVE_NANOSLEEP
|
|
|
|
struct timespec req, rem;
|
|
|
|
req.tv_sec = 0;
|
|
|
|
req.tv_nsec = 10 * 1000 * 1000; /* 10 ms */
|
|
|
|
nanosleep(&req, &rem);
|
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 10000; /* 10 ms */
|
|
|
|
select(0, NULL, NULL, NULL, &tv);
|
|
|
|
#endif
|
2007-02-08 06:51:40 -05:00
|
|
|
#ifndef __CYGWIN__
|
2006-12-31 10:02:22 -05:00
|
|
|
if (signal_thread_list_anchor.next) {
|
|
|
|
FGLOCK(&signal_thread_list_lock, {
|
2007-02-08 06:51:40 -05:00
|
|
|
struct signal_thread_list *list;
|
2006-12-31 10:02:22 -05:00
|
|
|
list = signal_thread_list_anchor.next;
|
|
|
|
while (list) {
|
2007-02-08 06:51:40 -05:00
|
|
|
ubf_select_each(list->th);
|
2006-12-31 10:02:22 -05:00
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2007-02-08 06:51:40 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
timer_thread_function();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_thread_create_timer_thread(void)
|
|
|
|
{
|
|
|
|
rb_enable_interrupt();
|
|
|
|
|
|
|
|
if (!timer_thread_id) {
|
|
|
|
pthread_attr_t attr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
pthread_attr_init(&attr);
|
2007-01-03 20:38:01 -05:00
|
|
|
#ifdef PTHREAD_STACK_MIN
|
2007-01-03 23:47:59 -05:00
|
|
|
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
|
2007-01-03 20:38:01 -05:00
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
err = pthread_create(&timer_thread_id, &attr, thread_timer, 0);
|
|
|
|
if (err != 0) {
|
|
|
|
rb_bug("rb_thread_create_timer_thread: return non-zero (%d)", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_disable_interrupt(); /* only timer thread recieve signal */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
|