From 5e8a1dad862ee804a2a152eb4aa1c97180cbe2a2 Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 20 Nov 2018 10:18:12 +0000 Subject: Expose stack functions to coroutine and non-windows implementations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- cont.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'cont.c') diff --git a/cont.c b/cont.c index b76af31850..95a2d7c7d3 100644 --- a/cont.c +++ b/cont.c @@ -179,17 +179,6 @@ fiber_context_create(ucontext_t *context, void (*func)(), void *arg, void *ptr, } #endif -#if FIBER_USE_NATIVE && !defined(_WIN32) -#define MAX_MACHINE_STACK_CACHE 10 -static int machine_stack_cache_index = 0; -typedef struct machine_stack_cache_struct { - void *ptr; - size_t size; -} machine_stack_cache_t; -static machine_stack_cache_t machine_stack_cache[MAX_MACHINE_STACK_CACHE]; -static machine_stack_cache_t terminated_machine_stack; -#endif - struct rb_fiber_struct { rb_context_t cont; VALUE first_proc; @@ -203,12 +192,14 @@ struct rb_fiber_struct { #if FIBER_USE_NATIVE #if defined(FIBER_USE_COROUTINE) +#define FIBER_ALLOCATE_STACK coroutine_context context; void *ss_sp; size_t ss_size; #elif defined(_WIN32) void *fib_handle; #else +#define FIBER_ALLOCATE_STACK ucontext_t context; /* Because context.uc_stack.ss_sp and context.uc_stack.ss_size * are not necessarily valid after makecontext() or swapcontext(), @@ -220,6 +211,17 @@ struct rb_fiber_struct { #endif }; +#ifdef FIBER_ALLOCATE_STACK +#define MAX_MACHINE_STACK_CACHE 10 +static int machine_stack_cache_index = 0; +typedef struct machine_stack_cache_struct { + void *ptr; + size_t size; +} machine_stack_cache_t; +static machine_stack_cache_t machine_stack_cache[MAX_MACHINE_STACK_CACHE]; +static machine_stack_cache_t terminated_machine_stack; +#endif + static const char * fiber_status_name(enum fiber_status s) { @@ -847,7 +849,9 @@ fiber_entry(void *arg) rb_fiber_start(); } #endif +#endif +#ifdef FIBER_ALLOCATE_STACK /* * FreeBSD require a first (i.e. addr) argument of mmap(2) is not NULL * if MAP_STACK is passed. @@ -992,7 +996,7 @@ fiber_setcontext(rb_fiber_t *newfib, rb_fiber_t *oldfib) swapcontext(&oldfib->context, &newfib->context); #endif } -#endif /* FIBER_USE_NATIVE */ +#endif /* FIBER_ALLOCATE_STACK */ NOINLINE(NORETURN(static void cont_restore_1(rb_context_t *))); -- cgit v1.2.3