]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
CLI: Sleep
authorJan Maria Matejka <mq@ucw.cz>
Thu, 13 Sep 2018 11:24:49 +0000 (13:24 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Fri, 14 Sep 2018 12:50:31 +0000 (14:50 +0200)
Sometimes CLI waits for another routine to finish. In these cases,
we shouldn't resume its run until it is explicitly woken up.

Adding the appropriate calls.

nest/cli.c
nest/cli.h

index 6e7e9eccad3d7f922d7c20d974494fe2e4738eec..5debc7cc1eb1ac7423cf0ff81d0a35b584c9a51a 100644 (file)
@@ -64,7 +64,7 @@
  * and its outpos field is the position of the read head.
  */
 
-#define LOCAL_DEBUG 1
+#undef LOCAL_DEBUG
 
 #include "nest/bird.h"
 #include "nest/cli.h"
@@ -243,6 +243,7 @@ cli_free_out(cli *c)
 static void
 cli_write(cli *c)
 {
+  DBG("CLI write begin\n");
   sock *s = c->socket;
 
   while (c->tx_pos)
@@ -261,7 +262,7 @@ cli_write(cli *c)
   /* Everything is written */
   s->tbuf = NULL;
   cli_free_out(c);
-  ev_schedule(c->event);
+  DBG("CLI write done\n");
 }
 
 void
@@ -484,6 +485,24 @@ cli_yield(cli *c)
   DBG("CLI: Yield resumed\n");
 }
 
+void
+cli_sleep(cli *c)
+{
+  c->state = CLI_STATE_SLEEP;
+  DBG("CLI: Sleeping\n");
+  coro_suspend();
+  c->state = CLI_STATE_RUN;
+  DBG("CLI: Woken up\n");
+}
+
+void
+cli_wakeup(cli *c)
+{
+  ASSERT(c->state == CLI_STATE_SLEEP);
+  c->state = CLI_STATE_YIELD;
+  ev_schedule(c->event);
+}
+
 static void
 cli_coroutine(void *_c)
 {
index 18e680e280099d2b8a6e18506caf928d1d596e80..80aea375519daf14a5b7705b9970afd068106e7e 100644 (file)
@@ -33,6 +33,7 @@ enum cli_state {
   CLI_STATE_WAIT_RX,
   CLI_STATE_WAIT_TX,
   CLI_STATE_YIELD,
+  CLI_STATE_SLEEP,
 };
 
 typedef struct cli {
@@ -79,6 +80,8 @@ void cli_printf(cli *, int, char *, ...);
 void cli_write_trigger(cli *c);
 void cli_set_log_echo(cli *, uint mask, uint size);
 void cli_yield(cli *c);
+void cli_sleep(cli *c);
+void cli_wakeup(cli *c);
 
 /* Functions provided to sysdep layer */