mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* cont.c: use #if FIBER_USE_NATIVE instead of #ifdef.
you can suppress use of setcontext for Fiber with compile option -DFIBER_USE_NATIVE=0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dc62f1b651
commit
4d85a0df20
2 changed files with 21 additions and 14 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Jun 6 22:51:43 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
||||
|
||||
* cont.c: use #if FIBER_USE_NATIVE instead of #ifdef.
|
||||
you can suppress use of setcontext for Fiber with compile option
|
||||
-DFIBER_USE_NATIVE=0
|
||||
|
||||
Mon Jun 6 21:59:23 2011 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* test/date/test_switch_hitter.rb: added a test.
|
||||
|
|
29
cont.c
29
cont.c
|
@ -33,10 +33,11 @@
|
|||
* are represented by stack pointer (higher bits of stack pointer).
|
||||
* TODO: check such constraint on configure.
|
||||
*/
|
||||
|
||||
#elif !defined(FIBER_USE_NATIVE)
|
||||
#define FIBER_USE_NATIVE 0
|
||||
#endif
|
||||
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -84,7 +85,7 @@ enum fiber_status {
|
|||
TERMINATED
|
||||
};
|
||||
|
||||
#if defined(FIBER_USE_NATIVE) && !defined(_WIN32)
|
||||
#if FIBER_USE_NATIVE && !defined(_WIN32)
|
||||
#define MAX_MAHINE_STACK_CACHE 10
|
||||
static int machine_stack_cache_index = 0;
|
||||
typedef struct machine_stack_cache_struct {
|
||||
|
@ -101,7 +102,7 @@ typedef struct rb_fiber_struct {
|
|||
enum fiber_status status;
|
||||
struct rb_fiber_struct *prev_fiber;
|
||||
struct rb_fiber_struct *next_fiber;
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
#ifdef _WIN32
|
||||
void *fib_handle;
|
||||
#else
|
||||
|
@ -183,7 +184,7 @@ cont_free(void *ptr)
|
|||
if (ptr) {
|
||||
rb_context_t *cont = ptr;
|
||||
RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack); fflush(stdout);
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
if (cont->type == CONTINUATION_CONTEXT) {
|
||||
/* cont */
|
||||
RUBY_FREE_UNLESS_NULL(cont->machine_stack);
|
||||
|
@ -490,7 +491,7 @@ cont_restore_thread(rb_context_t *cont)
|
|||
th->first_proc = sth->first_proc;
|
||||
}
|
||||
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
#ifdef _WIN32
|
||||
static void
|
||||
fiber_set_stack_location(void)
|
||||
|
@ -1030,7 +1031,7 @@ fiber_init(VALUE fibval, VALUE proc)
|
|||
|
||||
th->first_proc = proc;
|
||||
|
||||
#ifndef FIBER_USE_NATIVE
|
||||
#if !FIBER_USE_NATIVE
|
||||
MEMCPY(&cont->jmpbuf, &th->root_jmpbuf, rb_jmpbuf_t, 1);
|
||||
#endif
|
||||
|
||||
|
@ -1081,7 +1082,7 @@ rb_fiber_terminate(rb_fiber_t *fib)
|
|||
{
|
||||
VALUE value = fib->cont.value;
|
||||
fib->status = TERMINATED;
|
||||
#if defined(FIBER_USE_NATIVE) && !defined(_WIN32)
|
||||
#if FIBER_USE_NATIVE && !defined(_WIN32)
|
||||
/* Ruby must not switch to other thread until storing terminated_machine_stack */
|
||||
terminated_machine_stack.ptr = fib->context.uc_stack.ss_sp;
|
||||
terminated_machine_stack.size = fib->context.uc_stack.ss_size / sizeof(VALUE);
|
||||
|
@ -1143,7 +1144,7 @@ root_fiber_alloc(rb_thread_t *th)
|
|||
/* no need to allocate vm stack */
|
||||
fib = fiber_t_alloc(fiber_alloc(rb_cFiber));
|
||||
fib->cont.type = ROOT_FIBER_CONTEXT;
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
#ifdef _WIN32
|
||||
fib->fib_handle = ConvertThreadToFiber(0);
|
||||
#endif
|
||||
|
@ -1182,7 +1183,7 @@ fiber_store(rb_fiber_t *next_fib)
|
|||
th->root_fiber = th->fiber = fib->cont.self;
|
||||
}
|
||||
|
||||
#ifndef FIBER_USE_NATIVE
|
||||
#if !FIBER_USE_NATIVE
|
||||
cont_save_machine_stack(th, &fib->cont);
|
||||
|
||||
if (ruby_setjmp(fib->cont.jmpbuf)) {
|
||||
|
@ -1214,7 +1215,7 @@ fiber_store(rb_fiber_t *next_fib)
|
|||
if (fib->cont.argc == -1) rb_exc_raise(fib->cont.value);
|
||||
return fib->cont.value;
|
||||
}
|
||||
#ifndef FIBER_USE_NATIVE
|
||||
#if !FIBER_USE_NATIVE
|
||||
else {
|
||||
return Qundef;
|
||||
}
|
||||
|
@ -1253,7 +1254,7 @@ fiber_switch(VALUE fibval, int argc, VALUE *argv, int is_resume)
|
|||
cont = &fib->cont;
|
||||
cont->argc = -1;
|
||||
cont->value = value;
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
{
|
||||
VALUE oldfibval;
|
||||
rb_fiber_t *oldfib;
|
||||
|
@ -1274,7 +1275,7 @@ fiber_switch(VALUE fibval, int argc, VALUE *argv, int is_resume)
|
|||
cont->value = make_passing_arg(argc, argv);
|
||||
|
||||
value = fiber_store(fib);
|
||||
#ifndef FIBER_USE_NATIVE
|
||||
#if !FIBER_USE_NATIVE
|
||||
if (value == Qundef) {
|
||||
cont_restore_0(cont, &value);
|
||||
rb_bug("rb_fiber_resume: unreachable");
|
||||
|
@ -1420,7 +1421,7 @@ rb_fiber_s_current(VALUE klass)
|
|||
void
|
||||
Init_Cont(void)
|
||||
{
|
||||
#ifdef FIBER_USE_NATIVE
|
||||
#if FIBER_USE_NATIVE
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Reference in a new issue