Skip to content

Commit

Permalink
PR13052 (Make caml_max_stack_wsize atomic to avoid a data race): upst…
Browse files Browse the repository at this point in the history
…ream 5fe8065
  • Loading branch information
mshinwell committed Aug 16, 2024
1 parent a229de3 commit 990ebf4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ocaml/runtime/caml/gc_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "misc.h"

CAMLextern uintnat caml_max_stack_wsize;
CAMLextern atomic_uintnat caml_max_stack_wsize;
CAMLextern uintnat caml_fiber_wsz;
CAMLextern uintnat caml_major_cycles_completed;

Expand Down
3 changes: 2 additions & 1 deletion ocaml/runtime/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,9 @@ int caml_try_realloc_stack(asize_t required_space)
old_stack = Caml_state->current_stack;
stack_used = Stack_high(old_stack) - (value*)old_stack->sp;
wsize = Stack_high(old_stack) - Stack_base(old_stack);
uintnat max_stack_wsize = caml_max_stack_wsize;
do {
if (wsize >= caml_max_stack_wsize) return 0;
if (wsize >= max_stack_wsize) return 0;
wsize *= 2;
} while (wsize < stack_used + required_space);

Expand Down
4 changes: 2 additions & 2 deletions ocaml/runtime/gc_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "caml/startup.h"
#include "caml/fail.h"

uintnat caml_max_stack_wsize;
atomic_uintnat caml_max_stack_wsize;
uintnat caml_fiber_wsz;

extern uintnat caml_major_heap_increment; /* percent or words; see major_gc.c */
Expand Down Expand Up @@ -338,7 +338,7 @@ void caml_init_gc (void)
caml_percent_free = norm_pfree (caml_params->init_percent_free);
caml_gc_log ("Initial stack limit: %"
ARCH_INTNAT_PRINTF_FORMAT "uk bytes",
caml_max_stack_wsize / 1024 * sizeof (value));
caml_params->init_max_stack_wsz / 1024 * sizeof (value));

caml_custom_major_ratio =
norm_custom_maj (caml_params->init_custom_major_ratio);
Expand Down

0 comments on commit 990ebf4

Please sign in to comment.