Commit 87a726c3c44d9b659fce6e6a5cba50d34ac059a9

Thomas de Grivel 2022-08-09T16:32:21

g_rtbuf_running

diff --git a/cli/rtbuf_cli.c b/cli/rtbuf_cli.c
index 9efbaac..2860737 100644
--- a/cli/rtbuf_cli.c
+++ b/cli/rtbuf_cli.c
@@ -220,14 +220,17 @@ void * rtbuf_cli_run_thread_proc (void *arg)
 {
   (void) arg;
   printf("rtbuf thread: start\n");
-  if (!rtbuf_start())
+  if (!rtbuf_start()) {
     g_rtbuf_run = 1;
+    g_rtbuf_running = 1;
+  }
   while (g_rtbuf_run) {
     if (rtbuf_run())
       g_rtbuf_run = 0;
   }
   printf("rtbuf thread: stop\n");
   rtbuf_stop();
+  g_rtbuf_running = 0;
   return 0;
 }
 
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index 5b53224..ece4f6a 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -32,9 +32,10 @@ s_data_type   g_rtbuf_type = {
   sizeof(s_rtbuf) * 8,
   DATA_TYPE_BITS
 };
-s_data_alloc  g_rtbuf_alloc;
+s_data_alloc  g_rtbuf_alloc = {0};
 s_rtbuf      *g_rtbuf = 0;
 int           g_rtbuf_run = 0;
+int           g_rtbuf_running = 0;
 unsigned int  g_rtbuf_sort = 0;
 unsigned int  g_rtbuf_sorted[RTBUF_MAX];
 unsigned int  g_rtbuf_sorted_n = 0;
diff --git a/librtbuf/rtbuf.h b/librtbuf/rtbuf.h
index 4be7dd5..9491355 100644
--- a/librtbuf/rtbuf.h
+++ b/librtbuf/rtbuf.h
@@ -107,6 +107,11 @@ extern s_rtbuf     *g_rtbuf;
 extern int          g_rtbuf_run;
 
 /**
+ * @brief Is the main loop still active ?
+ */
+extern int          g_rtbuf_running;
+
+/**
  * @brief Callback function for rtbuf_new.
  */
 typedef void (*f_rtbuf_new_cb) (s_rtbuf *rtb);