1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
samuel 2018-11-20 10:18:12 +00:00
parent c5d3b83a9f
commit 5e8a1dad86

28
cont.c
View file

@ -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 *)));