Commit 049b2bff authored by Jan Maria Matejka's avatar Jan Maria Matejka Committed by Maria Matejka
Browse files

Coro: Fixed deadlock when CLI is killed.

parent 9668c97e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,5 +18,6 @@ void coro_resume(coroutine *c);

struct birdsock;
int coro_sk_read(struct birdsock *s);
void coro_sk_write(struct birdsock *s, unsigned len);

#endif
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ typedef struct birdsock {
  struct ssh_sock *ssh;			/* Used in SK_SSH */

  struct coroutine *rx_coroutine;
  struct coroutine *tx_coroutine;
} sock;

sock *sock_new(pool *);			/* Allocate new socket */
+1 −9
Original line number Diff line number Diff line
@@ -246,8 +246,7 @@ cli_write(cli *c)
      s->tbuf = o->outpos;
      o->outpos = o->wpos;

      if (sk_send(s, len) <= 0)
	return;
      coro_sk_write(s, len);

      c->tx_pos = o->next;
    }
@@ -265,12 +264,6 @@ cli_write_trigger(cli *c)
    cli_write(c);
}

static void
cli_tx_hook(sock *s)
{
  cli_write(s->data);
}

static void
cli_err_hook(sock *s, int err)
{
@@ -542,7 +535,6 @@ cli_new(sock *s)

  s->pool = c->pool;		/* We need to have all the socket buffers allocated in the cli pool */
  rmove(s, c->pool);
  s->tx_hook = cli_tx_hook;
  s->err_hook = cli_err_hook;
  s->data = c;

+21 −0
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ static void
coro_free(resource *r)
{
  coroutine *c = (coroutine *) r;
  ASSERT(coro_current != c);
  pthread_cancel(c->thread);
  pthread_join(c->thread, NULL);
}
@@ -246,6 +247,14 @@ coro_sk_rx_hook(sock *sk, uint size UNUSED)
  return 0;
}

static void
coro_sk_tx_hook(sock *sk)
{
  ASSERT(sk->tx_coroutine);
  ASSERT(!coro_current);
  coro_resume(sk->tx_coroutine);
}

int
coro_sk_read(sock *s)
{
@@ -256,3 +265,15 @@ coro_sk_read(sock *s)
  s->rx_hook = NULL;
  return s->rpos - s->rbuf;
}

void
coro_sk_write(sock *s, unsigned len)
{
  ASSERT(coro_current);
  s->tx_coroutine = coro_current;
  s->tx_hook = coro_sk_tx_hook;
  s->ttx = s->tbuf;
  s->tpos = s->tbuf + len;
  coro_suspend();
  s->tx_hook = NULL;
}