Skip to content

Commit c6ca778

Browse files
authored
Revert "port #852 (add primitive to enable/disable tick thread) (#2054)" (#2129)
1 parent 16bdb1b commit c6ca778

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

ocaml/otherlibs/systhreads/st_stubs.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct caml_thread_table {
116116
caml_thread_t active_thread;
117117
st_masterlock thread_lock;
118118
int tick_thread_running;
119-
int tick_thread_enabled;
120119
st_thread_id tick_thread_id;
121120
};
122121

@@ -146,9 +145,6 @@ static void thread_lock_release(int dom_id)
146145
/* Whether the "tick" thread is already running for this domain */
147146
#define Tick_thread_running thread_table[Caml_state->id].tick_thread_running
148147

149-
/* Whether the "tick" thread is enabled for this domain */
150-
#define Tick_thread_enabled thread_table[Caml_state->id].tick_thread_enabled
151-
152148
/* The thread identifier of the "tick" thread for this domain */
153149
#define Tick_thread_id thread_table[Caml_state->id].tick_thread_id
154150

@@ -511,18 +507,15 @@ CAMLprim value caml_thread_initialize(value unit)
511507
return Val_unit;
512508
}
513509

514-
static void stop_tick_thread(void)
515-
{
516-
if (!Tick_thread_running) return;
517-
atomic_store_release(&Tick_thread_stop, 1);
518-
st_thread_join(Tick_thread_id);
519-
atomic_store_release(&Tick_thread_stop, 0);
520-
Tick_thread_running = 0;
521-
}
522-
523510
CAMLprim value caml_thread_cleanup(value unit)
524511
{
525-
stop_tick_thread();
512+
if (Tick_thread_running){
513+
atomic_store_release(&Tick_thread_stop, 1);
514+
st_thread_join(Tick_thread_id);
515+
atomic_store_release(&Tick_thread_stop, 0);
516+
Tick_thread_running = 0;
517+
}
518+
526519
return Val_unit;
527520
}
528521

@@ -601,29 +594,6 @@ static int create_tick_thread(void)
601594
return err;
602595
}
603596

604-
static st_retcode start_tick_thread(void)
605-
{
606-
if (Tick_thread_running) return 0;
607-
st_retcode err = create_tick_thread();
608-
if (err == 0) Tick_thread_running = 1;
609-
return err;
610-
}
611-
612-
CAMLprim value caml_enable_tick_thread(value v_enable)
613-
{
614-
int enable = Long_val(v_enable) ? 1 : 0;
615-
616-
if (enable) {
617-
st_retcode err = start_tick_thread();
618-
sync_check_error(err, "caml_enable_tick_thread");
619-
} else {
620-
stop_tick_thread();
621-
}
622-
623-
Tick_thread_enabled = enable;
624-
return Val_unit;
625-
}
626-
627597
CAMLprim value caml_thread_new(value clos)
628598
{
629599
CAMLparam1(clos);
@@ -671,9 +641,10 @@ CAMLprim value caml_thread_new(value clos)
671641
sync_check_error(err, "Thread.create");
672642
}
673643

674-
if (Tick_thread_enabled) {
675-
err = start_tick_thread();
644+
if (! Tick_thread_running) {
645+
err = create_tick_thread();
676646
sync_check_error(err, "Thread.create");
647+
Tick_thread_running = 1;
677648
}
678649
CAMLreturn(th->descr);
679650
}
@@ -716,9 +687,10 @@ CAMLexport int caml_c_thread_register(void)
716687
/* Allocate the thread descriptor on the heap */
717688
th->descr = caml_thread_new_descriptor(Val_unit); /* no closure */
718689

719-
if (Tick_thread_enabled) {
720-
st_retcode err = start_tick_thread();
690+
if (! Tick_thread_running) {
691+
st_retcode err = create_tick_thread();
721692
sync_check_error(err, "caml_register_c_thread");
693+
Tick_thread_running = 1;
722694
}
723695

724696
/* Release the master lock */

0 commit comments

Comments
 (0)