diff options
-rw-r--r-- | lib9p/srv.c | 12 | ||||
-rw-r--r-- | libcr/coroutine.c | 7 | ||||
-rw-r--r-- | libcr_ipc/include/libcr_ipc/_common.h | 5 | ||||
-rw-r--r-- | libcr_ipc/include/libcr_ipc/sema.h | 4 | ||||
-rw-r--r-- | libnetio/netio_posix.c | 14 |
5 files changed, 21 insertions, 21 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index 997d137..af713e2 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -53,7 +53,7 @@ struct lib9p_req { /* base utilities *************************************************************/ -#define nonrespond_errorf(...) fprintf(stderr, "error: " __VA_ARGS__) +#define nonrespond_errorf(fmt, ...) fprintf(stderr, "error: " fmt "\n" __VA_OPT__(,) __VA_ARGS__) static uint32_t rerror_overhead_for_version(enum lib9p_version version, uint8_t *scratch) { struct lib9p_ctx empty_ctx = { @@ -99,18 +99,20 @@ static void respond_error(struct lib9p_req *req) { /* read coroutine *************************************************************/ static bool read_at_least(int fd, uint8_t *buf, size_t goal, size_t *done) { + assert(buf); + assert(goal); + assert(done); while (*done < goal) { ssize_t r = netio_read(fd, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done); if (r < 0) { nonrespond_errorf("read: %s", strerror(-r)); return true; } else if (r == 0) { - if (*done != 0) { + if (*done != 0) nonrespond_errorf("read: unexpected EOF"); - return true; - } - *done += r; + return true; } + *done += r; } return false; } diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 79ba894..25e3e4f 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -421,7 +421,7 @@ static inline void _cr_transition(enum coroutine_state state) { next = next_coroutine(); if (next) break; - if (state == CR_RUNNABLE) { + if (coroutine_table[coroutine_running-1].state == CR_RUNNABLE) { debugf("cid=%zu: no other runnable coroutines, not yielding\n", coroutine_running); coroutine_table[coroutine_running-1].state = CR_RUNNING; return; @@ -473,10 +473,13 @@ void cr_unpause_from_sighandler(cid_t cid) { switch (coroutine_table[cid-1].state) { case CR_RUNNING: + debugf("... raced, deferring unpause\n"); coroutine_table[cid-1].sig_unpause = true; break; case CR_PAUSED: - coroutine_table[cid-1].state = CR_RUNNABLE; + debugf("... actual unpause\n"); + coroutine_table[cid-1].sig_unpause = false; + coroutine_table[cid-1].state = CR_RUNNABLE; break; default: assertf(false, "cid=%zu state=%s\n", diff --git a/libcr_ipc/include/libcr_ipc/_common.h b/libcr_ipc/include/libcr_ipc/_common.h index 547ab81..247ba3d 100644 --- a/libcr_ipc/include/libcr_ipc/_common.h +++ b/libcr_ipc/include/libcr_ipc/_common.h @@ -31,10 +31,15 @@ struct _cr_ipc_cid_fifo { .next = NULL, \ } +static inline bool _cr_ipc_cid_fifo_isempty(struct _cr_ipc_cid_fifo *fifo) { + return !fifo->head; +} + static inline void _cr_ipc_cid_fifo_push(struct _cr_ipc_cid_fifo *fifo, struct _cr_ipc_cid_fifo_node *self) { if (!fifo->tail) fifo->tail = &(fifo->head); *(fifo->tail) = self; + fifo->tail = &(self->next); } static inline cid_t _cr_ipc_cid_fifo_pop(struct _cr_ipc_cid_fifo *fifo) { diff --git a/libcr_ipc/include/libcr_ipc/sema.h b/libcr_ipc/include/libcr_ipc/sema.h index 8d71c69..257c8d5 100644 --- a/libcr_ipc/include/libcr_ipc/sema.h +++ b/libcr_ipc/include/libcr_ipc/sema.h @@ -45,7 +45,7 @@ static inline bool _cr_sema_drain(cr_sema_t *sema) { sema->locked = true; asm volatile ("":::"memory"); while (state == DRAINING) { - if (!sema->waiters.head) { + if (_cr_ipc_cid_fifo_isempty(&sema->waiters)) { state = DRAINED_ALL; } else if (!sema->cnt) { state = DRAINED_SOME; @@ -66,7 +66,7 @@ static inline bool _cr_sema_drain(cr_sema_t *sema) { } while (state == DRAINED_SOME && sema->cnt); /* If state == DRAINED_SELF, then we better have been the last * item in the list! */ - assert(state != DRAINED_SELF || !sema->waiters.head); + assert(state != DRAINED_SELF || _cr_ipc_cid_fifo_isempty(&sema->waiters)); return state == DRAINED_SELF; } diff --git a/libnetio/netio_posix.c b/libnetio/netio_posix.c index 34eac80..34f415d 100644 --- a/libnetio/netio_posix.c +++ b/libnetio/netio_posix.c @@ -10,8 +10,6 @@ #include <sys/socket.h> /* for struct sockaddr, socket(), SOCK_* flags, setsockopt(), SOL_SOCKET, SO_REUSEADDR, bind(), listen(), accept() */ #include <unistd.h> /* for getpid() */ -#include <stdio.h> - #define USE_CONFIG_NETIO_POSIX #include "config.h" @@ -138,11 +136,9 @@ int netio_accept(int sock) { * while waiting for us to accept(). */ for (;;) { #if CONFIG_NETIO_ISLINUX - printf("accept...\n"); cr_sema_wait(&socket_table[sock].accept_waiters); #endif int conn = accept(socket_table[sock].fd, NULL, NULL); - printf("... accept => %d\n", conn); if (conn < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { #if !CONFIG_NETIO_ISLINUX @@ -174,11 +170,8 @@ ssize_t netio_read(int conn, void *buf, size_t count) { if (aio_read(&ctl_block) < 0) return -errno; - while ((r = aio_error(&ctl_block)) == EINPROGRESS) { - printf("read %zu...\n", count); + while ((r = aio_error(&ctl_block)) == EINPROGRESS) cr_pause_and_yield(); - } - printf("...read => n=%zd errno=%d\n", aio_return(&ctl_block), r); return r ? -abs(r) : aio_return(&ctl_block); } @@ -202,11 +195,8 @@ ssize_t netio_write(int conn, void *buf, size_t goal) { if (aio_write(&ctl_block) < 0) return -errno; - while ((r = aio_error(&ctl_block)) == EINPROGRESS) { - printf("write %zu...\n", goal-done); + while ((r = aio_error(&ctl_block)) == EINPROGRESS) cr_pause_and_yield(); - } - printf("...write => n=%zd errno=%d", aio_return(&ctl_block), r); if (r < 0) return -abs(r); done += aio_return(&ctl_block); |