@@ -116,7 +116,6 @@ struct caml_thread_table {
116
116
caml_thread_t active_thread ;
117
117
st_masterlock thread_lock ;
118
118
int tick_thread_running ;
119
- int tick_thread_enabled ;
120
119
st_thread_id tick_thread_id ;
121
120
};
122
121
@@ -146,9 +145,6 @@ static void thread_lock_release(int dom_id)
146
145
/* Whether the "tick" thread is already running for this domain */
147
146
#define Tick_thread_running thread_table[Caml_state->id].tick_thread_running
148
147
149
- /* Whether the "tick" thread is enabled for this domain */
150
- #define Tick_thread_enabled thread_table[Caml_state->id].tick_thread_enabled
151
-
152
148
/* The thread identifier of the "tick" thread for this domain */
153
149
#define Tick_thread_id thread_table[Caml_state->id].tick_thread_id
154
150
@@ -511,18 +507,15 @@ CAMLprim value caml_thread_initialize(value unit)
511
507
return Val_unit ;
512
508
}
513
509
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
-
523
510
CAMLprim value caml_thread_cleanup (value unit )
524
511
{
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
+
526
519
return Val_unit ;
527
520
}
528
521
@@ -601,29 +594,6 @@ static int create_tick_thread(void)
601
594
return err ;
602
595
}
603
596
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
-
627
597
CAMLprim value caml_thread_new (value clos )
628
598
{
629
599
CAMLparam1 (clos );
@@ -671,9 +641,10 @@ CAMLprim value caml_thread_new(value clos)
671
641
sync_check_error (err , "Thread.create" );
672
642
}
673
643
674
- if (Tick_thread_enabled ) {
675
- err = start_tick_thread ();
644
+ if (! Tick_thread_running ) {
645
+ err = create_tick_thread ();
676
646
sync_check_error (err , "Thread.create" );
647
+ Tick_thread_running = 1 ;
677
648
}
678
649
CAMLreturn (th -> descr );
679
650
}
@@ -716,9 +687,10 @@ CAMLexport int caml_c_thread_register(void)
716
687
/* Allocate the thread descriptor on the heap */
717
688
th -> descr = caml_thread_new_descriptor (Val_unit ); /* no closure */
718
689
719
- if (Tick_thread_enabled ) {
720
- st_retcode err = start_tick_thread ();
690
+ if (! Tick_thread_running ) {
691
+ st_retcode err = create_tick_thread ();
721
692
sync_check_error (err , "caml_register_c_thread" );
693
+ Tick_thread_running = 1 ;
722
694
}
723
695
724
696
/* Release the master lock */
0 commit comments