Commit d1f33012 authored by Jan Maria Matejka's avatar Jan Maria Matejka
Browse files

CLI: Sleep

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.
parent a0bd04c0
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -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)
{
+3 −0
Original line number Diff line number Diff line
@@ -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 */