2006-12-31 18:02:22 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
thread.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
|
* 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-14 01:13:04 +03:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
YARV Thread Desgin
|
|
|
|
|
|
|
|
model 1: Userlevel Thread
|
|
|
|
Same as traditional ruby thread.
|
|
|
|
|
|
|
|
model 2: Native Thread with Giant VM lock
|
|
|
|
Using pthread (or Windows thread) and Ruby threads run concurrent.
|
|
|
|
|
|
|
|
model 3: Native Thread with fine grain lock
|
|
|
|
Using pthread and Ruby threads run concurrent or parallel.
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
|
|
model 2:
|
|
|
|
A thread has mutex (GVL: Global VM Lock) can run. When thread
|
|
|
|
scheduling, running thread release GVL. If running thread
|
|
|
|
try blocking operation, this thread must release GVL and another
|
|
|
|
thread can continue this flow. After blocking operation, thread
|
* 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 22:00:03 +03:00
|
|
|
must check interrupt (RUBY_VM_CHECK_INTS).
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
Every VM can run parallel.
|
|
|
|
|
|
|
|
Ruby threads are scheduled by OS thread scheduler.
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
|
|
|
|
model 3:
|
|
|
|
Every threads run concurrent or parallel and to access shared object
|
|
|
|
exclusive access control is needed. For example, to access String
|
|
|
|
object or Array object, fine grain lock must be locked every time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* for model 2 */
|
|
|
|
|
|
|
|
#include "eval_intern.h"
|
|
|
|
#include "vm.h"
|
2007-02-05 15:21:01 +03:00
|
|
|
#include "gc.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-08-13 11:53:35 +04:00
|
|
|
#ifndef USE_NATIVE_THREAD_PRIORITY
|
|
|
|
#define USE_NATIVE_THREAD_PRIORITY 0
|
|
|
|
#define RUBY_THREAD_PRIORITY_MAX 3
|
|
|
|
#define RUBY_THREAD_PRIORITY_MIN -3
|
|
|
|
#endif
|
|
|
|
|
2007-02-24 12:39:25 +03:00
|
|
|
#ifndef THREAD_DEBUG
|
2006-12-31 18:02:22 +03:00
|
|
|
#define THREAD_DEBUG 0
|
2007-02-24 12:39:25 +03:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE rb_cMutex;
|
|
|
|
VALUE rb_cBarrier;
|
|
|
|
|
* 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 09:37:46 +03:00
|
|
|
static void sleep_timeval(rb_thread_t *th, struct timeval time);
|
|
|
|
static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec);
|
2008-06-12 17:01:38 +04:00
|
|
|
static void sleep_forever(rb_thread_t *th, int nodeadlock);
|
2007-05-03 17:04:42 +04:00
|
|
|
static double timeofday(void);
|
2006-12-31 18:02:22 +03:00
|
|
|
struct timeval rb_time_interval(VALUE);
|
* 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 09:37:46 +03:00
|
|
|
static int rb_thread_dead(rb_thread_t *th);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static void rb_check_deadlock(rb_vm_t *vm);
|
|
|
|
|
* 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 09:37:46 +03:00
|
|
|
void rb_signal_exec(rb_thread_t *th, int sig);
|
2007-03-19 06:58:57 +03:00
|
|
|
void rb_disable_interrupt(void);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-07-01 12:44:32 +04:00
|
|
|
static const VALUE eKillSignal = INT2FIX(0);
|
|
|
|
static const VALUE eTerminateSignal = INT2FIX(1);
|
2007-01-07 12:47:52 +03:00
|
|
|
static volatile int system_working = 1;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
inline static void
|
2008-05-08 01:27:34 +04:00
|
|
|
st_delete_wrap(st_table *table, st_data_t key)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-05-08 01:27:34 +04:00
|
|
|
st_delete(table, &key, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
#define THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
|
|
|
|
|
2008-05-30 05:52:38 +04:00
|
|
|
static void set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg,
|
|
|
|
struct rb_unblock_callback *old);
|
|
|
|
static void reset_unblock_function(rb_thread_t *th, const struct rb_unblock_callback *old);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-08 14:51:40 +03:00
|
|
|
#define GVL_UNLOCK_BEGIN() do { \
|
|
|
|
rb_thread_t *_th_stored = GET_THREAD(); \
|
|
|
|
rb_gc_save_machine_context(_th_stored); \
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_unlock(&_th_stored->vm->global_vm_lock)
|
2007-02-08 14:51:40 +03:00
|
|
|
|
|
|
|
#define GVL_UNLOCK_END() \
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_lock(&_th_stored->vm->global_vm_lock); \
|
2007-02-08 14:51:40 +03:00
|
|
|
rb_thread_set_current(_th_stored); \
|
|
|
|
} while(0)
|
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
#define BLOCKING_REGION_CORE(exec) do { \
|
|
|
|
GVL_UNLOCK_BEGIN(); {\
|
|
|
|
exec; \
|
|
|
|
} \
|
|
|
|
GVL_UNLOCK_END(); \
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
#define BLOCKING_REGION(exec, ubf, ubfarg) do { \
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *__th = GET_THREAD(); \
|
2008-07-16 23:19:36 +04:00
|
|
|
enum rb_thread_status __prev_status = __th->status; \
|
2008-05-30 05:52:38 +04:00
|
|
|
struct rb_unblock_callback __oldubf; \
|
|
|
|
set_unblock_function(__th, ubf, ubfarg, &__oldubf); \
|
2008-06-19 18:18:46 +04:00
|
|
|
__th->status = THREAD_STOPPED; \
|
2007-02-24 12:41:41 +03:00
|
|
|
thread_debug("enter blocking region (%p)\n", __th); \
|
2008-06-19 18:18:46 +04:00
|
|
|
BLOCKING_REGION_CORE(exec); \
|
2007-02-24 12:41:41 +03:00
|
|
|
thread_debug("leave blocking region (%p)\n", __th); \
|
2007-02-08 14:51:40 +03:00
|
|
|
remove_signal_thread_list(__th); \
|
2008-05-30 05:52:38 +04:00
|
|
|
reset_unblock_function(__th, &__oldubf); \
|
2008-06-19 18:18:46 +04:00
|
|
|
if (__th->status == THREAD_STOPPED) { \
|
2006-12-31 18:02:22 +03:00
|
|
|
__th->status = __prev_status; \
|
|
|
|
} \
|
2008-06-19 18:18:46 +04:00
|
|
|
RUBY_VM_CHECK_INTS(); \
|
2006-12-31 18:02:22 +03:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#if THREAD_DEBUG
|
2008-07-09 15:18:52 +04:00
|
|
|
#ifdef HAVE_VA_ARGS_MACRO
|
|
|
|
void rb_thread_debug(const char *file, int line, const char *fmt, ...);
|
|
|
|
#define thread_debug(fmt, ...) rb_thread_debug(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
|
|
|
#define POSITION_FORMAT "%s:%d:"
|
|
|
|
#define POSITION_ARGS ,file, line
|
|
|
|
#else
|
2007-02-24 12:39:25 +03:00
|
|
|
void rb_thread_debug(const char *fmt, ...);
|
2008-07-09 15:18:52 +04:00
|
|
|
#define thread_debug rb_thread_debug
|
|
|
|
#define POSITION_FORMAT
|
|
|
|
#define POSITION_ARGS
|
|
|
|
#endif
|
2007-02-24 12:39:25 +03:00
|
|
|
|
|
|
|
# if THREAD_DEBUG < 0
|
|
|
|
static int rb_thread_debug_enabled;
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_s_debug(void)
|
|
|
|
{
|
|
|
|
return INT2NUM(rb_thread_debug_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_s_debug_set(VALUE self, VALUE val)
|
|
|
|
{
|
|
|
|
rb_thread_debug_enabled = RTEST(val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
# define rb_thread_debug_enabled THREAD_DEBUG
|
|
|
|
# endif
|
2006-12-31 18:02:22 +03:00
|
|
|
#else
|
|
|
|
#define thread_debug if(0)printf
|
|
|
|
#endif
|
|
|
|
|
2007-07-12 05:19:18 +04:00
|
|
|
#ifndef __ia64
|
|
|
|
#define thread_start_func_2(th, st, rst) thread_start_func_2(th, st)
|
|
|
|
#endif
|
|
|
|
NOINLINE(static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start,
|
|
|
|
VALUE *register_stack_start));
|
2008-07-05 17:22:29 +04:00
|
|
|
static void timer_thread_function(void *);
|
2007-07-12 05:19:18 +04:00
|
|
|
|
2007-02-08 14:51:40 +03:00
|
|
|
#if defined(_WIN32)
|
2007-12-20 12:29:46 +03:00
|
|
|
#include "thread_win32.c"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define DEBUG_OUT() \
|
|
|
|
WaitForSingleObject(&debug_mutex, INFINITE); \
|
2008-07-09 15:18:52 +04:00
|
|
|
printf(POSITION_FORMAT"%p - %s" POSITION_ARGS, GetCurrentThreadId(), buf); \
|
2007-02-24 12:39:25 +03:00
|
|
|
fflush(stdout); \
|
2006-12-31 18:02:22 +03:00
|
|
|
ReleaseMutex(&debug_mutex);
|
|
|
|
|
|
|
|
#elif defined(HAVE_PTHREAD_H)
|
2007-12-20 12:29:46 +03:00
|
|
|
#include "thread_pthread.c"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
#define DEBUG_OUT() \
|
|
|
|
pthread_mutex_lock(&debug_mutex); \
|
2008-07-09 15:18:52 +04:00
|
|
|
printf(POSITION_FORMAT"%#"PRIxVALUE" - %s" POSITION_ARGS, (VALUE)pthread_self(), buf); \
|
2007-02-24 12:39:25 +03:00
|
|
|
fflush(stdout); \
|
2006-12-31 18:02:22 +03:00
|
|
|
pthread_mutex_unlock(&debug_mutex);
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "unsupported thread type"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if THREAD_DEBUG
|
|
|
|
static int debug_mutex_initialized = 1;
|
* 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 22:00:03 +03:00
|
|
|
static rb_thread_lock_t debug_mutex;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
void
|
2008-07-09 15:18:52 +04:00
|
|
|
rb_thread_debug(
|
|
|
|
#ifdef HAVE_VA_ARGS_MACRO
|
|
|
|
const char *file, int line,
|
|
|
|
#endif
|
|
|
|
const char *fmt, ...)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
2007-02-24 12:39:25 +03:00
|
|
|
if (!rb_thread_debug_enabled) return;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (debug_mutex_initialized == 1) {
|
|
|
|
debug_mutex_initialized = 0;
|
|
|
|
native_mutex_initialize(&debug_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buf, BUFSIZ, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
DEBUG_OUT();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-08-27 20:48:14 +04:00
|
|
|
static void
|
|
|
|
set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func, void *arg,
|
2008-05-30 05:52:38 +04:00
|
|
|
struct rb_unblock_callback *old)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
check_ints:
|
2007-02-14 05:42:11 +03:00
|
|
|
RUBY_VM_CHECK_INTS(); /* check signal or so */
|
2006-12-31 18:02:22 +03:00
|
|
|
native_mutex_lock(&th->interrupt_lock);
|
|
|
|
if (th->interrupt_flag) {
|
|
|
|
native_mutex_unlock(&th->interrupt_lock);
|
2007-02-24 12:41:41 +03:00
|
|
|
goto check_ints;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
else {
|
2008-05-30 05:52:38 +04:00
|
|
|
if (old) *old = th->unblock;
|
|
|
|
th->unblock.func = func;
|
|
|
|
th->unblock.arg = arg;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
native_mutex_unlock(&th->interrupt_lock);
|
|
|
|
}
|
|
|
|
|
2008-05-30 05:52:38 +04:00
|
|
|
static void
|
|
|
|
reset_unblock_function(rb_thread_t *th, const struct rb_unblock_callback *old)
|
|
|
|
{
|
|
|
|
native_mutex_lock(&th->interrupt_lock);
|
|
|
|
th->unblock = *old;
|
|
|
|
native_mutex_unlock(&th->interrupt_lock);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03: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 09:37:46 +03:00
|
|
|
rb_thread_interrupt(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
native_mutex_lock(&th->interrupt_lock);
|
2007-12-25 07:16:06 +03:00
|
|
|
RUBY_VM_SET_INTERRUPT(th);
|
2008-05-30 05:52:38 +04:00
|
|
|
if (th->unblock.func) {
|
|
|
|
(th->unblock.func)(th->unblock.arg);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* none */
|
|
|
|
}
|
|
|
|
native_mutex_unlock(&th->interrupt_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 09:37:46 +03:00
|
|
|
terminate_i(st_data_t key, st_data_t val, rb_thread_t *main_thread)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE thval = key;
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
|
|
|
if (th != main_thread) {
|
|
|
|
thread_debug("terminate_i: %p\n", th);
|
|
|
|
rb_thread_interrupt(th);
|
2007-04-02 16:54:42 +04:00
|
|
|
th->thrown_errinfo = eTerminateSignal;
|
2006-12-31 18:02:22 +03:00
|
|
|
th->status = THREAD_TO_KILL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
thread_debug("terminate_i: main thread (%p)\n", th);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:27:43 +04:00
|
|
|
typedef struct rb_mutex_struct
|
|
|
|
{
|
|
|
|
rb_thread_lock_t lock;
|
|
|
|
rb_thread_cond_t cond;
|
|
|
|
struct rb_thread_struct volatile *th;
|
|
|
|
volatile int cond_waiting, cond_notified;
|
|
|
|
struct rb_mutex_struct *next_mutex;
|
|
|
|
} mutex_t;
|
|
|
|
|
|
|
|
static void rb_mutex_unlock_all(mutex_t *mutex);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
|
|
|
rb_thread_terminate_all(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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD(); /* main thread */
|
* 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 22:00:03 +03:00
|
|
|
rb_vm_t *vm = th->vm;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (vm->main_thread != th) {
|
|
|
|
rb_bug("rb_thread_terminate_all: called by child thread (%p, %p)", vm->main_thread, th);
|
|
|
|
}
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
/* unlock all locking mutexes */
|
|
|
|
if (th->keeping_mutexes) {
|
|
|
|
rb_mutex_unlock_all(th->keeping_mutexes);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
thread_debug("rb_thread_terminate_all (main thread: %p)\n", th);
|
|
|
|
st_foreach(vm->living_threads, terminate_i, (st_data_t)th);
|
|
|
|
|
|
|
|
while (!rb_thread_alone()) {
|
2007-08-17 11:24:03 +04:00
|
|
|
PUSH_TAG();
|
|
|
|
if (EXEC_TAG() == 0) {
|
|
|
|
rb_thread_schedule();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* ignore exception */
|
|
|
|
}
|
|
|
|
POP_TAG();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
system_working = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-05-11 08:15:29 +04:00
|
|
|
thread_cleanup_func_before_exec(void *th_ptr)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = th_ptr;
|
2006-12-31 18:02:22 +03:00
|
|
|
th->status = THREAD_KILLED;
|
|
|
|
th->machine_stack_start = th->machine_stack_end = 0;
|
2007-06-14 12:35:20 +04:00
|
|
|
#ifdef __ia64
|
|
|
|
th->machine_register_stack_start = th->machine_register_stack_end = 0;
|
|
|
|
#endif
|
2008-05-11 08:15:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
thread_cleanup_func(void *th_ptr)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = th_ptr;
|
|
|
|
thread_cleanup_func_before_exec(th_ptr);
|
2007-02-08 23:24:55 +03:00
|
|
|
native_thread_destroy(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-08-10 00:12:21 +04:00
|
|
|
extern void ruby_error_print(void);
|
|
|
|
static VALUE rb_thread_raise(int, VALUE *, rb_thread_t *);
|
2007-11-21 12:06:06 +03:00
|
|
|
void rb_thread_recycle_stack_release(VALUE *);
|
2007-08-10 00:12:21 +04:00
|
|
|
|
2008-06-14 06:59:19 +04:00
|
|
|
void
|
|
|
|
ruby_thread_init_stack(rb_thread_t *th)
|
|
|
|
{
|
|
|
|
native_thread_init_stack(th);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2007-07-12 05:19:18 +04:00
|
|
|
thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int state;
|
|
|
|
VALUE args = th->first_args;
|
* 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 22:00:03 +03:00
|
|
|
rb_proc_t *proc;
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *join_th;
|
2007-08-10 19:01:14 +04:00
|
|
|
rb_thread_t *main_th;
|
2007-08-10 00:12:21 +04:00
|
|
|
VALUE errinfo = Qnil;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
th->machine_stack_start = stack_start;
|
2007-06-14 12:35:20 +04:00
|
|
|
#ifdef __ia64
|
|
|
|
th->machine_register_stack_start = register_stack_start;
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
thread_debug("thread start: %p\n", th);
|
|
|
|
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_lock(&th->vm->global_vm_lock);
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
thread_debug("thread start (get lock): %p\n", th);
|
* 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 22:00:03 +03:00
|
|
|
rb_thread_set_current(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
TH_PUSH_TAG(th);
|
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
* cont.c: support Fiber. Check test/ruby/test_fiber.rb for detail.
Fiber is known as "Micro Thread", "Coroutine", and other terms.
At this time, only Fiber#pass is supported to change context.
I want to know more suitable method name/API for Fiber (... do you
know more suitable class name instead of Fiber?) as "suspend/resume",
"call", "yield", "start/kick/stop/restart", ....
* eval.c, eval_intern.h, thread.c, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-27 23:12:43 +04:00
|
|
|
SAVE_ROOT_JMPBUF(th, {
|
|
|
|
if (th->first_proc) {
|
|
|
|
GetProcPtr(th->first_proc, proc);
|
|
|
|
th->errinfo = Qnil;
|
|
|
|
th->local_lfp = proc->block.lfp;
|
|
|
|
th->local_svar = Qnil;
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
th->value = vm_invoke_proc(th, proc, proc->block.self,
|
2007-12-20 10:07:35 +03:00
|
|
|
RARRAY_LEN(args), RARRAY_PTR(args), 0);
|
* cont.c: support Fiber. Check test/ruby/test_fiber.rb for detail.
Fiber is known as "Micro Thread", "Coroutine", and other terms.
At this time, only Fiber#pass is supported to change context.
I want to know more suitable method name/API for Fiber (... do you
know more suitable class name instead of Fiber?) as "suspend/resume",
"call", "yield", "start/kick/stop/restart", ....
* eval.c, eval_intern.h, thread.c, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-27 23:12:43 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-08-20 18:17:16 +04:00
|
|
|
th->value = (*th->first_func)((void *)th->first_args);
|
* cont.c: support Fiber. Check test/ruby/test_fiber.rb for detail.
Fiber is known as "Micro Thread", "Coroutine", and other terms.
At this time, only Fiber#pass is supported to change context.
I want to know more suitable method name/API for Fiber (... do you
know more suitable class name instead of Fiber?) as "suspend/resume",
"call", "yield", "start/kick/stop/restart", ....
* eval.c, eval_intern.h, thread.c, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-27 23:12:43 +04:00
|
|
|
}
|
|
|
|
});
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-08-06 01:55:23 +04:00
|
|
|
errinfo = th->errinfo;
|
|
|
|
if (NIL_P(errinfo)) errinfo = rb_errinfo();
|
|
|
|
if (state == TAG_FATAL) {
|
|
|
|
/* fatal error within this thread, need to stop whole script */
|
|
|
|
}
|
|
|
|
else if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
|
|
|
if (th->safe_level >= 4) {
|
|
|
|
th->errinfo = rb_exc_new3(rb_eSecurityError,
|
|
|
|
rb_sprintf("Insecure exit at level %d", th->safe_level));
|
|
|
|
errinfo = Qnil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (th->safe_level < 4 &&
|
|
|
|
(th->vm->thread_abort_on_exception ||
|
|
|
|
th->abort_on_exception || RTEST(ruby_debug))) {
|
|
|
|
/* exit on main_thread */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
errinfo = Qnil;
|
2007-08-10 00:12:21 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
th->value = Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
th->status = THREAD_KILLED;
|
|
|
|
thread_debug("thread end: %p\n", th);
|
|
|
|
|
2007-08-10 19:01:14 +04:00
|
|
|
main_th = th->vm->main_thread;
|
2007-08-17 11:24:03 +04:00
|
|
|
if (th != main_th) {
|
|
|
|
if (TYPE(errinfo) == T_OBJECT) {
|
|
|
|
/* treat with normal error object */
|
|
|
|
rb_thread_raise(1, &errinfo, main_th);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TH_POP_TAG();
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
/* locking_mutex must be Qfalse */
|
|
|
|
if (th->locking_mutex != Qfalse) {
|
2008-06-16 18:56:14 +04:00
|
|
|
rb_bug("thread_start_func_2: locking_mutex must not be set (%p:%"PRIxVALUE")",
|
|
|
|
th, th->locking_mutex);
|
2008-06-12 17:01:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* unlock all locking mutexes */
|
|
|
|
if (th->keeping_mutexes) {
|
|
|
|
rb_mutex_unlock_all(th->keeping_mutexes);
|
2008-07-27 19:20:01 +04:00
|
|
|
th->keeping_mutexes = NULL;
|
2008-06-12 17:01:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delete self from living_threads */
|
2007-08-17 11:24:03 +04:00
|
|
|
st_delete_wrap(th->vm->living_threads, th->self);
|
2007-08-10 19:01:14 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* wake up joinning threads */
|
|
|
|
join_th = th->join_list_head;
|
|
|
|
while (join_th) {
|
2007-08-10 19:01:14 +04:00
|
|
|
if (join_th == main_th) errinfo = Qnil;
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_thread_interrupt(join_th);
|
2008-07-16 23:19:36 +04:00
|
|
|
switch (join_th->status) {
|
|
|
|
case THREAD_STOPPED: case THREAD_STOPPED_FOREVER:
|
|
|
|
join_th->status = THREAD_RUNNABLE;
|
|
|
|
default: break;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
join_th = join_th->join_list_next;
|
|
|
|
}
|
2008-06-12 17:01:38 +04:00
|
|
|
if (th != main_th) rb_check_deadlock(th->vm);
|
2007-11-21 12:06:06 +03:00
|
|
|
|
|
|
|
if (!th->root_fiber) {
|
|
|
|
rb_thread_recycle_stack_release(th->stack);
|
|
|
|
th->stack = 0;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-08 23:24:55 +03:00
|
|
|
thread_cleanup_func(th);
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_unlock(&th->vm->global_vm_lock);
|
2007-08-10 00:12:21 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2007-12-05 10:18:52 +03:00
|
|
|
thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS))
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-01-18 21:48:12 +03:00
|
|
|
if (OBJ_FROZEN(GET_THREAD()->thgroup)) {
|
|
|
|
rb_raise(rb_eThreadError,
|
|
|
|
"can't start a new thread (frozen ThreadGroup)");
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thval, th);
|
2007-02-05 15:21:01 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* setup thread environment */
|
2007-02-05 15:21:01 +03:00
|
|
|
th->first_func = fn;
|
2008-07-10 19:58:07 +04:00
|
|
|
th->first_proc = fn ? Qfalse : rb_block_proc();
|
|
|
|
th->first_args = args; /* GC: shouldn't put before above line */
|
2007-02-05 15:21:01 +03:00
|
|
|
|
2007-08-10 18:54:50 +04:00
|
|
|
th->priority = GET_THREAD()->priority;
|
2008-01-18 21:48:12 +03:00
|
|
|
th->thgroup = GET_THREAD()->thgroup;
|
2007-08-10 18:54:50 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
native_mutex_initialize(&th->interrupt_lock);
|
|
|
|
/* kick thread */
|
|
|
|
st_insert(th->vm->living_threads, thval, (st_data_t) th->thread_id);
|
|
|
|
native_thread_create(th);
|
|
|
|
return thval;
|
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
static VALUE
|
2007-12-05 10:18:52 +03:00
|
|
|
thread_s_new(int argc, VALUE *argv, VALUE klass)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
2007-12-05 10:18:52 +03:00
|
|
|
rb_thread_t *th;
|
|
|
|
VALUE thread = rb_thread_alloc(klass);
|
|
|
|
rb_obj_call_init(thread, argc, argv);
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
if (!th->first_args) {
|
|
|
|
rb_raise(rb_eThreadError, "uninitialized thread - check `%s#initialize'",
|
|
|
|
rb_class2name(klass));
|
|
|
|
}
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2007-12-24 10:52:39 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.start([args]*) {|args| block } => thread
|
|
|
|
* Thread.fork([args]*) {|args| block } => thread
|
|
|
|
*
|
|
|
|
* Basically the same as <code>Thread::new</code>. However, if class
|
|
|
|
* <code>Thread</code> is subclassed, then calling <code>start</code> in that
|
|
|
|
* subclass will not invoke the subclass's <code>initialize</code> method.
|
|
|
|
*/
|
|
|
|
|
2007-12-05 10:18:52 +03:00
|
|
|
static VALUE
|
|
|
|
thread_start(VALUE klass, VALUE args)
|
|
|
|
{
|
|
|
|
return thread_create_core(rb_thread_alloc(klass), args, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thread_initialize(VALUE thread, VALUE args)
|
|
|
|
{
|
|
|
|
rb_thread_t *th;
|
|
|
|
if (!rb_block_given_p()) {
|
|
|
|
rb_raise(rb_eThreadError, "must be called with a block");
|
|
|
|
}
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
if (th->first_args) {
|
|
|
|
VALUE rb_proc_location(VALUE self);
|
|
|
|
VALUE proc = th->first_proc, line, loc;
|
|
|
|
const char *file;
|
|
|
|
if (!proc || !RTEST(loc = rb_proc_location(proc))) {
|
|
|
|
rb_raise(rb_eThreadError, "already initialized thread");
|
|
|
|
}
|
2007-12-05 10:43:08 +03:00
|
|
|
file = RSTRING_PTR(RARRAY_PTR(loc)[0]);
|
2007-12-05 10:18:52 +03:00
|
|
|
if (NIL_P(line = RARRAY_PTR(loc)[1])) {
|
|
|
|
rb_raise(rb_eThreadError, "already initialized thread - %s",
|
|
|
|
file);
|
|
|
|
}
|
2008-07-05 17:22:29 +04:00
|
|
|
rb_raise(rb_eThreadError, "already initialized thread - %s:%d",
|
2007-12-05 10:18:52 +03:00
|
|
|
file, NUM2INT(line));
|
|
|
|
}
|
|
|
|
return thread_create_core(thread, args, 0);
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_create(VALUE (*fn)(ANYARGS), void *arg)
|
|
|
|
{
|
2007-12-05 10:18:52 +03:00
|
|
|
return thread_create_core(rb_thread_alloc(rb_cThread), (VALUE)arg, fn);
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/* +infty, for this purpose */
|
|
|
|
#define DELAY_INFTY 1E30
|
|
|
|
|
2008-04-22 08:13:01 +04:00
|
|
|
struct join_arg {
|
|
|
|
rb_thread_t *target, *waiting;
|
|
|
|
double limit;
|
|
|
|
int forever;
|
|
|
|
};
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
2008-04-22 08:13:01 +04:00
|
|
|
remove_from_join_list(VALUE arg)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-04-22 08:13:01 +04:00
|
|
|
struct join_arg *p = (struct join_arg *)arg;
|
|
|
|
rb_thread_t *target_th = p->target, *th = p->waiting;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (target_th->status != THREAD_KILLED) {
|
2008-04-22 08:13:01 +04:00
|
|
|
rb_thread_t **pth = &target_th->join_list_head;
|
|
|
|
|
|
|
|
while (*pth) {
|
|
|
|
if (*pth == th) {
|
|
|
|
*pth = th->join_list_next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pth = &(*pth)->join_list_next;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-04-22 08:13:01 +04:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thread_join_sleep(VALUE arg)
|
|
|
|
{
|
|
|
|
struct join_arg *p = (struct join_arg *)arg;
|
|
|
|
rb_thread_t *target_th = p->target, *th = p->waiting;
|
|
|
|
double now, limit = p->limit;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
while (target_th->status != THREAD_KILLED) {
|
2008-04-22 08:13:01 +04:00
|
|
|
if (p->forever) {
|
2008-06-12 17:01:38 +04:00
|
|
|
sleep_forever(th, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
now = timeofday();
|
|
|
|
if (now > limit) {
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_debug("thread_join: timeout (thid: %p)\n",
|
* 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 08:25:46 +04:00
|
|
|
(void *)target_th->thread_id);
|
2008-04-22 08:13:01 +04:00
|
|
|
return Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
sleep_wait_for_interrupt(th, limit - now);
|
|
|
|
}
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_debug("thread_join: interrupted (thid: %p)\n",
|
* 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 08:25:46 +04:00
|
|
|
(void *)target_th->thread_id);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-04-22 08:13:01 +04:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thread_join(rb_thread_t *target_th, double delay)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
struct join_arg arg;
|
|
|
|
|
|
|
|
arg.target = target_th;
|
|
|
|
arg.waiting = th;
|
|
|
|
arg.limit = timeofday() + delay;
|
|
|
|
arg.forever = delay == DELAY_INFTY;
|
|
|
|
|
|
|
|
thread_debug("thread_join (thid: %p)\n", (void *)target_th->thread_id);
|
|
|
|
|
|
|
|
if (target_th->status != THREAD_KILLED) {
|
|
|
|
th->join_list_next = target_th->join_list_head;
|
|
|
|
target_th->join_list_head = th;
|
|
|
|
if (!rb_ensure(thread_join_sleep, (VALUE)&arg,
|
|
|
|
remove_from_join_list, (VALUE)&arg)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_debug("thread_join: success (thid: %p)\n",
|
* 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 08:25:46 +04:00
|
|
|
(void *)target_th->thread_id);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
if (target_th->errinfo != Qnil) {
|
|
|
|
VALUE err = target_th->errinfo;
|
|
|
|
|
|
|
|
if (FIXNUM_P(err)) {
|
|
|
|
/* */
|
|
|
|
}
|
|
|
|
else if (TYPE(target_th->errinfo) == T_NODE) {
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
rb_exc_raise(vm_make_jump_tag_but_local_jump(
|
2006-12-31 18:02:22 +03:00
|
|
|
GET_THROWOBJ_STATE(err), GET_THROWOBJ_VAL(err)));
|
|
|
|
}
|
|
|
|
else {
|
2007-02-14 05:42:11 +03:00
|
|
|
/* normal exception */
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_exc_raise(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target_th->self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.join => thr
|
|
|
|
* thr.join(limit) => thr
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* The calling thread will suspend execution and run <i>thr</i>. Does not
|
|
|
|
* return until <i>thr</i> exits or until <i>limit</i> seconds have passed. If
|
|
|
|
* the time limit expires, <code>nil</code> will be returned, otherwise
|
|
|
|
* <i>thr</i> is returned.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Any threads not joined will be killed when the main program exits. If
|
|
|
|
* <i>thr</i> had previously raised an exception and the
|
|
|
|
* <code>abort_on_exception</code> and <code>$DEBUG</code> flags are not set
|
|
|
|
* (so the exception has not yet been processed) it will be processed at this
|
|
|
|
* time.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { print "a"; sleep(10); print "b"; print "c" }
|
|
|
|
* x = Thread.new { print "x"; Thread.pass; print "y"; print "z" }
|
|
|
|
* x.join # Let x thread finish, a will be killed on exit.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* axyz
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* The following example illustrates the <i>limit</i> parameter.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }}
|
|
|
|
* puts "Waiting" until y.join(0.15)
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* tick...
|
|
|
|
* Waiting
|
|
|
|
* tick...
|
|
|
|
* Waitingtick...
|
* 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 08:25:10 +04:00
|
|
|
*
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* tick...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_join_m(int argc, VALUE *argv, VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *target_th;
|
2006-12-31 18:02:22 +03:00
|
|
|
double delay = DELAY_INFTY;
|
|
|
|
VALUE limit;
|
* 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 08:25:10 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(self, target_th);
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "01", &limit);
|
|
|
|
if (!NIL_P(limit)) {
|
|
|
|
delay = rb_num2dbl(limit);
|
|
|
|
}
|
2007-12-25 07:16:06 +03:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
return thread_join(target_th, delay);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.value => obj
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Waits for <i>thr</i> to complete (via <code>Thread#join</code>) and returns
|
|
|
|
* its value.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { 2 + 2 }
|
|
|
|
* a.value #=> 4
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_value(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(self, th);
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_join(th, DELAY_INFTY);
|
2006-12-31 18:02:22 +03:00
|
|
|
return th->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Thread Scheduling
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct timeval
|
|
|
|
double2timeval(double d)
|
|
|
|
{
|
|
|
|
struct timeval time;
|
|
|
|
|
|
|
|
time.tv_sec = (int)d;
|
|
|
|
time.tv_usec = (int)((d - (int)d) * 1e6);
|
|
|
|
if (time.tv_usec < 0) {
|
|
|
|
time.tv_usec += (long)1e6;
|
|
|
|
time.tv_sec -= 1;
|
|
|
|
}
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-12 17:01:38 +04:00
|
|
|
sleep_forever(rb_thread_t *th, int deadlockable)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-07-16 23:19:36 +04:00
|
|
|
enum rb_thread_status prev_status = th->status;
|
|
|
|
|
|
|
|
th->status = deadlockable ? THREAD_STOPPED_FOREVER : THREAD_STOPPED;
|
|
|
|
do {
|
|
|
|
if (deadlockable) {
|
|
|
|
th->vm->sleeper++;
|
|
|
|
rb_check_deadlock(th->vm);
|
|
|
|
}
|
|
|
|
native_sleep(th, 0);
|
|
|
|
if (deadlockable) {
|
|
|
|
th->vm->sleeper--;
|
|
|
|
}
|
|
|
|
RUBY_VM_CHECK_INTS();
|
|
|
|
} while (th->status == THREAD_STOPPED_FOREVER);
|
|
|
|
th->status = prev_status;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2008-07-09 17:41:19 +04:00
|
|
|
static void
|
|
|
|
getclockofday(struct timeval *tp)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
|
|
|
|
tp->tv_sec = ts.tv_sec;
|
|
|
|
tp->tv_usec = ts.tv_nsec / 1000;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
gettimeofday(tp, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03: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 09:37:46 +03:00
|
|
|
sleep_timeval(rb_thread_t *th, struct timeval tv)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-07-16 23:19:36 +04:00
|
|
|
struct timeval to, tvn;
|
|
|
|
enum rb_thread_status prev_status = th->status;
|
|
|
|
|
|
|
|
getclockofday(&to);
|
|
|
|
to.tv_sec += tv.tv_sec;
|
|
|
|
if ((to.tv_usec += tv.tv_usec) >= 1000000) {
|
|
|
|
to.tv_sec++;
|
|
|
|
to.tv_usec -= 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
th->status = THREAD_STOPPED;
|
|
|
|
do {
|
|
|
|
native_sleep(th, &tv);
|
|
|
|
RUBY_VM_CHECK_INTS();
|
|
|
|
getclockofday(&tvn);
|
|
|
|
if (to.tv_sec < tvn.tv_sec) break;
|
|
|
|
if (to.tv_sec == tvn.tv_sec && to.tv_usec <= tvn.tv_usec) break;
|
|
|
|
thread_debug("sleep_timeval: %ld.%.6ld > %ld.%.6ld\n",
|
|
|
|
(long)to.tv_sec, to.tv_usec,
|
|
|
|
(long)tvn.tv_sec, tvn.tv_usec);
|
|
|
|
tv.tv_sec = to.tv_sec - tvn.tv_sec;
|
|
|
|
if ((tv.tv_usec = to.tv_usec - tvn.tv_usec) < 0) {
|
|
|
|
--tv.tv_sec;
|
|
|
|
tv.tv_usec += 1000000;
|
|
|
|
}
|
|
|
|
} while (th->status == THREAD_STOPPED);
|
|
|
|
th->status = prev_status;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_sleep_forever()
|
|
|
|
{
|
|
|
|
thread_debug("rb_thread_sleep_forever\n");
|
2008-06-12 17:01:38 +04:00
|
|
|
sleep_forever(GET_THREAD(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_thread_sleep_deadly()
|
|
|
|
{
|
|
|
|
thread_debug("rb_thread_sleep_deadly\n");
|
|
|
|
sleep_forever(GET_THREAD(), 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
timeofday(void)
|
|
|
|
{
|
2008-05-09 14:17:15 +04:00
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
|
|
|
|
return (double)tp.tv_sec + (double)tp.tv_nsec * 1e-9;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
|
|
|
|
}
|
2006-12-31 18:02:22 +03: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 09:37:46 +03:00
|
|
|
sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
sleep_timeval(th, double2timeval(sleepsec));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 09:37:46 +03:00
|
|
|
sleep_for_polling(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
struct timeval time;
|
|
|
|
time.tv_sec = 0;
|
|
|
|
time.tv_usec = 100 * 1000; /* 0.1 sec */
|
|
|
|
sleep_timeval(th, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_wait_for(struct timeval time)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2008-07-16 23:19:36 +04:00
|
|
|
sleep_timeval(th, time);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_polling(void)
|
|
|
|
{
|
2007-02-23 12:33:53 +03:00
|
|
|
RUBY_VM_CHECK_INTS();
|
2006-12-31 18:02:22 +03:00
|
|
|
if (!rb_thread_alone()) {
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2006-12-31 18:02:22 +03:00
|
|
|
sleep_for_polling(th);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:21:24 +04:00
|
|
|
/*
|
|
|
|
* CAUTION: This function causes thread switching.
|
|
|
|
* rb_thread_check_ints() check ruby's interrupts.
|
|
|
|
* some interrupt needs thread switching/invoke handlers,
|
|
|
|
* and so on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_check_ints(void)
|
|
|
|
{
|
|
|
|
RUBY_VM_CHECK_INTS();
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
struct timeval rb_time_timeval();
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_sleep(int sec)
|
|
|
|
{
|
|
|
|
rb_thread_wait_for(rb_time_timeval(INT2FIX(sec)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-03-19 06:58:57 +03:00
|
|
|
rb_thread_schedule(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
thread_debug("rb_thread_schedule\n");
|
|
|
|
if (!rb_thread_alone()) {
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
thread_debug("rb_thread_schedule/switch start\n");
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_gc_save_machine_context(th);
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_unlock(&th->vm->global_vm_lock);
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
native_thread_yield();
|
|
|
|
}
|
2008-06-15 20:48:02 +04:00
|
|
|
native_mutex_lock(&th->vm->global_vm_lock);
|
2006-12-31 18:02:22 +03: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 22:00:03 +03:00
|
|
|
rb_thread_set_current(th);
|
2006-12-31 18:02:22 +03:00
|
|
|
thread_debug("rb_thread_schedule/switch done\n");
|
|
|
|
|
* 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 22:00:03 +03:00
|
|
|
RUBY_VM_CHECK_INTS();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
int rb_thread_critical; /* TODO: dummy variable */
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
VALUE
|
2007-02-08 15:06:08 +03:00
|
|
|
rb_thread_blocking_region(
|
2007-08-27 20:48:14 +04:00
|
|
|
rb_blocking_function_t *func, void *data1,
|
|
|
|
rb_unblock_function_t *ubf, void *data2)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE val;
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-02-08 15:06:08 +03:00
|
|
|
|
2007-02-24 12:41:41 +03:00
|
|
|
if (ubf == RB_UBF_DFL) {
|
|
|
|
ubf = ubf_select;
|
2007-11-20 13:47:53 +03:00
|
|
|
data2 = th;
|
2007-02-24 12:41:41 +03:00
|
|
|
}
|
2007-08-27 20:48:14 +04:00
|
|
|
|
2007-02-08 15:06:08 +03:00
|
|
|
BLOCKING_REGION({
|
2007-11-20 13:47:53 +03:00
|
|
|
val = func(data1);
|
2008-06-19 18:18:46 +04:00
|
|
|
}, ubf, data2);
|
2007-02-08 15:06:08 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.pass => nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Invokes the thread scheduler to pass execution to another thread.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { print "a"; Thread.pass;
|
|
|
|
* print "b"; Thread.pass;
|
|
|
|
* print "c" }
|
|
|
|
* b = Thread.new { print "x"; Thread.pass;
|
|
|
|
* print "y"; Thread.pass;
|
|
|
|
* print "z" }
|
|
|
|
* a.join
|
|
|
|
* b.join
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* axbycz
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_s_pass(VALUE klass)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
rb_thread_schedule();
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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 09:37:46 +03:00
|
|
|
rb_thread_execute_interrupts(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-05-27 16:53:51 +04:00
|
|
|
if (th->raised_flag) return;
|
2008-07-27 09:59:32 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
while (th->interrupt_flag) {
|
2008-07-16 23:19:36 +04:00
|
|
|
enum rb_thread_status status = th->status;
|
2008-07-27 09:59:32 +04:00
|
|
|
int timer_interrupt = th->interrupt_flag & 0x01;
|
|
|
|
int finalizer_interrupt = th->interrupt_flag & 0x04;
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
th->status = THREAD_RUNNABLE;
|
|
|
|
th->interrupt_flag = 0;
|
|
|
|
|
|
|
|
/* signal handling */
|
|
|
|
if (th->exec_signal) {
|
|
|
|
int sig = th->exec_signal;
|
|
|
|
th->exec_signal = 0;
|
|
|
|
rb_signal_exec(th, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exception from another thread */
|
2007-04-02 16:54:42 +04:00
|
|
|
if (th->thrown_errinfo) {
|
|
|
|
VALUE err = th->thrown_errinfo;
|
|
|
|
th->thrown_errinfo = 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-07 04:25:05 +03:00
|
|
|
thread_debug("rb_thread_execute_interrupts: %ld\n", err);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-06-07 16:41:30 +04:00
|
|
|
if (err == eKillSignal || err == eTerminateSignal) {
|
2006-12-31 18:02:22 +03:00
|
|
|
th->errinfo = INT2FIX(TAG_FATAL);
|
|
|
|
TH_JUMP_TAG(th, TAG_FATAL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_exc_raise(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
th->status = status;
|
|
|
|
|
2008-07-27 09:59:32 +04:00
|
|
|
if (finalizer_interrupt) {
|
|
|
|
rb_gc_finalize_deferred();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer_interrupt) {
|
|
|
|
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
2008-08-14 01:26:49 +04:00
|
|
|
|
2008-08-13 11:53:35 +04:00
|
|
|
if (th->slice > 0) {
|
|
|
|
th->slice--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reschedule:
|
|
|
|
rb_thread_schedule();
|
|
|
|
if (th->slice < 0) {
|
|
|
|
th->slice++;
|
|
|
|
goto reschedule;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
th->slice = th->priority;
|
|
|
|
}
|
|
|
|
}
|
2008-07-27 09:59:32 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-03-19 06:58:57 +03:00
|
|
|
rb_gc_mark_threads(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 19:26:04 +03:00
|
|
|
/* TODO: remove */
|
2006-12-31 18:02:22 +03: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 09:37:46 +03:00
|
|
|
rb_thread_ready(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
rb_thread_interrupt(th);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-08 14:51:40 +03:00
|
|
|
rb_thread_raise(int argc, VALUE *argv, rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE exc;
|
|
|
|
|
2007-08-13 00:06:59 +04:00
|
|
|
again:
|
2006-12-31 18:02:22 +03:00
|
|
|
if (rb_thread_dead(th)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:06:59 +04:00
|
|
|
if (th->thrown_errinfo != 0 || th->raised_flag) {
|
|
|
|
rb_thread_schedule();
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
exc = rb_make_exception(argc, argv);
|
2007-04-02 16:54:42 +04:00
|
|
|
th->thrown_errinfo = exc;
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_thread_ready(th);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-04-19 21:37:03 +04:00
|
|
|
rb_thread_signal_raise(void *thptr, int sig)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-04-19 21:37:03 +04:00
|
|
|
VALUE argv[2];
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = thptr;
|
2007-04-19 21:37:03 +04:00
|
|
|
|
|
|
|
argv[0] = rb_eSignal;
|
|
|
|
argv[1] = INT2FIX(sig);
|
|
|
|
rb_thread_raise(2, argv, th->vm->main_thread);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_signal_exit(void *thptr)
|
|
|
|
{
|
2007-04-19 21:37:03 +04:00
|
|
|
VALUE argv[2];
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = thptr;
|
2007-04-19 21:37:03 +04:00
|
|
|
|
|
|
|
argv[0] = rb_eSystemExit;
|
|
|
|
argv[1] = rb_str_new2("exit");
|
|
|
|
rb_thread_raise(2, argv, th->vm->main_thread);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
int
|
2008-02-28 07:52:01 +03:00
|
|
|
rb_thread_set_raised(rb_thread_t *th)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
2008-02-28 07:52:01 +03:00
|
|
|
if (th->raised_flag & RAISED_EXCEPTION) {
|
2007-02-05 15:21:01 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2008-02-28 07:52:01 +03:00
|
|
|
th->raised_flag |= RAISED_EXCEPTION;
|
2007-02-05 15:21:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-02-28 07:52:01 +03:00
|
|
|
rb_thread_reset_raised(rb_thread_t *th)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
2008-02-28 07:52:01 +03:00
|
|
|
if (!(th->raised_flag & RAISED_EXCEPTION)) {
|
2007-02-05 15:21:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-28 07:52:01 +03:00
|
|
|
th->raised_flag &= ~RAISED_EXCEPTION;
|
2007-02-05 15:21:01 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_fd_close(int fd)
|
|
|
|
{
|
|
|
|
/* TODO: fix me */
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.raise(exception)
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Raises an exception (see <code>Kernel::raise</code>) from <i>thr</i>. The
|
|
|
|
* caller does not have to be <i>thr</i>.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.abort_on_exception = true
|
|
|
|
* a = Thread.new { sleep(200) }
|
|
|
|
* a.raise("Gotcha")
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* prog.rb:3: Gotcha (RuntimeError)
|
|
|
|
* from prog.rb:2:in `initialize'
|
|
|
|
* from prog.rb:2:in `new'
|
|
|
|
* from prog.rb:2
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_raise_m(int argc, VALUE *argv, VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(self, th);
|
2007-02-08 14:51:40 +03:00
|
|
|
rb_thread_raise(argc, argv, th);
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.exit => thr or nil
|
|
|
|
* thr.kill => thr or nil
|
|
|
|
* thr.terminate => thr or nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Terminates <i>thr</i> and schedules another thread to be run. If this thread
|
|
|
|
* is already marked to be killed, <code>exit</code> returns the
|
|
|
|
* <code>Thread</code>. If this is the main thread, or the last thread, exits
|
|
|
|
* the process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_kill(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (th != GET_THREAD() && th->safe_level < 4) {
|
|
|
|
rb_secure(4);
|
|
|
|
}
|
|
|
|
if (th->status == THREAD_TO_KILL || th->status == THREAD_KILLED) {
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
if (th == th->vm->main_thread) {
|
|
|
|
rb_exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
* 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-07 04:25:05 +03:00
|
|
|
thread_debug("rb_thread_kill: %p (%p)\n", th, (void *)th->thread_id);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_thread_interrupt(th);
|
2007-04-02 16:54:42 +04:00
|
|
|
th->thrown_errinfo = eKillSignal;
|
2006-12-31 18:02:22 +03:00
|
|
|
th->status = THREAD_TO_KILL;
|
|
|
|
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.kill(thread) => thread
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Causes the given <em>thread</em> to exit (see <code>Thread::exit</code>).
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* count = 0
|
|
|
|
* a = Thread.new { loop { count += 1 } }
|
|
|
|
* sleep(0.1) #=> 0
|
|
|
|
* Thread.kill(a) #=> #<Thread:0x401b3d30 dead>
|
|
|
|
* count #=> 93947
|
|
|
|
* a.alive? #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_s_kill(VALUE obj, VALUE th)
|
|
|
|
{
|
|
|
|
return rb_thread_kill(th);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.exit => thread
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Terminates the currently running thread and schedules another thread to be
|
|
|
|
* run. If this thread is already marked to be killed, <code>exit</code>
|
|
|
|
* returns the <code>Thread</code>. If this is the main thread, or the last
|
|
|
|
* thread, exit the process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-03-19 06:58:57 +03:00
|
|
|
rb_thread_exit(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
return rb_thread_kill(GET_THREAD()->self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.wakeup => thr
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Marks <i>thr</i> as eligible for scheduling (it may still remain blocked on
|
|
|
|
* I/O, however). Does not invoke the scheduler (see <code>Thread#run</code>).
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* c = Thread.new { Thread.stop; puts "hey!" }
|
|
|
|
* c.wakeup
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* hey!
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_wakeup(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (th->status == THREAD_KILLED) {
|
|
|
|
rb_raise(rb_eThreadError, "killed thread");
|
|
|
|
}
|
|
|
|
rb_thread_ready(th);
|
2008-07-16 23:19:36 +04:00
|
|
|
if (th->status != THREAD_TO_KILL) {
|
|
|
|
th->status = THREAD_RUNNABLE;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.run => thr
|
* 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 08:25:10 +04:00
|
|
|
*
|
2007-12-25 16:14:23 +03:00
|
|
|
* Wakes up <i>thr</i>, making it eligible for scheduling.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { puts "a"; Thread.stop; puts "c" }
|
|
|
|
* Thread.pass
|
|
|
|
* puts "Got here"
|
|
|
|
* a.run
|
|
|
|
* a.join
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a
|
|
|
|
* Got here
|
|
|
|
* c
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
2007-02-25 05:36:58 +03:00
|
|
|
rb_thread_run(VALUE thread)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
rb_thread_wakeup(thread);
|
|
|
|
rb_thread_schedule();
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.stop => nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Stops execution of the current thread, putting it into a ``sleep'' state,
|
2007-12-25 16:14:23 +03:00
|
|
|
* and schedules execution of another thread.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { print "a"; Thread.stop; print "c" }
|
|
|
|
* Thread.pass
|
|
|
|
* print "b"
|
|
|
|
* a.run
|
|
|
|
* a.join
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* abc
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_stop(void)
|
|
|
|
{
|
|
|
|
if (rb_thread_alone()) {
|
|
|
|
rb_raise(rb_eThreadError,
|
|
|
|
"stopping only thread\n\tnote: use sleep to stop forever");
|
|
|
|
}
|
2008-06-12 17:01:38 +04:00
|
|
|
rb_thread_sleep_deadly();
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
thread_list_i(st_data_t key, st_data_t val, void *data)
|
|
|
|
{
|
|
|
|
VALUE ary = (VALUE)data;
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr((VALUE)key, th);
|
|
|
|
|
|
|
|
switch (th->status) {
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_RUNNABLE:
|
|
|
|
case THREAD_STOPPED:
|
2008-06-12 17:01:38 +04:00
|
|
|
case THREAD_STOPPED_FOREVER:
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_TO_KILL:
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ary, th->self);
|
* 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 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.list => array
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns an array of <code>Thread</code> objects for all threads that are
|
|
|
|
* either runnable or stopped.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.new { sleep(200) }
|
|
|
|
* Thread.new { 1000000.times {|i| i*i } }
|
|
|
|
* Thread.new { Thread.stop }
|
|
|
|
* Thread.list.each {|t| p t}
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* #<Thread:0x401b3e84 sleep>
|
|
|
|
* #<Thread:0x401b3f38 run>
|
|
|
|
* #<Thread:0x401b3fb0 sleep>
|
|
|
|
* #<Thread:0x401bdf4c run>
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_list(void)
|
|
|
|
{
|
|
|
|
VALUE ary = rb_ary_new();
|
|
|
|
st_foreach(GET_THREAD()->vm->living_threads, thread_list_i, ary);
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
VALUE
|
|
|
|
rb_thread_current(void)
|
|
|
|
{
|
|
|
|
return GET_THREAD()->self;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.current => thread
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the currently executing thread.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.current #=> #<Thread:0x401bdf4c run>
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-02-05 15:21:01 +03:00
|
|
|
thread_s_current(VALUE klass)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-02-05 15:21:01 +03:00
|
|
|
return rb_thread_current();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_main(void)
|
|
|
|
{
|
|
|
|
return GET_THREAD()->vm->main_thread->self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_s_main(VALUE klass)
|
|
|
|
{
|
|
|
|
return rb_thread_main();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.abort_on_exception => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the status of the global ``abort on exception'' condition. The
|
|
|
|
* default is <code>false</code>. When set to <code>true</code>, or if the
|
|
|
|
* global <code>$DEBUG</code> flag is <code>true</code> (perhaps because the
|
|
|
|
* command line option <code>-d</code> was specified) all threads will abort
|
|
|
|
* (the process will <code>exit(0)</code>) if an exception is raised in any
|
|
|
|
* thread. See also <code>Thread::abort_on_exception=</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-03-19 06:58:57 +03:00
|
|
|
rb_thread_s_abort_exc(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
return GET_THREAD()->vm->thread_abort_on_exception ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Thread.abort_on_exception= boolean => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* When set to <code>true</code>, all threads will abort if an exception is
|
|
|
|
* raised. Returns the new state.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.abort_on_exception = true
|
|
|
|
* t1 = Thread.new do
|
|
|
|
* puts "In new thread"
|
|
|
|
* raise "Exception from thread"
|
|
|
|
* end
|
|
|
|
* sleep(1)
|
|
|
|
* puts "not reached"
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* In new thread
|
|
|
|
* prog.rb:4: Exception from thread (RuntimeError)
|
|
|
|
* from prog.rb:2:in `initialize'
|
|
|
|
* from prog.rb:2:in `new'
|
|
|
|
* from prog.rb:2
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_s_abort_exc_set(VALUE self, VALUE val)
|
|
|
|
{
|
|
|
|
rb_secure(4);
|
|
|
|
GET_THREAD()->vm->thread_abort_on_exception = RTEST(val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.abort_on_exception => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the status of the thread-local ``abort on exception'' condition for
|
|
|
|
* <i>thr</i>. The default is <code>false</code>. See also
|
|
|
|
* <code>Thread::abort_on_exception=</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_abort_exc(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
return th->abort_on_exception ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.abort_on_exception= boolean => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* When set to <code>true</code>, causes all threads (including the main
|
|
|
|
* program) to abort if an exception is raised in <i>thr</i>. The process will
|
|
|
|
* effectively <code>exit(0)</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_abort_exc_set(VALUE thread, VALUE val)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_secure(4);
|
|
|
|
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
th->abort_on_exception = RTEST(val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.group => thgrp or nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the <code>ThreadGroup</code> which contains <i>thr</i>, or nil if
|
|
|
|
* the thread is not a member of any group.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.main.group #=> #<ThreadGroup:0x4029d914>
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_group(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE group;
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
group = th->thgroup;
|
|
|
|
|
|
|
|
if (!group) {
|
|
|
|
group = Qnil;
|
|
|
|
}
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
* 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 22:00:03 +03:00
|
|
|
thread_status_name(enum rb_thread_status status)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
switch (status) {
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_RUNNABLE:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "run";
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_STOPPED:
|
2008-06-12 17:01:38 +04:00
|
|
|
case THREAD_STOPPED_FOREVER:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "sleep";
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_TO_KILL:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "aborting";
|
* 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 08:25:10 +04:00
|
|
|
case THREAD_KILLED:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "dead";
|
* 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 08:25:10 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 09:37:46 +03:00
|
|
|
rb_thread_dead(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
return th->status == THREAD_KILLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.status => string, false or nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the status of <i>thr</i>: ``<code>sleep</code>'' if <i>thr</i> is
|
|
|
|
* sleeping or waiting on I/O, ``<code>run</code>'' if <i>thr</i> is executing,
|
|
|
|
* ``<code>aborting</code>'' if <i>thr</i> is aborting, <code>false</code> if
|
|
|
|
* <i>thr</i> terminated normally, and <code>nil</code> if <i>thr</i>
|
|
|
|
* terminated with an exception.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { raise("die now") }
|
|
|
|
* b = Thread.new { Thread.stop }
|
|
|
|
* c = Thread.new { Thread.exit }
|
|
|
|
* d = Thread.new { sleep }
|
|
|
|
* d.kill #=> #<Thread:0x401b3678 aborting>
|
|
|
|
* a.status #=> nil
|
|
|
|
* b.status #=> "sleep"
|
|
|
|
* c.status #=> false
|
|
|
|
* d.status #=> "aborting"
|
|
|
|
* Thread.current.status #=> "run"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_status(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (rb_thread_dead(th)) {
|
|
|
|
if (!NIL_P(th->errinfo) && !FIXNUM_P(th->errinfo)
|
|
|
|
/* TODO */ ) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
return rb_str_new2(thread_status_name(th->status));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.alive? => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns <code>true</code> if <i>thr</i> is running or sleeping.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* thr = Thread.new { }
|
|
|
|
* thr.join #=> #<Thread:0x401b3fb0 dead>
|
|
|
|
* Thread.current.alive? #=> true
|
|
|
|
* thr.alive? #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_alive_p(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (rb_thread_dead(th))
|
|
|
|
return Qfalse;
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.stop? => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns <code>true</code> if <i>thr</i> is dead or sleeping.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { Thread.stop }
|
|
|
|
* b = Thread.current
|
|
|
|
* a.stop? #=> true
|
|
|
|
* b.stop? #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_stop_p(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (rb_thread_dead(th))
|
|
|
|
return Qtrue;
|
2008-06-12 17:01:38 +04:00
|
|
|
if (th->status == THREAD_STOPPED || th->status == THREAD_STOPPED_FOREVER)
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.safe_level => integer
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns the safe level in effect for <i>thr</i>. Setting thread-local safe
|
|
|
|
* levels can help when implementing sandboxes which run insecure code.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* thr = Thread.new { $SAFE = 3; sleep }
|
|
|
|
* Thread.current.safe_level #=> 0
|
|
|
|
* thr.safe_level #=> 3
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_safe_level(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
return INT2NUM(th->safe_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.inspect => string
|
|
|
|
*
|
|
|
|
* Dump the name, id, and status of _thr_ to a string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_inspect(VALUE thread)
|
|
|
|
{
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname = rb_obj_classname(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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
const char *status;
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
status = thread_status_name(th->status);
|
|
|
|
str = rb_sprintf("#<%s:%p %s>", cname, (void *)thread, status);
|
|
|
|
OBJ_INFECT(str, thread);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_local_aref(VALUE thread, ID id)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE val;
|
|
|
|
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: thread locals");
|
|
|
|
}
|
|
|
|
if (!th->local_storage) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
if (st_lookup(th->local_storage, id, &val)) {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr[sym] => obj or nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Attribute Reference---Returns the value of a thread-local variable, using
|
|
|
|
* either a symbol or a string name. If the specified variable does not exist,
|
|
|
|
* returns <code>nil</code>.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* a = Thread.new { Thread.current["name"] = "A"; Thread.stop }
|
|
|
|
* b = Thread.new { Thread.current[:name] = "B"; Thread.stop }
|
|
|
|
* c = Thread.new { Thread.current["name"] = "C"; Thread.stop }
|
|
|
|
* Thread.list.each {|x| puts "#{x.inspect}: #{x[:name]}" }
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* #<Thread:0x401b3b3c sleep>: C
|
|
|
|
* #<Thread:0x401b3bc8 sleep>: B
|
|
|
|
* #<Thread:0x401b3c68 sleep>: A
|
|
|
|
* #<Thread:0x401bdf4c run>:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_aref(VALUE thread, VALUE id)
|
|
|
|
{
|
|
|
|
return rb_thread_local_aref(thread, rb_to_id(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_local_aset(VALUE thread, ID id, VALUE val)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't modify thread locals");
|
|
|
|
}
|
|
|
|
if (OBJ_FROZEN(thread)) {
|
|
|
|
rb_error_frozen("thread locals");
|
|
|
|
}
|
|
|
|
if (!th->local_storage) {
|
|
|
|
th->local_storage = st_init_numtable();
|
|
|
|
}
|
|
|
|
if (NIL_P(val)) {
|
2008-05-08 01:27:34 +04:00
|
|
|
st_delete_wrap(th->local_storage, id);
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
st_insert(th->local_storage, id, val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr[sym] = obj => obj
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Attribute Assignment---Sets or creates the value of a thread-local variable,
|
|
|
|
* using either a symbol or a string. See also <code>Thread#[]</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_aset(VALUE self, ID id, VALUE val)
|
|
|
|
{
|
|
|
|
return rb_thread_local_aset(self, rb_to_id(id), val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.key?(sym) => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns <code>true</code> if the given string (or symbol) exists as a
|
|
|
|
* thread-local variable.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* me = Thread.current
|
|
|
|
* me[:oliver] = "a"
|
|
|
|
* me.key?(:oliver) #=> true
|
|
|
|
* me.key?(:stanley) #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2008-05-07 17:24:03 +04:00
|
|
|
rb_thread_key_p(VALUE self, VALUE key)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2008-05-07 17:24:03 +04:00
|
|
|
ID id = rb_to_id(key);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(self, th);
|
|
|
|
|
|
|
|
if (!th->local_storage) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2008-05-08 01:27:34 +04:00
|
|
|
if (st_lookup(th->local_storage, id, 0)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
thread_keys_i(ID key, VALUE value, VALUE ary)
|
|
|
|
{
|
|
|
|
rb_ary_push(ary, ID2SYM(key));
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
static int
|
|
|
|
vm_living_thread_num(rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
return vm->living_threads->num_entries;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
int
|
|
|
|
rb_thread_alone()
|
|
|
|
{
|
|
|
|
int num = 1;
|
|
|
|
if (GET_THREAD()->vm->living_threads) {
|
2008-06-19 18:18:46 +04:00
|
|
|
num = vm_living_thread_num(GET_THREAD()->vm);
|
2006-12-31 18:02:22 +03:00
|
|
|
thread_debug("rb_thread_alone: %d\n", num);
|
|
|
|
}
|
|
|
|
return num == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.keys => array
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns an an array of the names of the thread-local variables (as Symbols).
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* thr = Thread.new do
|
|
|
|
* Thread.current[:cat] = 'meow'
|
|
|
|
* Thread.current["dog"] = 'woof'
|
|
|
|
* end
|
|
|
|
* thr.join #=> #<Thread:0x401b3f10 dead>
|
|
|
|
* thr.keys #=> [:dog, :cat]
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_keys(VALUE self)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE ary = rb_ary_new();
|
|
|
|
GetThreadPtr(self, th);
|
|
|
|
|
|
|
|
if (th->local_storage) {
|
|
|
|
st_foreach(th->local_storage, thread_keys_i, ary);
|
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.priority => integer
|
2007-05-10 05:12:10 +04:00
|
|
|
*
|
|
|
|
* Returns the priority of <i>thr</i>. Default is inherited from the
|
|
|
|
* current thread which creating the new thread, or zero for the
|
|
|
|
* initial main thread; higher-priority threads will run before
|
|
|
|
* lower-priority threads.
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Thread.current.priority #=> 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_priority(VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
return INT2NUM(th->priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thr.priority= integer => thr
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Sets the priority of <i>thr</i> to <i>integer</i>. Higher-priority threads
|
|
|
|
* will run before lower-priority threads.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* count1 = count2 = 0
|
|
|
|
* a = Thread.new do
|
|
|
|
* loop { count1 += 1 }
|
|
|
|
* end
|
|
|
|
* a.priority = -1
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* b = Thread.new do
|
|
|
|
* loop { count2 += 1 }
|
|
|
|
* end
|
|
|
|
* b.priority = -2
|
|
|
|
* sleep 1 #=> 1
|
|
|
|
* count1 #=> 622504
|
|
|
|
* count2 #=> 5832
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_thread_priority_set(VALUE thread, VALUE prio)
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2008-08-13 11:53:35 +04:00
|
|
|
int priority;
|
2008-08-14 09:56:51 +04:00
|
|
|
GetThreadPtr(thread, th);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
|
2008-08-13 11:53:35 +04:00
|
|
|
#if USE_NATIVE_THREAD_PRIORITY
|
2006-12-31 18:02:22 +03:00
|
|
|
th->priority = NUM2INT(prio);
|
|
|
|
native_thread_apply_priority(th);
|
2008-08-13 11:53:35 +04:00
|
|
|
#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);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* for IO */
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT)
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_fd_init(volatile rb_fdset_t *fds)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-02-05 15:21:01 +03:00
|
|
|
fds->maxfd = 0;
|
|
|
|
fds->fdset = ALLOC(fd_set);
|
|
|
|
FD_ZERO(fds->fdset);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
void
|
|
|
|
rb_fd_term(rb_fdset_t *fds)
|
|
|
|
{
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
if (fds->fdset) xfree(fds->fdset);
|
2007-02-05 15:21:01 +03:00
|
|
|
fds->maxfd = 0;
|
|
|
|
fds->fdset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_fd_zero(rb_fdset_t *fds)
|
|
|
|
{
|
|
|
|
if (fds->fdset) {
|
|
|
|
MEMZERO(fds->fdset, fd_mask, howmany(fds->maxfd, NFDBITS));
|
|
|
|
FD_ZERO(fds->fdset);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_fd_resize(int n, rb_fdset_t *fds)
|
|
|
|
{
|
|
|
|
int m = howmany(n + 1, NFDBITS) * sizeof(fd_mask);
|
|
|
|
int o = howmany(fds->maxfd, NFDBITS) * sizeof(fd_mask);
|
|
|
|
|
|
|
|
if (m < sizeof(fd_set)) m = sizeof(fd_set);
|
|
|
|
if (o < sizeof(fd_set)) o = sizeof(fd_set);
|
|
|
|
|
|
|
|
if (m > o) {
|
|
|
|
fds->fdset = realloc(fds->fdset, m);
|
|
|
|
memset((char *)fds->fdset + o, 0, m - o);
|
|
|
|
}
|
|
|
|
if (n >= fds->maxfd) fds->maxfd = n + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_fd_set(int n, rb_fdset_t *fds)
|
|
|
|
{
|
|
|
|
rb_fd_resize(n, fds);
|
|
|
|
FD_SET(n, fds->fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_fd_clr(int n, rb_fdset_t *fds)
|
|
|
|
{
|
|
|
|
if (n >= fds->maxfd) return;
|
|
|
|
FD_CLR(n, fds->fdset);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_fd_isset(int n, const rb_fdset_t *fds)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-02-05 15:21:01 +03:00
|
|
|
if (n >= fds->maxfd) return 0;
|
|
|
|
return FD_ISSET(n, fds->fdset) != 0; /* "!= 0" avoids FreeBSD PR 91421 */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
|
|
|
|
{
|
|
|
|
int size = howmany(max, NFDBITS) * sizeof(fd_mask);
|
|
|
|
|
|
|
|
if (size < sizeof(fd_set)) size = sizeof(fd_set);
|
|
|
|
dst->maxfd = max;
|
|
|
|
dst->fdset = realloc(dst->fdset, size);
|
|
|
|
memcpy(dst->fdset, src, size);
|
|
|
|
}
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
int
|
|
|
|
rb_fd_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *exceptfds, struct timeval *timeout)
|
|
|
|
{
|
|
|
|
fd_set *r = NULL, *w = NULL, *e = NULL;
|
|
|
|
if (readfds) {
|
|
|
|
rb_fd_resize(n - 1, readfds);
|
|
|
|
r = rb_fd_ptr(readfds);
|
|
|
|
}
|
|
|
|
if (writefds) {
|
|
|
|
rb_fd_resize(n - 1, writefds);
|
|
|
|
w = rb_fd_ptr(writefds);
|
|
|
|
}
|
|
|
|
if (exceptfds) {
|
|
|
|
rb_fd_resize(n - 1, exceptfds);
|
|
|
|
e = rb_fd_ptr(exceptfds);
|
|
|
|
}
|
|
|
|
return select(n, r, w, e, timeout);
|
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
#undef FD_ZERO
|
|
|
|
#undef FD_SET
|
|
|
|
#undef FD_CLR
|
|
|
|
#undef FD_ISSET
|
|
|
|
|
|
|
|
#define FD_ZERO(f) rb_fd_zero(f)
|
|
|
|
#define FD_SET(i, f) rb_fd_set(i, f)
|
|
|
|
#define FD_CLR(i, f) rb_fd_clr(i, f)
|
|
|
|
#define FD_ISSET(i, f) rb_fd_isset(i, f)
|
|
|
|
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-03-08 03:23:14 +03:00
|
|
|
#if defined(__CYGWIN__) || defined(_WIN32)
|
2007-02-08 14:51:40 +03:00
|
|
|
static long
|
|
|
|
cmp_tv(const struct timeval *a, const struct timeval *b)
|
|
|
|
{
|
|
|
|
long d = (a->tv_sec - b->tv_sec);
|
|
|
|
return (d != 0) ? d : (a->tv_usec - b->tv_usec);
|
|
|
|
}
|
|
|
|
|
* 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 08:25:10 +04:00
|
|
|
static int
|
2008-07-30 12:48:31 +04:00
|
|
|
subtract_tv(struct timeval *rest, const struct timeval *wait)
|
2007-02-08 14:51:40 +03:00
|
|
|
{
|
|
|
|
while (rest->tv_usec < wait->tv_usec) {
|
|
|
|
if (rest->tv_sec <= wait->tv_sec) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rest->tv_sec -= 1;
|
|
|
|
rest->tv_usec += 1000 * 1000;
|
|
|
|
}
|
|
|
|
rest->tv_sec -= wait->tv_sec;
|
|
|
|
rest->tv_usec -= wait->tv_usec;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-03-08 03:23:14 +03:00
|
|
|
#endif
|
2007-02-08 14:51:40 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
do_select(int n, fd_set *read, fd_set *write, fd_set *except,
|
|
|
|
struct timeval *timeout)
|
|
|
|
{
|
2007-02-14 07:02:12 +03:00
|
|
|
int result, lerrno;
|
2007-02-08 14:51:40 +03:00
|
|
|
fd_set orig_read, orig_write, orig_except;
|
2007-02-14 07:02:12 +03:00
|
|
|
|
|
|
|
#ifndef linux
|
2008-04-26 13:36:35 +04:00
|
|
|
double limit = 0;
|
2007-02-14 07:02:12 +03:00
|
|
|
struct timeval wait_rest;
|
2008-07-30 12:48:31 +04:00
|
|
|
# if defined(__CYGWIN__) || defined(_WIN32)
|
|
|
|
struct timeval start_time;
|
|
|
|
# endif
|
2007-02-14 07:02:12 +03:00
|
|
|
|
|
|
|
if (timeout) {
|
2008-07-30 12:48:31 +04:00
|
|
|
# if defined(__CYGWIN__) || defined(_WIN32)
|
|
|
|
gettimeofday(&start_time, NULL);
|
|
|
|
limit = (double)start_time.tv_sec + (double)start_time.tv_usec*1e-6;
|
|
|
|
# else
|
|
|
|
limit = timeofday();
|
|
|
|
# endif
|
|
|
|
limit += (double)timeout->tv_sec+(double)timeout->tv_usec*1e-6;
|
2007-02-14 07:02:12 +03:00
|
|
|
wait_rest = *timeout;
|
|
|
|
timeout = &wait_rest;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (read) orig_read = *read;
|
|
|
|
if (write) orig_write = *write;
|
|
|
|
if (except) orig_except = *except;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
lerrno = 0;
|
|
|
|
|
|
|
|
#if defined(__CYGWIN__) || defined(_WIN32)
|
|
|
|
{
|
2008-07-30 12:48:31 +04:00
|
|
|
int finish = 0;
|
2007-02-14 07:02:12 +03:00
|
|
|
/* polling duration: 100ms */
|
|
|
|
struct timeval wait_100ms, *wait;
|
|
|
|
wait_100ms.tv_sec = 0;
|
|
|
|
wait_100ms.tv_usec = 100 * 1000; /* 100 ms */
|
|
|
|
|
|
|
|
do {
|
|
|
|
wait = (timeout == 0 || cmp_tv(&wait_100ms, timeout) > 0) ? &wait_100ms : timeout;
|
|
|
|
BLOCKING_REGION({
|
|
|
|
do {
|
|
|
|
result = select(n, read, write, except, wait);
|
|
|
|
if (result < 0) lerrno = errno;
|
|
|
|
if (result != 0) break;
|
|
|
|
|
|
|
|
if (read) *read = orig_read;
|
|
|
|
if (write) *write = orig_write;
|
|
|
|
if (except) *except = orig_except;
|
|
|
|
wait = &wait_100ms;
|
2008-07-30 12:48:31 +04:00
|
|
|
if (timeout) {
|
|
|
|
struct timeval elapsed;
|
|
|
|
gettimeofday(&elapsed, NULL);
|
|
|
|
subtract_tv(&elapsed, &start_time);
|
|
|
|
if (!subtract_tv(timeout, &elapsed)) {
|
|
|
|
finish = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cmp_tv(&wait_100ms, timeout) < 0) wait = timeout;
|
|
|
|
}
|
|
|
|
} while (__th->interrupt_flag == 0);
|
2008-06-19 18:18:46 +04:00
|
|
|
}, 0, 0);
|
2008-07-30 12:48:31 +04:00
|
|
|
} while (result == 0 && !finish);
|
2007-02-14 07:02:12 +03:00
|
|
|
}
|
2007-02-08 14:51:40 +03:00
|
|
|
#else
|
2007-02-08 15:06:08 +03:00
|
|
|
BLOCKING_REGION({
|
2007-02-08 14:51:40 +03:00
|
|
|
result = select(n, read, write, except, timeout);
|
|
|
|
if (result < 0) lerrno = errno;
|
2008-06-19 18:18:46 +04:00
|
|
|
}, ubf_select, GET_THREAD());
|
2007-02-08 14:51:40 +03:00
|
|
|
#endif
|
2007-02-14 07:02:12 +03:00
|
|
|
|
2007-02-08 14:51:40 +03:00
|
|
|
errno = lerrno;
|
2007-02-14 07:02:12 +03:00
|
|
|
|
|
|
|
if (result < 0) {
|
2008-04-26 13:36:35 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EINTR:
|
2007-02-14 07:02:12 +03:00
|
|
|
#ifdef ERESTART
|
2008-04-26 13:36:35 +04:00
|
|
|
case ERESTART:
|
2007-02-14 07:02:12 +03:00
|
|
|
#endif
|
|
|
|
if (read) *read = orig_read;
|
|
|
|
if (write) *write = orig_write;
|
|
|
|
if (except) *except = orig_except;
|
|
|
|
#ifndef linux
|
|
|
|
if (timeout) {
|
|
|
|
double d = limit - timeofday();
|
|
|
|
|
|
|
|
wait_rest.tv_sec = (unsigned int)d;
|
|
|
|
wait_rest.tv_usec = (long)((d-(double)wait_rest.tv_sec)*1e6);
|
|
|
|
if (wait_rest.tv_sec < 0) wait_rest.tv_sec = 0;
|
|
|
|
if (wait_rest.tv_usec < 0) wait_rest.tv_usec = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
goto retry;
|
2008-04-26 13:36:35 +04:00
|
|
|
default:
|
|
|
|
break;
|
2007-02-14 07:02:12 +03:00
|
|
|
}
|
|
|
|
}
|
2007-02-08 14:51:40 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
static void
|
2007-02-14 07:02:12 +03:00
|
|
|
rb_thread_wait_fd_rw(int fd, int read)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
|
|
|
int result = 0;
|
2007-02-14 07:02:12 +03:00
|
|
|
thread_debug("rb_thread_wait_fd_rw(%d, %s)\n", fd, read ? "read" : "write");
|
2007-02-05 15:21:01 +03:00
|
|
|
|
2008-07-11 15:51:39 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
rb_raise(rb_eIOError, "closed stream");
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
while (result <= 0) {
|
2007-02-08 14:51:40 +03:00
|
|
|
rb_fdset_t set;
|
|
|
|
rb_fd_init(&set);
|
|
|
|
FD_SET(fd, &set);
|
|
|
|
|
2007-02-14 07:02:12 +03:00
|
|
|
if (read) {
|
2007-02-08 14:51:40 +03:00
|
|
|
result = do_select(fd + 1, rb_fd_ptr(&set), 0, 0, 0);
|
2007-02-14 07:02:12 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-02-08 14:51:40 +03:00
|
|
|
result = do_select(fd + 1, 0, rb_fd_ptr(&set), 0, 0);
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
2007-02-20 09:07:05 +03:00
|
|
|
|
2007-06-26 11:30:01 +04:00
|
|
|
rb_fd_term(&set);
|
|
|
|
|
2007-12-25 07:47:47 +03:00
|
|
|
if (result < 0) {
|
2007-02-20 09:07:05 +03:00
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-05 15:21:01 +03:00
|
|
|
|
2007-02-14 07:02:12 +03:00
|
|
|
thread_debug("rb_thread_wait_fd_rw(%d, %s): done\n", fd, read ? "read" : "write");
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_wait_fd(int fd)
|
|
|
|
{
|
2007-02-14 07:02:12 +03:00
|
|
|
rb_thread_wait_fd_rw(fd, 1);
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_thread_fd_writable(int fd)
|
|
|
|
{
|
2007-02-14 07:02:12 +03:00
|
|
|
rb_thread_wait_fd_rw(fd, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_thread_select(int max, fd_set * read, fd_set * write, fd_set * except,
|
|
|
|
struct timeval *timeout)
|
|
|
|
{
|
|
|
|
if (!read && !write && !except) {
|
|
|
|
if (!timeout) {
|
|
|
|
rb_thread_sleep_forever();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rb_thread_wait_for(*timeout);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-14 07:02:12 +03:00
|
|
|
else {
|
|
|
|
return do_select(max, read, write, except, timeout);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-02-20 09:07:05 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for GC
|
|
|
|
*/
|
|
|
|
|
2007-07-14 11:19:59 +04:00
|
|
|
#ifdef USE_CONSERVATIVE_STACK_END
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_gc_set_stack_end(VALUE **stack_end_p)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE stack_end;
|
|
|
|
*stack_end_p = &stack_end;
|
|
|
|
}
|
2007-07-14 11:19:59 +04:00
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
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 09:37:46 +03:00
|
|
|
rb_gc_save_machine_context(rb_thread_t *th)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-07-14 11:19:59 +04:00
|
|
|
SET_MACHINE_STACK_END(&th->machine_stack_end);
|
2008-05-08 10:59:03 +04:00
|
|
|
FLUSH_REGISTER_WINDOWS;
|
2007-06-14 12:35:20 +04:00
|
|
|
#ifdef __ia64
|
|
|
|
th->machine_register_stack_end = rb_ia64_bsp();
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
setjmp(th->machine_regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
* 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 22:00:03 +03:00
|
|
|
int rb_get_next_signal(rb_vm_t *vm);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
static void
|
2008-07-05 17:22:29 +04:00
|
|
|
timer_thread_function(void *arg)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-07-05 17:22:29 +04:00
|
|
|
rb_vm_t *vm = arg; /* TODO: fix me for Multi-VM */
|
2007-04-25 07:50:00 +04:00
|
|
|
|
|
|
|
/* for time slice */
|
2007-12-25 07:16:06 +03:00
|
|
|
RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread);
|
2007-04-25 07:50:00 +04:00
|
|
|
|
|
|
|
/* check signal */
|
2007-09-28 11:25:51 +04:00
|
|
|
if (vm->buffered_signal_size && vm->main_thread->exec_signal == 0) {
|
2008-07-16 23:19:36 +04:00
|
|
|
rb_thread_t *mth = vm->main_thread;
|
|
|
|
enum rb_thread_status prev_status = mth->status;
|
|
|
|
mth->exec_signal = rb_get_next_signal(vm);
|
|
|
|
thread_debug("main_thread: %s\n", thread_status_name(prev_status));
|
2008-04-26 13:36:35 +04:00
|
|
|
thread_debug("buffered_signal_size: %ld, sig: %d\n",
|
|
|
|
(long)vm->buffered_signal_size, vm->main_thread->exec_signal);
|
2008-07-16 23:19:36 +04:00
|
|
|
if (mth->status != THREAD_KILLED) mth->status = THREAD_RUNNABLE;
|
|
|
|
rb_thread_interrupt(mth);
|
|
|
|
mth->status = prev_status;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-04-25 07:50:00 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* prove profiler */
|
|
|
|
if (vm->prove_profile.enable) {
|
|
|
|
rb_thread_t *th = vm->running_thread;
|
|
|
|
|
|
|
|
if (vm->during_gc) {
|
|
|
|
/* GC prove profiling */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-01-07 12:47:52 +03:00
|
|
|
void
|
|
|
|
rb_thread_stop_timer_thread(void)
|
|
|
|
{
|
|
|
|
if (timer_thread_id) {
|
|
|
|
system_working = 0;
|
|
|
|
native_thread_join(timer_thread_id);
|
2008-04-22 08:26:44 +04:00
|
|
|
timer_thread_id = 0;
|
2007-01-07 12:47:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_reset_timer_thread(void)
|
|
|
|
{
|
|
|
|
timer_thread_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_start_timer_thread(void)
|
|
|
|
{
|
|
|
|
rb_thread_create_timer_thread();
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:55:30 +04:00
|
|
|
static int
|
|
|
|
clear_coverage_i(st_data_t key, st_data_t val, st_data_t dummy)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
VALUE lines = (VALUE)val;
|
|
|
|
|
|
|
|
for (i = 0; i < RARRAY_LEN(lines); i++) {
|
|
|
|
if (RARRAY_PTR(lines)[i] != Qnil) {
|
|
|
|
RARRAY_PTR(lines)[i] = INT2FIX(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_coverage(void)
|
|
|
|
{
|
2008-07-08 19:13:22 +04:00
|
|
|
extern VALUE rb_get_coverages(void);
|
|
|
|
VALUE coverages = rb_get_coverages();
|
2008-07-03 16:55:12 +04:00
|
|
|
if (RTEST(coverages)) {
|
|
|
|
st_foreach(RHASH_TBL(coverages), clear_coverage_i, 0);
|
2008-07-01 20:55:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-14 13:02:51 +03:00
|
|
|
static int
|
|
|
|
terminate_atfork_i(st_data_t key, st_data_t val, rb_thread_t *current_th)
|
|
|
|
{
|
|
|
|
VALUE thval = key;
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
|
|
|
if (th != current_th) {
|
|
|
|
thread_cleanup_func(th);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_atfork(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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
* 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 22:00:03 +03:00
|
|
|
rb_vm_t *vm = th->vm;
|
2007-12-24 07:43:38 +03:00
|
|
|
VALUE thval = th->self;
|
2006-12-31 18:02:22 +03:00
|
|
|
vm->main_thread = th;
|
|
|
|
|
2008-01-14 13:02:51 +03:00
|
|
|
st_foreach(vm->living_threads, terminate_atfork_i, (st_data_t)th);
|
2007-12-24 07:43:38 +03:00
|
|
|
st_clear(vm->living_threads);
|
2008-05-11 08:15:29 +04:00
|
|
|
st_insert(vm->living_threads, thval, (st_data_t) th->thread_id);
|
2008-06-19 22:02:40 +04:00
|
|
|
vm->sleeper = 0;
|
2008-07-01 20:55:30 +04:00
|
|
|
clear_coverage();
|
2008-06-20 06:46:17 +04:00
|
|
|
rb_reset_random_seed();
|
2008-05-11 08:15:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
terminate_atfork_before_exec_i(st_data_t key, st_data_t val, rb_thread_t *current_th)
|
|
|
|
{
|
|
|
|
VALUE thval = key;
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
|
|
|
if (th != current_th) {
|
|
|
|
thread_cleanup_func_before_exec(th);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_atfork_before_exec(void)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
rb_vm_t *vm = th->vm;
|
|
|
|
VALUE thval = th->self;
|
|
|
|
vm->main_thread = th;
|
|
|
|
|
|
|
|
st_foreach(vm->living_threads, terminate_atfork_before_exec_i, (st_data_t)th);
|
|
|
|
st_clear(vm->living_threads);
|
2007-12-21 11:27:14 +03:00
|
|
|
st_insert(vm->living_threads, thval, (st_data_t) th->thread_id);
|
2008-06-19 22:02:40 +04:00
|
|
|
vm->sleeper = 0;
|
2008-07-01 20:55:30 +04:00
|
|
|
clear_coverage();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct thgroup {
|
|
|
|
int enclosed;
|
|
|
|
VALUE group;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: ThreadGroup
|
|
|
|
*
|
|
|
|
* <code>ThreadGroup</code> provides a means of keeping track of a number of
|
|
|
|
* threads as a group. A <code>Thread</code> can belong to only one
|
|
|
|
* <code>ThreadGroup</code> at a time; adding a thread to a new group will
|
|
|
|
* remove it from any previous group.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Newly created threads belong to the same group as the thread from which they
|
|
|
|
* were created.
|
|
|
|
*/
|
|
|
|
|
2007-12-25 07:17:06 +03:00
|
|
|
static VALUE thgroup_s_alloc(VALUE);
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
thgroup_s_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE group;
|
|
|
|
struct thgroup *data;
|
|
|
|
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
group = Data_Make_Struct(klass, struct thgroup, 0, -1, data);
|
2006-12-31 18:02:22 +03:00
|
|
|
data->enclosed = 0;
|
|
|
|
data->group = group;
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct thgroup_list_params {
|
|
|
|
VALUE ary;
|
|
|
|
VALUE group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
thgroup_list_i(st_data_t key, st_data_t val, st_data_t data)
|
|
|
|
{
|
|
|
|
VALUE thread = (VALUE)key;
|
|
|
|
VALUE ary = ((struct thgroup_list_params *)data)->ary;
|
|
|
|
VALUE group = ((struct thgroup_list_params *)data)->group;
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (th->thgroup == group) {
|
|
|
|
rb_ary_push(ary, thread);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thgrp.list => array
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns an array of all existing <code>Thread</code> objects that belong to
|
|
|
|
* this group.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* ThreadGroup::Default.list #=> [#<Thread:0x401bdf4c run>]
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thgroup_list(VALUE group)
|
|
|
|
{
|
|
|
|
VALUE ary = rb_ary_new();
|
2007-07-20 11:11:35 +04:00
|
|
|
struct thgroup_list_params param;
|
|
|
|
|
|
|
|
param.ary = ary;
|
|
|
|
param.group = group;
|
2006-12-31 18:02:22 +03:00
|
|
|
st_foreach(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param);
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thgrp.enclose => thgrp
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Prevents threads from being added to or removed from the receiving
|
|
|
|
* <code>ThreadGroup</code>. New threads can still be started in an enclosed
|
|
|
|
* <code>ThreadGroup</code>.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* ThreadGroup::Default.enclose #=> #<ThreadGroup:0x4029d914>
|
|
|
|
* thr = Thread::new { Thread.stop } #=> #<Thread:0x402a7210 sleep>
|
|
|
|
* tg = ThreadGroup::new #=> #<ThreadGroup:0x402752d4>
|
|
|
|
* tg.add thr
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* ThreadError: can't move from the enclosed thread group
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
2007-03-19 06:58:57 +03:00
|
|
|
thgroup_enclose(VALUE group)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
struct thgroup *data;
|
|
|
|
|
|
|
|
Data_Get_Struct(group, struct thgroup, data);
|
|
|
|
data->enclosed = 1;
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thgrp.enclosed? => true or false
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Returns <code>true</code> if <em>thgrp</em> is enclosed. See also
|
|
|
|
* ThreadGroup#enclose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thgroup_enclosed_p(VALUE group)
|
|
|
|
{
|
|
|
|
struct thgroup *data;
|
|
|
|
|
|
|
|
Data_Get_Struct(group, struct thgroup, data);
|
|
|
|
if (data->enclosed)
|
|
|
|
return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* thgrp.add(thread) => thgrp
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Adds the given <em>thread</em> to this group, removing it from any other
|
|
|
|
* group to which it may have previously belonged.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* puts "Initial group is #{ThreadGroup::Default.list}"
|
|
|
|
* tg = ThreadGroup.new
|
|
|
|
* t1 = Thread.new { sleep }
|
|
|
|
* t2 = Thread.new { sleep }
|
|
|
|
* puts "t1 is #{t1}"
|
|
|
|
* puts "t2 is #{t2}"
|
|
|
|
* tg.add(t1)
|
|
|
|
* puts "Initial group now #{ThreadGroup::Default.list}"
|
|
|
|
* puts "tg group now #{tg.list}"
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* <em>produces:</em>
|
* 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 08:25:10 +04:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Initial group is #<Thread:0x401bdf4c>
|
|
|
|
* t1 is #<Thread:0x401b3c90>
|
|
|
|
* t2 is #<Thread:0x401b3c18>
|
|
|
|
* Initial group now #<Thread:0x401b3c18>#<Thread:0x401bdf4c>
|
|
|
|
* tg group now #<Thread:0x401b3c90>
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thgroup_add(VALUE group, VALUE 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 09:37:46 +03:00
|
|
|
rb_thread_t *th;
|
2006-12-31 18:02:22 +03:00
|
|
|
struct thgroup *data;
|
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
GetThreadPtr(thread, th);
|
|
|
|
|
|
|
|
if (OBJ_FROZEN(group)) {
|
|
|
|
rb_raise(rb_eThreadError, "can't move to the frozen thread group");
|
|
|
|
}
|
|
|
|
Data_Get_Struct(group, struct thgroup, data);
|
|
|
|
if (data->enclosed) {
|
|
|
|
rb_raise(rb_eThreadError, "can't move to the enclosed thread group");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!th->thgroup) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OBJ_FROZEN(th->thgroup)) {
|
|
|
|
rb_raise(rb_eThreadError, "can't move from the frozen thread group");
|
|
|
|
}
|
|
|
|
Data_Get_Struct(th->thgroup, struct thgroup, data);
|
|
|
|
if (data->enclosed) {
|
|
|
|
rb_raise(rb_eThreadError,
|
|
|
|
"can't move from the enclosed thread group");
|
|
|
|
}
|
|
|
|
|
|
|
|
th->thgroup = group;
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
2007-05-03 17:04:42 +04:00
|
|
|
* Document-class: Mutex
|
|
|
|
*
|
|
|
|
* Mutex implements a simple semaphore that can be used to coordinate access to
|
|
|
|
* shared data from multiple concurrent threads.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* require 'thread'
|
|
|
|
* semaphore = Mutex.new
|
|
|
|
*
|
|
|
|
* a = Thread.new {
|
|
|
|
* semaphore.synchronize {
|
|
|
|
* # access shared resource
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* b = Thread.new {
|
|
|
|
* semaphore.synchronize {
|
|
|
|
* # access shared resource
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
2007-08-27 20:48:14 +04:00
|
|
|
#define GetMutexPtr(obj, tobj) \
|
2006-12-31 18:02:22 +03:00
|
|
|
Data_Get_Struct(obj, mutex_t, tobj)
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static const char *mutex_unlock(mutex_t *mutex);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
|
|
|
mutex_free(void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr) {
|
|
|
|
mutex_t *mutex = ptr;
|
2008-06-12 17:01:38 +04:00
|
|
|
if (mutex->th) {
|
|
|
|
/* rb_warn("free locked mutex"); */
|
|
|
|
mutex_unlock(mutex);
|
|
|
|
}
|
2007-02-08 23:24:55 +03:00
|
|
|
native_mutex_destroy(&mutex->lock);
|
2007-08-27 20:48:14 +04:00
|
|
|
native_cond_destroy(&mutex->cond);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
ruby_xfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
mutex_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE volatile obj;
|
|
|
|
mutex_t *mutex;
|
|
|
|
|
2008-07-27 19:20:01 +04:00
|
|
|
obj = Data_Make_Struct(klass, mutex_t, NULL, mutex_free, mutex);
|
2006-12-31 18:02:22 +03:00
|
|
|
native_mutex_initialize(&mutex->lock);
|
2007-08-27 20:48:14 +04:00
|
|
|
native_cond_initialize(&mutex->cond);
|
2006-12-31 18:02:22 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Mutex.new => mutex
|
|
|
|
*
|
|
|
|
* Creates a new Mutex
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
mutex_initialize(VALUE self)
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
VALUE
|
|
|
|
rb_mutex_new(void)
|
|
|
|
{
|
|
|
|
return mutex_alloc(rb_cMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mutex.locked? => true or false
|
|
|
|
*
|
|
|
|
* Returns +true+ if this lock is currently held by some thread.
|
|
|
|
*/
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE
|
|
|
|
rb_mutex_locked_p(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
mutex_t *mutex;
|
2007-08-27 20:48:14 +04:00
|
|
|
GetMutexPtr(self, mutex);
|
2006-12-31 18:02:22 +03:00
|
|
|
return mutex->th ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static void
|
|
|
|
mutex_locked(rb_thread_t *th, VALUE self)
|
|
|
|
{
|
2008-07-27 19:20:01 +04:00
|
|
|
mutex_t *mutex;
|
|
|
|
GetMutexPtr(self, mutex);
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
if (th->keeping_mutexes) {
|
|
|
|
mutex->next_mutex = th->keeping_mutexes;
|
|
|
|
}
|
2008-07-27 19:20:01 +04:00
|
|
|
th->keeping_mutexes = mutex;
|
2008-06-12 17:01:38 +04:00
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mutex.try_lock => true or false
|
|
|
|
*
|
|
|
|
* Attempts to obtain the lock and returns immediately. Returns +true+ if the
|
|
|
|
* lock was granted.
|
|
|
|
*/
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE
|
2007-08-27 20:48:14 +04:00
|
|
|
rb_mutex_trylock(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
mutex_t *mutex;
|
2007-08-27 20:48:14 +04:00
|
|
|
VALUE locked = Qfalse;
|
|
|
|
GetMutexPtr(self, mutex);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-04-12 12:14:54 +04:00
|
|
|
if (mutex->th == GET_THREAD()) {
|
|
|
|
rb_raise(rb_eThreadError, "deadlock; recursive locking");
|
|
|
|
}
|
|
|
|
|
2007-08-27 20:48:14 +04:00
|
|
|
native_mutex_lock(&mutex->lock);
|
|
|
|
if (mutex->th == 0) {
|
2007-04-12 12:14:54 +04:00
|
|
|
mutex->th = GET_THREAD();
|
2007-08-27 20:48:14 +04:00
|
|
|
locked = Qtrue;
|
2008-06-12 17:01:38 +04:00
|
|
|
|
|
|
|
mutex_locked(GET_THREAD(), self);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-08-27 20:48:14 +04:00
|
|
|
native_mutex_unlock(&mutex->lock);
|
|
|
|
|
|
|
|
return locked;
|
|
|
|
}
|
|
|
|
|
2008-04-13 13:52:29 +04:00
|
|
|
static int
|
2008-06-12 17:01:38 +04:00
|
|
|
lock_func(rb_thread_t *th, mutex_t *mutex, int last_thread)
|
2007-08-27 20:48:14 +04:00
|
|
|
{
|
2008-06-12 17:01:38 +04:00
|
|
|
int interrupted = 0;
|
2008-06-19 18:18:46 +04:00
|
|
|
#if 0 /* for debug */
|
|
|
|
native_thread_yield();
|
|
|
|
#endif
|
2008-04-13 13:52:29 +04:00
|
|
|
|
2008-04-09 09:43:29 +04:00
|
|
|
native_mutex_lock(&mutex->lock);
|
2008-06-19 18:18:46 +04:00
|
|
|
th->transition_for_lock = 0;
|
2008-04-13 13:52:29 +04:00
|
|
|
while (mutex->th || (mutex->th = th, 0)) {
|
2008-06-12 17:01:38 +04:00
|
|
|
if (last_thread) {
|
|
|
|
interrupted = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-09 09:43:29 +04:00
|
|
|
mutex->cond_waiting++;
|
|
|
|
native_cond_wait(&mutex->cond, &mutex->lock);
|
2008-06-12 17:01:38 +04:00
|
|
|
mutex->cond_notified--;
|
2008-04-09 09:43:29 +04:00
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
if (RUBY_VM_INTERRUPTED(th)) {
|
|
|
|
interrupted = 1;
|
2008-04-13 13:52:29 +04:00
|
|
|
break;
|
2007-11-20 13:47:53 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2008-06-19 18:18:46 +04:00
|
|
|
th->transition_for_lock = 1;
|
2008-04-09 09:43:29 +04:00
|
|
|
native_mutex_unlock(&mutex->lock);
|
2008-06-19 18:18:46 +04:00
|
|
|
|
2008-06-19 22:02:40 +04:00
|
|
|
if (interrupted == 2) native_thread_yield();
|
2008-06-19 18:18:46 +04:00
|
|
|
#if 0 /* for debug */
|
|
|
|
native_thread_yield();
|
|
|
|
#endif
|
|
|
|
|
2008-04-13 13:52:29 +04:00
|
|
|
return interrupted;
|
2007-08-27 20:48:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-20 13:47:53 +03:00
|
|
|
lock_interrupt(void *ptr)
|
2007-08-27 20:48:14 +04:00
|
|
|
{
|
|
|
|
mutex_t *mutex = (mutex_t *)ptr;
|
|
|
|
native_mutex_lock(&mutex->lock);
|
|
|
|
if (mutex->cond_waiting > 0) {
|
|
|
|
native_cond_broadcast(&mutex->cond);
|
2008-06-12 17:01:38 +04:00
|
|
|
mutex->cond_notified = mutex->cond_waiting;
|
2007-08-27 20:48:14 +04:00
|
|
|
mutex->cond_waiting = 0;
|
|
|
|
}
|
|
|
|
native_mutex_unlock(&mutex->lock);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mutex.lock => true or false
|
|
|
|
*
|
|
|
|
* Attempts to grab the lock and waits if it isn't available.
|
|
|
|
* Raises +ThreadError+ if +mutex+ was locked by the current thread.
|
|
|
|
*/
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE
|
|
|
|
rb_mutex_lock(VALUE self)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-08-27 20:48:14 +04:00
|
|
|
if (rb_mutex_trylock(self) == Qfalse) {
|
|
|
|
mutex_t *mutex;
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
GetMutexPtr(self, mutex);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-27 20:48:14 +04:00
|
|
|
while (mutex->th != th) {
|
2008-04-13 13:52:29 +04:00
|
|
|
int interrupted;
|
2008-07-16 23:19:36 +04:00
|
|
|
enum rb_thread_status prev_status = th->status;
|
2008-06-12 17:01:38 +04:00
|
|
|
int last_thread = 0;
|
2008-06-19 18:18:46 +04:00
|
|
|
struct rb_unblock_callback oldubf;
|
2008-06-12 17:01:38 +04:00
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
set_unblock_function(th, lock_interrupt, mutex, &oldubf);
|
2008-06-12 17:01:38 +04:00
|
|
|
th->status = THREAD_STOPPED_FOREVER;
|
|
|
|
th->vm->sleeper++;
|
2008-06-19 18:18:46 +04:00
|
|
|
th->locking_mutex = self;
|
|
|
|
if (vm_living_thread_num(th->vm) == th->vm->sleeper) {
|
2008-06-12 17:01:38 +04:00
|
|
|
last_thread = 1;
|
|
|
|
}
|
2008-04-13 13:52:29 +04:00
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
th->transition_for_lock = 1;
|
|
|
|
BLOCKING_REGION_CORE({
|
2008-06-12 17:01:38 +04:00
|
|
|
interrupted = lock_func(th, mutex, last_thread);
|
2008-06-19 18:18:46 +04:00
|
|
|
});
|
|
|
|
th->transition_for_lock = 0;
|
|
|
|
remove_signal_thread_list(th);
|
|
|
|
reset_unblock_function(th, &oldubf);
|
2008-06-12 17:01:38 +04:00
|
|
|
|
|
|
|
th->locking_mutex = Qfalse;
|
2008-06-19 18:18:46 +04:00
|
|
|
if (mutex->th && interrupted == 2) {
|
2008-06-12 17:01:38 +04:00
|
|
|
rb_check_deadlock(th->vm);
|
|
|
|
}
|
2008-06-19 18:18:46 +04:00
|
|
|
if (th->status == THREAD_STOPPED_FOREVER) {
|
|
|
|
th->status = prev_status;
|
|
|
|
}
|
2008-06-12 17:01:38 +04:00
|
|
|
th->vm->sleeper--;
|
|
|
|
|
|
|
|
if (mutex->th == th) mutex_locked(th, self);
|
2007-11-20 13:47:53 +03:00
|
|
|
|
2008-04-13 13:52:29 +04:00
|
|
|
if (interrupted) {
|
|
|
|
RUBY_VM_CHECK_INTS();
|
|
|
|
}
|
2007-08-27 20:48:14 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static const char *
|
|
|
|
mutex_unlock(mutex_t *mutex)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *err = NULL;
|
2008-06-12 17:01:38 +04:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
mutex_t *th_mutex;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-08-27 20:48:14 +04:00
|
|
|
native_mutex_lock(&mutex->lock);
|
2008-01-10 19:12:32 +03:00
|
|
|
|
|
|
|
if (mutex->th == 0) {
|
|
|
|
err = "Attempt to unlock a mutex which is not locked";
|
2007-08-27 20:48:14 +04:00
|
|
|
}
|
2008-01-10 19:12:32 +03:00
|
|
|
else if (mutex->th != GET_THREAD()) {
|
|
|
|
err = "Attempt to unlock a mutex which is locked by another thread";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mutex->th = 0;
|
|
|
|
if (mutex->cond_waiting > 0) {
|
|
|
|
/* waiting thread */
|
|
|
|
native_cond_signal(&mutex->cond);
|
|
|
|
mutex->cond_waiting--;
|
2008-06-12 18:33:07 +04:00
|
|
|
mutex->cond_notified++;
|
2008-01-10 19:12:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
native_mutex_unlock(&mutex->lock);
|
2007-08-27 20:48:14 +04:00
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
if (!err) {
|
2008-07-27 19:20:01 +04:00
|
|
|
th_mutex = th->keeping_mutexes;
|
2008-06-12 17:01:38 +04:00
|
|
|
if (th_mutex == mutex) {
|
|
|
|
th->keeping_mutexes = mutex->next_mutex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (1) {
|
|
|
|
mutex_t *tmp_mutex;
|
2008-07-27 19:20:01 +04:00
|
|
|
tmp_mutex = th_mutex->next_mutex;
|
2008-06-12 17:01:38 +04:00
|
|
|
if (tmp_mutex == mutex) {
|
|
|
|
th_mutex->next_mutex = tmp_mutex->next_mutex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
th_mutex = tmp_mutex;
|
|
|
|
}
|
|
|
|
}
|
2008-07-28 13:59:12 +04:00
|
|
|
mutex->next_mutex = NULL;
|
2008-06-12 17:01:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mutex.unlock => self
|
|
|
|
*
|
|
|
|
* Releases the lock.
|
|
|
|
* Raises +ThreadError+ if +mutex+ wasn't locked by the current thread.
|
|
|
|
*/
|
|
|
|
VALUE
|
|
|
|
rb_mutex_unlock(VALUE self)
|
|
|
|
{
|
|
|
|
const char *err;
|
|
|
|
mutex_t *mutex;
|
|
|
|
GetMutexPtr(self, mutex);
|
|
|
|
|
|
|
|
err = mutex_unlock(mutex);
|
2008-01-10 19:12:32 +03:00
|
|
|
if (err) rb_raise(rb_eThreadError, err);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static void
|
2008-07-27 19:20:01 +04:00
|
|
|
rb_mutex_unlock_all(mutex_t *mutexes)
|
2008-06-12 17:01:38 +04:00
|
|
|
{
|
|
|
|
const char *err;
|
|
|
|
mutex_t *mutex;
|
|
|
|
|
|
|
|
while (mutexes) {
|
2008-07-27 19:20:01 +04:00
|
|
|
mutex = mutexes;
|
2008-07-30 20:25:46 +04:00
|
|
|
/* rb_warn("mutex #<%p> remains to be locked by terminated thread",
|
|
|
|
mutexes); */
|
2008-06-12 17:01:38 +04:00
|
|
|
mutexes = mutex->next_mutex;
|
|
|
|
err = mutex_unlock(mutex);
|
2008-06-19 22:02:40 +04:00
|
|
|
if (err) rb_bug("invalid keeping_mutexes: %s", err);
|
2008-06-12 17:01:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-08 16:36:42 +04:00
|
|
|
static VALUE
|
|
|
|
rb_mutex_sleep_forever(VALUE time)
|
|
|
|
{
|
2008-06-12 17:01:38 +04:00
|
|
|
rb_thread_sleep_deadly();
|
2008-04-08 16:36:42 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mutex_wait_for(VALUE time)
|
|
|
|
{
|
|
|
|
const struct timeval *t = (struct timeval *)time;
|
|
|
|
rb_thread_wait_for(*t);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE
|
|
|
|
rb_mutex_sleep(VALUE self, VALUE timeout)
|
|
|
|
{
|
|
|
|
time_t beg, end;
|
|
|
|
struct timeval t;
|
|
|
|
|
|
|
|
if (!NIL_P(timeout)) {
|
|
|
|
t = rb_time_interval(timeout);
|
|
|
|
}
|
|
|
|
rb_mutex_unlock(self);
|
|
|
|
beg = time(0);
|
|
|
|
if (NIL_P(timeout)) {
|
2008-04-08 16:36:42 +04:00
|
|
|
rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-04-08 16:36:42 +04:00
|
|
|
rb_ensure(rb_mutex_wait_for, (VALUE)&t, rb_mutex_lock, self);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
end = time(0) - beg;
|
|
|
|
return INT2FIX(end);
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:04:42 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-04-08 16:36:42 +04:00
|
|
|
* mutex.sleep(timeout = nil) => number
|
2007-05-03 17:04:42 +04:00
|
|
|
*
|
|
|
|
* Releases the lock and sleeps +timeout+ seconds if it is given and
|
* 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 08:25:10 +04:00
|
|
|
* non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by
|
2007-05-03 17:04:42 +04:00
|
|
|
* the current thread.
|
|
|
|
*/
|
2006-12-31 18:02:22 +03:00
|
|
|
static VALUE
|
|
|
|
mutex_sleep(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
VALUE timeout;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
rb_scan_args(argc, argv, "01", &timeout);
|
|
|
|
return rb_mutex_sleep(self, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mutex.synchronize { ... } => result of the block
|
|
|
|
*
|
|
|
|
* Obtains a lock, runs the block, and releases the lock when the block
|
|
|
|
* completes. See the example under +Mutex+.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_thread_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg)
|
|
|
|
{
|
|
|
|
rb_mutex_lock(mutex);
|
|
|
|
return rb_ensure(func, arg, rb_mutex_unlock, mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Barrier
|
|
|
|
*/
|
|
|
|
typedef struct rb_thread_list_struct rb_thread_list_t;
|
|
|
|
|
|
|
|
struct rb_thread_list_struct {
|
|
|
|
rb_thread_t *th;
|
|
|
|
rb_thread_list_t *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
thlist_mark(void *ptr)
|
|
|
|
{
|
|
|
|
rb_thread_list_t *q = ptr;
|
|
|
|
|
|
|
|
for (; q; q = q->next) {
|
|
|
|
rb_gc_mark(q->th->self);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
thlist_free(void *ptr)
|
|
|
|
{
|
|
|
|
rb_thread_list_t *q = ptr, *next;
|
|
|
|
|
|
|
|
for (; q; q = next) {
|
|
|
|
next = q->next;
|
|
|
|
ruby_xfree(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-11-06 09:52:01 +03:00
|
|
|
thlist_signal(rb_thread_list_t **list, unsigned int maxth, rb_thread_t **woken_thread)
|
2007-05-03 17:19:11 +04:00
|
|
|
{
|
|
|
|
int woken = 0;
|
|
|
|
rb_thread_list_t *q;
|
|
|
|
|
* 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 08:25:46 +04:00
|
|
|
while ((q = *list) != NULL) {
|
2007-05-03 17:19:11 +04:00
|
|
|
rb_thread_t *th = q->th;
|
|
|
|
|
|
|
|
*list = q->next;
|
|
|
|
ruby_xfree(q);
|
|
|
|
if (th->status != THREAD_KILLED) {
|
|
|
|
rb_thread_ready(th);
|
2007-11-06 09:52:01 +03:00
|
|
|
if (!woken && woken_thread) *woken_thread = th;
|
2007-05-03 17:19:11 +04:00
|
|
|
if (++woken >= maxth && maxth) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return woken;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
rb_thread_t *owner;
|
|
|
|
rb_thread_list_t *waiting, **tail;
|
|
|
|
} rb_barrier_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
barrier_mark(void *ptr)
|
|
|
|
{
|
|
|
|
rb_barrier_t *b = ptr;
|
|
|
|
|
|
|
|
if (b->owner) rb_gc_mark(b->owner->self);
|
|
|
|
thlist_mark(b->waiting);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
barrier_free(void *ptr)
|
|
|
|
{
|
|
|
|
rb_barrier_t *b = ptr;
|
|
|
|
|
|
|
|
b->owner = 0;
|
|
|
|
thlist_free(b->waiting);
|
|
|
|
b->waiting = 0;
|
|
|
|
ruby_xfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
barrier_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
VALUE volatile obj;
|
|
|
|
rb_barrier_t *barrier;
|
|
|
|
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
obj = Data_Make_Struct(klass, rb_barrier_t, barrier_mark, barrier_free, barrier);
|
2007-05-03 17:19:11 +04:00
|
|
|
barrier->owner = GET_THREAD();
|
|
|
|
barrier->waiting = 0;
|
|
|
|
barrier->tail = &barrier->waiting;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_barrier_new(void)
|
|
|
|
{
|
|
|
|
return barrier_alloc(rb_cBarrier);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_barrier_wait(VALUE self)
|
|
|
|
{
|
|
|
|
rb_barrier_t *barrier;
|
|
|
|
rb_thread_list_t *q;
|
|
|
|
|
|
|
|
Data_Get_Struct(self, rb_barrier_t, barrier);
|
|
|
|
if (!barrier->owner || barrier->owner->status == THREAD_KILLED) {
|
|
|
|
barrier->owner = 0;
|
2007-11-06 09:52:01 +03:00
|
|
|
if (thlist_signal(&barrier->waiting, 1, &barrier->owner)) return Qfalse;
|
|
|
|
return Qtrue;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-12-24 11:59:31 +03:00
|
|
|
else if (barrier->owner == GET_THREAD()) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
else {
|
2007-05-03 17:19:11 +04:00
|
|
|
*barrier->tail = q = ALLOC(rb_thread_list_t);
|
|
|
|
q->th = GET_THREAD();
|
|
|
|
q->next = 0;
|
|
|
|
barrier->tail = &q->next;
|
|
|
|
rb_thread_sleep_forever();
|
2007-11-06 09:52:01 +03:00
|
|
|
return barrier->owner == GET_THREAD() ? Qtrue : Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_barrier_release(VALUE self)
|
|
|
|
{
|
|
|
|
rb_barrier_t *barrier;
|
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
Data_Get_Struct(self, rb_barrier_t, barrier);
|
2007-11-06 09:52:01 +03:00
|
|
|
if (barrier->owner != GET_THREAD()) {
|
|
|
|
rb_raise(rb_eThreadError, "not owned");
|
|
|
|
}
|
|
|
|
n = thlist_signal(&barrier->waiting, 0, &barrier->owner);
|
2007-05-03 17:19:11 +04:00
|
|
|
return n ? UINT2NUM(n) : Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
/* variables for recursive traversals */
|
|
|
|
static ID recursive_key;
|
|
|
|
|
|
|
|
static VALUE
|
2007-12-07 06:22:28 +03:00
|
|
|
recursive_check(VALUE hash, VALUE obj)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
|
|
|
if (NIL_P(hash) || TYPE(hash) != T_HASH) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE list = rb_hash_aref(hash, ID2SYM(rb_frame_this_func()));
|
|
|
|
|
2007-12-07 06:22:28 +03:00
|
|
|
if (NIL_P(list) || TYPE(list) != T_HASH)
|
|
|
|
return Qfalse;
|
2007-12-07 09:04:03 +03:00
|
|
|
if (NIL_P(rb_hash_lookup(list, obj)))
|
2007-02-05 15:21:01 +03:00
|
|
|
return Qfalse;
|
2007-12-07 06:22:28 +03:00
|
|
|
return Qtrue;
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-07 06:22:28 +03:00
|
|
|
static VALUE
|
|
|
|
recursive_push(VALUE hash, VALUE obj)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
|
|
|
VALUE list, sym;
|
|
|
|
|
|
|
|
sym = ID2SYM(rb_frame_this_func());
|
|
|
|
if (NIL_P(hash) || TYPE(hash) != T_HASH) {
|
|
|
|
hash = rb_hash_new();
|
|
|
|
rb_thread_local_aset(rb_thread_current(), recursive_key, hash);
|
|
|
|
list = Qnil;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
list = rb_hash_aref(hash, sym);
|
|
|
|
}
|
2007-12-07 06:22:28 +03:00
|
|
|
if (NIL_P(list) || TYPE(list) != T_HASH) {
|
|
|
|
list = rb_hash_new();
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_hash_aset(hash, sym, list);
|
|
|
|
}
|
2007-12-07 09:04:03 +03:00
|
|
|
rb_hash_aset(list, obj, Qtrue);
|
2007-12-07 06:22:28 +03:00
|
|
|
return hash;
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-07 06:22:28 +03:00
|
|
|
recursive_pop(VALUE hash, VALUE obj)
|
2007-02-05 15:21:01 +03:00
|
|
|
{
|
|
|
|
VALUE list, sym;
|
|
|
|
|
|
|
|
sym = ID2SYM(rb_frame_this_func());
|
|
|
|
if (NIL_P(hash) || TYPE(hash) != T_HASH) {
|
|
|
|
VALUE symname;
|
|
|
|
VALUE thrname;
|
|
|
|
symname = rb_inspect(sym);
|
|
|
|
thrname = rb_inspect(rb_thread_current());
|
|
|
|
|
|
|
|
rb_raise(rb_eTypeError, "invalid inspect_tbl hash for %s in %s",
|
|
|
|
StringValuePtr(symname), StringValuePtr(thrname));
|
|
|
|
}
|
|
|
|
list = rb_hash_aref(hash, sym);
|
2007-12-07 06:22:28 +03:00
|
|
|
if (NIL_P(list) || TYPE(list) != T_HASH) {
|
2007-02-05 15:21:01 +03:00
|
|
|
VALUE symname = rb_inspect(sym);
|
|
|
|
VALUE thrname = rb_inspect(rb_thread_current());
|
|
|
|
rb_raise(rb_eTypeError, "invalid inspect_tbl list for %s in %s",
|
|
|
|
StringValuePtr(symname), StringValuePtr(thrname));
|
|
|
|
}
|
2007-12-07 06:22:28 +03:00
|
|
|
rb_hash_delete(list, obj);
|
2007-02-05 15:21:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE arg)
|
|
|
|
{
|
2007-12-07 06:22:28 +03:00
|
|
|
VALUE hash = rb_thread_local_aref(rb_thread_current(), recursive_key);
|
2007-12-07 09:04:03 +03:00
|
|
|
VALUE objid = rb_obj_id(obj);
|
2007-12-07 06:22:28 +03:00
|
|
|
|
2007-12-07 09:04:03 +03:00
|
|
|
if (recursive_check(hash, objid)) {
|
2007-02-05 15:21:01 +03:00
|
|
|
return (*func) (obj, arg, Qtrue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE result = Qundef;
|
|
|
|
int state;
|
|
|
|
|
2007-12-07 09:04:03 +03:00
|
|
|
hash = recursive_push(hash, objid);
|
2007-04-25 05:35:13 +04:00
|
|
|
PUSH_TAG();
|
2007-02-05 15:21:01 +03:00
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
|
|
|
result = (*func) (obj, arg, Qfalse);
|
|
|
|
}
|
|
|
|
POP_TAG();
|
2007-12-07 09:04:03 +03:00
|
|
|
recursive_pop(hash, objid);
|
2007-02-05 15:21:01 +03:00
|
|
|
if (state)
|
|
|
|
JUMP_TAG(state);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-19 14:37:08 +04:00
|
|
|
/* tracer */
|
|
|
|
|
|
|
|
static rb_event_hook_t *
|
2008-06-05 18:27:09 +04:00
|
|
|
alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
|
2007-04-19 14:37:08 +04:00
|
|
|
{
|
|
|
|
rb_event_hook_t *hook = ALLOC(rb_event_hook_t);
|
|
|
|
hook->func = func;
|
|
|
|
hook->flag = events;
|
|
|
|
hook->data = data;
|
2007-04-25 05:32:24 +04:00
|
|
|
return hook;
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
thread_reset_event_flags(rb_thread_t *th)
|
|
|
|
{
|
|
|
|
rb_event_hook_t *hook = th->event_hooks;
|
|
|
|
rb_event_flag_t flag = th->event_flags & RUBY_EVENT_VM;
|
|
|
|
|
|
|
|
while (hook) {
|
|
|
|
flag |= hook->flag;
|
|
|
|
hook = hook->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_thread_add_event_hook(rb_thread_t *th,
|
|
|
|
rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
|
|
|
|
{
|
2008-06-05 18:27:09 +04:00
|
|
|
rb_event_hook_t *hook = alloc_event_hook(func, events, data);
|
2007-04-19 14:37:08 +04:00
|
|
|
hook->next = th->event_hooks;
|
|
|
|
th->event_hooks = hook;
|
|
|
|
thread_reset_event_flags(th);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_threads_event_flags_i(st_data_t key, st_data_t val, st_data_t flag)
|
|
|
|
{
|
|
|
|
VALUE thval = key;
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
th->event_flags |= RUBY_EVENT_VM;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
th->event_flags &= (~RUBY_EVENT_VM);
|
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_threads_event_flags(int flag)
|
|
|
|
{
|
|
|
|
st_foreach(GET_VM()->living_threads, set_threads_event_flags_i, (st_data_t) flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
|
|
|
|
{
|
2008-06-05 18:27:09 +04:00
|
|
|
rb_event_hook_t *hook = alloc_event_hook(func, events, data);
|
2007-04-19 14:37:08 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
|
|
|
|
hook->next = vm->event_hooks;
|
|
|
|
vm->event_hooks = hook;
|
|
|
|
|
|
|
|
set_threads_event_flags(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
remove_event_hook(rb_event_hook_t **root, rb_event_hook_func_t func)
|
|
|
|
{
|
2008-03-01 06:36:33 +03:00
|
|
|
rb_event_hook_t *prev = NULL, *hook = *root, *next;
|
2007-04-19 14:37:08 +04:00
|
|
|
|
|
|
|
while (hook) {
|
2008-03-01 06:36:33 +03:00
|
|
|
next = hook->next;
|
2007-04-19 14:37:08 +04:00
|
|
|
if (func == 0 || hook->func == func) {
|
|
|
|
if (prev) {
|
|
|
|
prev->next = hook->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*root = hook->next;
|
|
|
|
}
|
|
|
|
xfree(hook);
|
|
|
|
}
|
2008-03-01 06:36:33 +03:00
|
|
|
else {
|
|
|
|
prev = hook;
|
|
|
|
}
|
|
|
|
hook = next;
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_thread_remove_event_hook(rb_thread_t *th, rb_event_hook_func_t func)
|
|
|
|
{
|
2007-04-25 05:32:24 +04:00
|
|
|
int ret = remove_event_hook(&th->event_hooks, func);
|
2007-04-19 14:37:08 +04:00
|
|
|
thread_reset_event_flags(th);
|
2007-04-25 05:32:24 +04:00
|
|
|
return ret;
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_remove_event_hook(rb_event_hook_func_t func)
|
|
|
|
{
|
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
rb_event_hook_t *hook = vm->event_hooks;
|
|
|
|
int ret = remove_event_hook(&vm->event_hooks, func);
|
|
|
|
|
|
|
|
if (hook != NULL && vm->event_hooks == NULL) {
|
|
|
|
set_threads_event_flags(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clear_trace_func_i(st_data_t key, st_data_t val, st_data_t flag)
|
|
|
|
{
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr((VALUE)key, th);
|
|
|
|
rb_thread_remove_event_hook(th, 0);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_clear_trace_func(void)
|
|
|
|
{
|
|
|
|
st_foreach(GET_VM()->living_threads, clear_trace_func_i, (st_data_t) 0);
|
|
|
|
rb_remove_event_hook(0);
|
|
|
|
}
|
|
|
|
|
2007-12-24 10:52:39 +03:00
|
|
|
static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALUE klass);
|
|
|
|
|
2007-04-19 14:37:08 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* set_trace_func(proc) => proc
|
|
|
|
* set_trace_func(nil) => nil
|
* 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 08:25:10 +04:00
|
|
|
*
|
2007-04-19 14:37:08 +04:00
|
|
|
* Establishes _proc_ as the handler for tracing, or disables
|
|
|
|
* tracing if the parameter is +nil+. _proc_ takes up
|
|
|
|
* to six parameters: an event name, a filename, a line number, an
|
|
|
|
* object id, a binding, and the name of a class. _proc_ is
|
|
|
|
* invoked whenever an event occurs. Events are: <code>c-call</code>
|
|
|
|
* (call a C-language routine), <code>c-return</code> (return from a
|
|
|
|
* C-language routine), <code>call</code> (call a Ruby method),
|
|
|
|
* <code>class</code> (start a class or module definition),
|
|
|
|
* <code>end</code> (finish a class or module definition),
|
|
|
|
* <code>line</code> (execute code on a new line), <code>raise</code>
|
|
|
|
* (raise an exception), and <code>return</code> (return from a Ruby
|
|
|
|
* method). Tracing is disabled within the context of _proc_.
|
|
|
|
*
|
|
|
|
* class Test
|
|
|
|
* def test
|
|
|
|
* a = 1
|
|
|
|
* b = 2
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* set_trace_func proc { |event, file, line, id, binding, classname|
|
|
|
|
* printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
|
|
|
|
* }
|
|
|
|
* t = Test.new
|
|
|
|
* t.test
|
|
|
|
*
|
|
|
|
* line prog.rb:11 false
|
|
|
|
* c-call prog.rb:11 new Class
|
|
|
|
* c-call prog.rb:11 initialize Object
|
|
|
|
* c-return prog.rb:11 initialize Object
|
|
|
|
* c-return prog.rb:11 new Class
|
|
|
|
* line prog.rb:12 false
|
|
|
|
* call prog.rb:2 test Test
|
|
|
|
* line prog.rb:3 test Test
|
|
|
|
* line prog.rb:4 test Test
|
|
|
|
* return prog.rb:4 test Test
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
set_trace_func(VALUE obj, VALUE trace)
|
|
|
|
{
|
|
|
|
rb_remove_event_hook(call_trace_func);
|
|
|
|
|
|
|
|
if (NIL_P(trace)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rb_obj_is_proc(trace)) {
|
|
|
|
rb_raise(rb_eTypeError, "trace_func needs to be Proc");
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_add_event_hook(call_trace_func, RUBY_EVENT_ALL, trace);
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
thread_add_trace_func(rb_thread_t *th, VALUE trace)
|
|
|
|
{
|
|
|
|
if (!rb_obj_is_proc(trace)) {
|
|
|
|
rb_raise(rb_eTypeError, "trace_func needs to be Proc");
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_thread_add_event_hook(th, call_trace_func, RUBY_EVENT_ALL, trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thread_add_trace_func_m(VALUE obj, VALUE trace)
|
|
|
|
{
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(obj, th);
|
|
|
|
thread_add_trace_func(th, trace);
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
thread_set_trace_func_m(VALUE obj, VALUE trace)
|
|
|
|
{
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(obj, th);
|
|
|
|
rb_thread_remove_event_hook(th, call_trace_func);
|
|
|
|
|
2008-06-05 15:24:40 +04:00
|
|
|
if (NIL_P(trace)) {
|
2007-04-19 14:37:08 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
thread_add_trace_func(th, trace);
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
2008-05-31 13:28:20 +04:00
|
|
|
static const char *
|
2007-04-19 14:37:08 +04:00
|
|
|
get_event_name(rb_event_flag_t event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_LINE:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "line";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_CLASS:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "class";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_END:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "end";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_CALL:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "call";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_RETURN:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "return";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_C_CALL:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "c-call";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_C_RETURN:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "c-return";
|
* 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 08:25:10 +04:00
|
|
|
case RUBY_EVENT_RAISE:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "raise";
|
* 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 08:25:10 +04:00
|
|
|
default:
|
2007-04-19 14:37:08 +04:00
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 07:41:27 +03:00
|
|
|
VALUE ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always);
|
2007-06-18 11:55:45 +04:00
|
|
|
|
|
|
|
struct call_trace_func_args {
|
|
|
|
rb_event_flag_t event;
|
|
|
|
VALUE proc;
|
|
|
|
VALUE self;
|
|
|
|
ID id;
|
|
|
|
VALUE klass;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
2007-12-05 07:41:27 +03:00
|
|
|
call_trace_proc(VALUE args, int tracing)
|
2007-06-18 11:55:45 +04:00
|
|
|
{
|
|
|
|
struct call_trace_func_args *p = (struct call_trace_func_args *)args;
|
|
|
|
VALUE eventname = rb_str_new2(get_event_name(p->event));
|
|
|
|
VALUE filename = rb_str_new2(rb_sourcefile());
|
2008-06-10 20:33:51 +04:00
|
|
|
VALUE argv[6];
|
2007-06-18 11:55:45 +04:00
|
|
|
int line = rb_sourceline();
|
2007-11-11 11:42:13 +03:00
|
|
|
ID id = 0;
|
|
|
|
VALUE klass = 0;
|
2007-06-18 11:55:45 +04:00
|
|
|
|
2007-11-11 11:42:13 +03:00
|
|
|
if (p->event == RUBY_EVENT_C_CALL ||
|
|
|
|
p->event == RUBY_EVENT_C_RETURN) {
|
|
|
|
id = p->id;
|
|
|
|
klass = p->klass;
|
2007-11-10 11:33:28 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-11-22 04:17:52 +03:00
|
|
|
rb_thread_method_id_and_class(GET_THREAD(), &id, &klass);
|
2007-11-11 11:42:13 +03:00
|
|
|
}
|
|
|
|
if (id == ID_ALLOCATOR)
|
2008-07-01 22:13:22 +04:00
|
|
|
return Qnil;
|
2007-11-11 11:42:13 +03:00
|
|
|
if (klass) {
|
|
|
|
if (TYPE(klass) == T_ICLASS) {
|
|
|
|
klass = RBASIC(klass)->klass;
|
|
|
|
}
|
|
|
|
else if (FL_TEST(klass, FL_SINGLETON)) {
|
|
|
|
klass = rb_iv_get(klass, "__attached__");
|
|
|
|
}
|
2007-11-10 11:33:28 +03:00
|
|
|
}
|
2008-06-10 20:33:51 +04:00
|
|
|
|
|
|
|
argv[0] = eventname;
|
|
|
|
argv[1] = filename;
|
|
|
|
argv[2] = INT2FIX(line);
|
|
|
|
argv[3] = id ? ID2SYM(id) : Qnil;
|
|
|
|
argv[4] = p->self ? rb_binding_new() : Qnil;
|
|
|
|
argv[5] = klass ? klass : Qnil;
|
2008-07-01 22:13:22 +04:00
|
|
|
|
2008-06-10 20:33:51 +04:00
|
|
|
return rb_proc_call_with_block(p->proc, 6, argv, Qnil);
|
2007-06-18 11:55:45 +04:00
|
|
|
}
|
|
|
|
|
2007-04-19 14:37:08 +04:00
|
|
|
static void
|
|
|
|
call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
|
2007-06-18 11:55:45 +04:00
|
|
|
{
|
2007-07-20 11:11:35 +04:00
|
|
|
struct call_trace_func_args args;
|
|
|
|
|
|
|
|
args.event = event;
|
|
|
|
args.proc = proc;
|
|
|
|
args.self = self;
|
|
|
|
args.id = id;
|
|
|
|
args.klass = klass;
|
2007-12-05 07:41:27 +03:00
|
|
|
ruby_suppress_tracing(call_trace_proc, (VALUE)&args, Qfalse);
|
2007-06-18 11:55:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2007-12-05 07:41:27 +03:00
|
|
|
ruby_suppress_tracing(VALUE (*func)(VALUE, int), VALUE arg, int always)
|
2007-04-19 14:37:08 +04:00
|
|
|
{
|
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-12-05 07:41:27 +03:00
|
|
|
int state, raised, tracing;
|
2007-06-18 11:55:45 +04:00
|
|
|
VALUE result = Qnil;
|
2007-04-19 14:37:08 +04:00
|
|
|
|
2007-12-05 07:41:27 +03:00
|
|
|
if ((tracing = th->tracing) != 0 && !always) {
|
2007-06-18 11:55:45 +04:00
|
|
|
return Qnil;
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
th->tracing = 1;
|
|
|
|
}
|
|
|
|
|
2008-02-28 07:52:01 +03:00
|
|
|
raised = rb_thread_reset_raised(th);
|
2007-04-19 14:37:08 +04:00
|
|
|
|
|
|
|
PUSH_TAG();
|
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
2007-12-05 07:41:27 +03:00
|
|
|
result = (*func)(arg, tracing);
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (raised) {
|
2008-02-28 07:52:01 +03:00
|
|
|
rb_thread_set_raised(th);
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
|
|
|
POP_TAG();
|
|
|
|
|
2007-12-05 07:41:27 +03:00
|
|
|
th->tracing = tracing;
|
2007-04-19 14:37:08 +04:00
|
|
|
if (state) {
|
|
|
|
JUMP_TAG(state);
|
|
|
|
}
|
2007-06-18 11:55:45 +04:00
|
|
|
|
|
|
|
return result;
|
2007-04-19 14:37:08 +04:00
|
|
|
}
|
2007-02-05 15:21:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* +Thread+ encapsulates the behavior of a thread of
|
|
|
|
* execution, including the main thread of the Ruby script.
|
* 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 08:25:10 +04:00
|
|
|
*
|
2007-02-05 15:21:01 +03:00
|
|
|
* In the descriptions of the methods in this class, the parameter _sym_
|
|
|
|
* refers to a symbol, which is either a quoted string or a
|
|
|
|
* +Symbol+ (such as <code>:name</code>).
|
|
|
|
*/
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
2007-02-05 15:21:01 +03:00
|
|
|
Init_Thread(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-06-09 13:25:32 +04:00
|
|
|
#undef rb_intern
|
2008-08-16 04:20:31 +04:00
|
|
|
#define rb_intern(str) rb_intern_const(str)
|
2008-06-09 13:25:32 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE cThGroup;
|
|
|
|
|
2007-12-05 10:18:52 +03:00
|
|
|
rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1);
|
|
|
|
rb_define_singleton_method(rb_cThread, "start", thread_start, -2);
|
|
|
|
rb_define_singleton_method(rb_cThread, "fork", thread_start, -2);
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_define_singleton_method(rb_cThread, "main", rb_thread_s_main, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "current", thread_s_current, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "stop", rb_thread_stop, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "kill", rb_thread_s_kill, 1);
|
|
|
|
rb_define_singleton_method(rb_cThread, "exit", rb_thread_exit, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "pass", thread_s_pass, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "list", rb_thread_list, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "abort_on_exception", rb_thread_s_abort_exc, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "abort_on_exception=", rb_thread_s_abort_exc_set, 1);
|
2007-02-24 12:39:25 +03:00
|
|
|
#if THREAD_DEBUG < 0
|
|
|
|
rb_define_singleton_method(rb_cThread, "DEBUG", rb_thread_s_debug, 0);
|
|
|
|
rb_define_singleton_method(rb_cThread, "DEBUG=", rb_thread_s_debug_set, 1);
|
|
|
|
#endif
|
2007-02-05 15:21:01 +03:00
|
|
|
|
2007-12-05 10:18:52 +03:00
|
|
|
rb_define_method(rb_cThread, "initialize", thread_initialize, -2);
|
2007-02-05 15:21:01 +03:00
|
|
|
rb_define_method(rb_cThread, "raise", thread_raise_m, -1);
|
|
|
|
rb_define_method(rb_cThread, "join", thread_join_m, -1);
|
|
|
|
rb_define_method(rb_cThread, "value", thread_value, 0);
|
|
|
|
rb_define_method(rb_cThread, "kill", rb_thread_kill, 0);
|
|
|
|
rb_define_method(rb_cThread, "terminate", rb_thread_kill, 0);
|
|
|
|
rb_define_method(rb_cThread, "exit", rb_thread_kill, 0);
|
|
|
|
rb_define_method(rb_cThread, "run", rb_thread_run, 0);
|
|
|
|
rb_define_method(rb_cThread, "wakeup", rb_thread_wakeup, 0);
|
|
|
|
rb_define_method(rb_cThread, "[]", rb_thread_aref, 1);
|
|
|
|
rb_define_method(rb_cThread, "[]=", rb_thread_aset, 2);
|
|
|
|
rb_define_method(rb_cThread, "key?", rb_thread_key_p, 1);
|
|
|
|
rb_define_method(rb_cThread, "keys", rb_thread_keys, 0);
|
|
|
|
rb_define_method(rb_cThread, "priority", rb_thread_priority, 0);
|
|
|
|
rb_define_method(rb_cThread, "priority=", rb_thread_priority_set, 1);
|
|
|
|
rb_define_method(rb_cThread, "status", rb_thread_status, 0);
|
|
|
|
rb_define_method(rb_cThread, "alive?", rb_thread_alive_p, 0);
|
|
|
|
rb_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0);
|
|
|
|
rb_define_method(rb_cThread, "abort_on_exception", rb_thread_abort_exc, 0);
|
|
|
|
rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
|
|
|
|
rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
|
|
|
|
rb_define_method(rb_cThread, "group", rb_thread_group, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
cThGroup = rb_define_class("ThreadGroup", rb_cObject);
|
|
|
|
rb_define_alloc_func(cThGroup, thgroup_s_alloc);
|
|
|
|
rb_define_method(cThGroup, "list", thgroup_list, 0);
|
|
|
|
rb_define_method(cThGroup, "enclose", thgroup_enclose, 0);
|
|
|
|
rb_define_method(cThGroup, "enclosed?", thgroup_enclosed_p, 0);
|
|
|
|
rb_define_method(cThGroup, "add", thgroup_add, 1);
|
2007-02-05 15:21:01 +03:00
|
|
|
|
|
|
|
{
|
* 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 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-02-05 15:21:01 +03:00
|
|
|
th->thgroup = th->vm->thgroup_default = rb_obj_alloc(cThGroup);
|
|
|
|
rb_define_const(cThGroup, "Default", th->thgroup);
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
rb_cMutex = rb_define_class("Mutex", rb_cObject);
|
|
|
|
rb_define_alloc_func(rb_cMutex, mutex_alloc);
|
|
|
|
rb_define_method(rb_cMutex, "initialize", mutex_initialize, 0);
|
|
|
|
rb_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
|
2007-08-27 20:48:14 +04:00
|
|
|
rb_define_method(rb_cMutex, "try_lock", rb_mutex_trylock, 0);
|
2007-05-03 17:19:11 +04:00
|
|
|
rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
|
|
|
|
rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
|
|
|
|
rb_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
|
* 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 08:25:46 +04:00
|
|
|
|
2007-02-05 15:21:01 +03:00
|
|
|
recursive_key = rb_intern("__recursive_key__");
|
|
|
|
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
|
2007-02-07 16:44:11 +03:00
|
|
|
|
2007-04-19 14:37:08 +04:00
|
|
|
/* trace */
|
|
|
|
rb_define_global_function("set_trace_func", set_trace_func, 1);
|
|
|
|
rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1);
|
|
|
|
rb_define_method(rb_cThread, "add_trace_func", thread_add_trace_func_m, 1);
|
|
|
|
|
|
|
|
/* init thread core */
|
2006-12-31 18:02:22 +03:00
|
|
|
Init_native_thread();
|
|
|
|
{
|
|
|
|
/* main thread setting */
|
|
|
|
{
|
|
|
|
/* acquire global interpreter lock */
|
2008-06-15 20:48:02 +04:00
|
|
|
rb_thread_lock_t *lp = &GET_THREAD()->vm->global_vm_lock;
|
2006-12-31 18:02:22 +03:00
|
|
|
native_mutex_initialize(lp);
|
|
|
|
native_mutex_lock(lp);
|
|
|
|
native_mutex_initialize(&GET_THREAD()->interrupt_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_thread_create_timer_thread();
|
2008-06-01 23:55:25 +04:00
|
|
|
|
|
|
|
(void)native_mutex_trylock;
|
|
|
|
(void)ruby_thread_set_native;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-07-22 11:07:12 +04:00
|
|
|
int
|
2007-12-25 10:28:51 +03:00
|
|
|
ruby_native_thread_p(void)
|
2007-02-08 14:51:40 +03:00
|
|
|
{
|
2007-08-18 12:40:13 +04:00
|
|
|
rb_thread_t *th = ruby_thread_from_native();
|
|
|
|
|
|
|
|
return th ? Qtrue : Qfalse;
|
2007-02-08 14:51:40 +03:00
|
|
|
}
|
2008-06-12 17:01:38 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
check_deadlock_i(st_data_t key, st_data_t val, int *found)
|
|
|
|
{
|
|
|
|
VALUE thval = key;
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th) || th->transition_for_lock) {
|
2008-06-12 17:01:38 +04:00
|
|
|
*found = 1;
|
|
|
|
}
|
|
|
|
else if (th->locking_mutex) {
|
|
|
|
mutex_t *mutex;
|
|
|
|
GetMutexPtr(th->locking_mutex, mutex);
|
|
|
|
|
|
|
|
native_mutex_lock(&mutex->lock);
|
|
|
|
if (mutex->th == th || (!mutex->th && mutex->cond_notified)) {
|
|
|
|
*found = 1;
|
|
|
|
}
|
|
|
|
native_mutex_unlock(&mutex->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*found) ? ST_STOP : ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
#if 0 /* for debug */
|
|
|
|
static int
|
|
|
|
debug_i(st_data_t key, st_data_t val, int *found)
|
|
|
|
{
|
|
|
|
VALUE thval = key;
|
|
|
|
rb_thread_t *th;
|
|
|
|
GetThreadPtr(thval, th);
|
|
|
|
|
|
|
|
printf("th:%p %d %d %d", th, th->status, th->interrupt_flag, th->transition_for_lock);
|
|
|
|
if (th->locking_mutex) {
|
|
|
|
mutex_t *mutex;
|
|
|
|
GetMutexPtr(th->locking_mutex, mutex);
|
|
|
|
|
|
|
|
native_mutex_lock(&mutex->lock);
|
|
|
|
printf(" %p %d\n", mutex->th, mutex->cond_notified);
|
|
|
|
native_mutex_unlock(&mutex->lock);
|
|
|
|
}
|
|
|
|
else puts("");
|
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-12 17:01:38 +04:00
|
|
|
static void
|
|
|
|
rb_check_deadlock(rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
|
2008-06-19 18:18:46 +04:00
|
|
|
if (vm_living_thread_num(vm) > vm->sleeper) return;
|
|
|
|
if (vm_living_thread_num(vm) < vm->sleeper) rb_bug("sleeper must not be more than vm_living_thread_num(vm)");
|
2008-06-12 17:01:38 +04:00
|
|
|
|
|
|
|
st_foreach(vm->living_threads, check_deadlock_i, (st_data_t)&found);
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
VALUE argv[2];
|
|
|
|
argv[0] = rb_eFatal;
|
|
|
|
argv[1] = rb_str_new2("deadlock detected");
|
2008-06-19 18:18:46 +04:00
|
|
|
#if 0 /* for debug */
|
|
|
|
printf("%d %d %p %p\n", vm->living_threads->num_entries, vm->sleeper, GET_THREAD(), vm->main_thread);
|
|
|
|
st_foreach(vm->living_threads, debug_i, (st_data_t)0);
|
|
|
|
#endif
|
2008-06-12 17:01:38 +04:00
|
|
|
rb_thread_raise(2, argv, vm->main_thread);
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 16:55:12 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
|
|
|
|
{
|
2008-07-03 18:27:43 +04:00
|
|
|
VALUE coverage = GET_THREAD()->cfp->iseq->coverage;
|
2008-07-08 17:57:06 +04:00
|
|
|
if (coverage && RBASIC(coverage)->klass == 0) {
|
2008-07-03 18:27:43 +04:00
|
|
|
long line = rb_sourceline() - 1;
|
2008-07-03 16:55:12 +04:00
|
|
|
long count;
|
|
|
|
if (RARRAY_PTR(coverage)[line] == Qnil) {
|
|
|
|
rb_bug("bug");
|
|
|
|
}
|
|
|
|
count = FIX2LONG(RARRAY_PTR(coverage)[line]) + 1;
|
|
|
|
if (POSFIXABLE(count)) {
|
|
|
|
RARRAY_PTR(coverage)[line] = LONG2FIX(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-08 19:13:22 +04:00
|
|
|
VALUE
|
|
|
|
rb_get_coverages(void)
|
2008-07-08 17:57:06 +04:00
|
|
|
{
|
2008-07-08 19:13:22 +04:00
|
|
|
return GET_VM()->coverages;
|
2008-07-08 17:57:06 +04:00
|
|
|
}
|
|
|
|
|
2008-07-08 19:13:22 +04:00
|
|
|
void
|
|
|
|
rb_set_coverages(VALUE coverages)
|
2008-07-08 17:57:06 +04:00
|
|
|
{
|
2008-07-08 19:13:22 +04:00
|
|
|
GET_VM()->coverages = coverages;
|
|
|
|
rb_add_event_hook(update_coverage, RUBY_EVENT_COVERAGE, Qnil);
|
2008-07-08 17:57:06 +04:00
|
|
|
}
|
|
|
|
|
2008-07-03 16:55:12 +04:00
|
|
|
void
|
2008-07-08 19:13:22 +04:00
|
|
|
rb_reset_coverages(void)
|
2008-07-03 16:55:12 +04:00
|
|
|
{
|
2008-07-08 19:13:22 +04:00
|
|
|
GET_VM()->coverages = Qfalse;
|
|
|
|
rb_remove_event_hook(update_coverage);
|
2008-07-03 16:55:12 +04:00
|
|
|
}
|