aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cont.c24
-rw-r--r--coroutine/arm32/Context.h1
-rw-r--r--coroutine/copy/Context.h4
-rw-r--r--coroutine/ucontext/Context.h4
-rw-r--r--coroutine/win32/Context.h1
-rw-r--r--coroutine/x86/Context.h1
6 files changed, 23 insertions, 12 deletions
diff --git a/cont.c b/cont.c
index 16e8d7c33d..25fb62354a 100644
--- a/cont.c
+++ b/cont.c
@@ -37,7 +37,16 @@ static VALUE rb_cFiberPool;
#endif
#define CAPTURE_JUST_VALID_VM_STACK 1
-//#define FIBER_POOL_ALLOCATION_FREE
+
+// Defined in `coroutine/$arch/Context.h`:
+#ifdef COROUTINE_LIMITED_ADDRESS_SPACE
+#define FIBER_POOL_ALLOCATION_FREE
+#define FIBER_POOL_INITIAL_SIZE 8
+#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 32
+#else
+#define FIBER_POOL_INITIAL_SIZE 32
+#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 4096
+#endif
enum context_type {
CONTINUATION_CONTEXT = 0,
@@ -461,15 +470,6 @@ fiber_pool_expand(struct fiber_pool * fiber_pool, size_t count)
return allocation;
}
-static inline size_t
-fiber_pool_default_allocation_count_limit() {
- if (sizeof(void*) <= 4) {
- return 32;
- } else {
- return 1024;
- }
-}
-
// Initialize the specified fiber pool with the given number of stacks.
// @param vm_stack_size The size of the vm stack to allocate.
static void
@@ -542,7 +542,7 @@ fiber_pool_stack_acquire(struct fiber_pool * fiber_pool) {
if (DEBUG) fprintf(stderr, "fiber_pool_stack_acquire: %p used=%zu\n", fiber_pool->vacancies, fiber_pool->used);
if (!vacancy) {
- const size_t maximum = fiber_pool_default_allocation_count_limit();
+ const size_t maximum = FIBER_POOL_ALLOCATION_MAXIMUM_SIZE;
const size_t minimum = fiber_pool->initial_count;
size_t count = fiber_pool->count;
@@ -2335,7 +2335,7 @@ Init_Cont(void)
#endif
SET_MACHINE_STACK_END(&th->ec->machine.stack_end);
- fiber_pool_initialize(&shared_fiber_pool, stack_size, 8, vm_stack_size);
+ fiber_pool_initialize(&shared_fiber_pool, stack_size, FIBER_POOL_INITIAL_SIZE, vm_stack_size);
rb_cFiber = rb_define_class("Fiber", rb_cObject);
rb_define_alloc_func(rb_cFiber, fiber_alloc);
diff --git a/coroutine/arm32/Context.h b/coroutine/arm32/Context.h
index 27f97908bc..e29fe1bb63 100644
--- a/coroutine/arm32/Context.h
+++ b/coroutine/arm32/Context.h
@@ -11,6 +11,7 @@
#include <string.h>
#define COROUTINE __attribute__((noreturn)) void
+#define COROUTINE_LIMITED_ADDRESS_SPACE
enum {COROUTINE_REGISTERS = 8};
diff --git a/coroutine/copy/Context.h b/coroutine/copy/Context.h
index a62efa4e8a..0b6e3a9be0 100644
--- a/coroutine/copy/Context.h
+++ b/coroutine/copy/Context.h
@@ -16,6 +16,10 @@
#define COROUTINE __attribute__((noreturn)) void
+#if INTPTR_MAX <= INT32_MAX
+#define COROUTINE_LIMITED_ADDRESS_SPACE
+#endif
+
// This stack copying implementation which uses a private stack for each coroutine, including the main one.
#define COROUTINE_PRIVATE_STACK
diff --git a/coroutine/ucontext/Context.h b/coroutine/ucontext/Context.h
index bde9be302a..6cf16c8604 100644
--- a/coroutine/ucontext/Context.h
+++ b/coroutine/ucontext/Context.h
@@ -13,6 +13,10 @@
#define COROUTINE __attribute__((noreturn)) void
+#if INTPTR_MAX <= INT32_MAX
+#define COROUTINE_LIMITED_ADDRESS_SPACE
+#endif
+
struct coroutine_context
{
ucontext_t state;
diff --git a/coroutine/win32/Context.h b/coroutine/win32/Context.h
index fe1a8a3648..c70b65cd2f 100644
--- a/coroutine/win32/Context.h
+++ b/coroutine/win32/Context.h
@@ -11,6 +11,7 @@
#include <string.h>
#define COROUTINE __declspec(noreturn) void __fastcall
+#define COROUTINE_LIMITED_ADDRESS_SPACE
/* This doesn't include thread information block */
enum {COROUTINE_REGISTERS = 4};
diff --git a/coroutine/x86/Context.h b/coroutine/x86/Context.h
index a783dd296f..6d3a56eaa6 100644
--- a/coroutine/x86/Context.h
+++ b/coroutine/x86/Context.h
@@ -11,6 +11,7 @@
#include <string.h>
#define COROUTINE __attribute__((noreturn, fastcall)) void
+#define COROUTINE_LIMITED_ADDRESS_SPACE
enum {COROUTINE_REGISTERS = 4};