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.
* 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"
static void
cli_write(cli *c)
{
+ DBG("CLI write begin\n");
sock *s = c->socket;
while (c->tx_pos)
/* Everything is written */
s->tbuf = NULL;
cli_free_out(c);
- ev_schedule(c->event);
+ DBG("CLI write done\n");
}
void
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)
{
CLI_STATE_WAIT_RX,
CLI_STATE_WAIT_TX,
CLI_STATE_YIELD,
+ CLI_STATE_SLEEP,
};
typedef struct cli {
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 */