From 4d85a0df206abc08fe0c7a0f20c2f2f6293c65f2 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 6 Jun 2011 14:06:59 +0000 Subject: * 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 --- cont.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'cont.c') diff --git a/cont.c b/cont.c index 9a0593c21e..72e111797c 100644 --- a/cont.c +++ b/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 #include @@ -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 -- cgit v1.2.3