Skip to content

Commit

Permalink
Remove channel pre-definition
Browse files Browse the repository at this point in the history
  • Loading branch information
hurufu committed Mar 9, 2024
1 parent 1bb551c commit aacff36
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion co/comultitask.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static inline void sus_exit(void) {

__attribute__((noreturn))
static void starter(struct sus_coroutine_reg* const reg) {
reg->result = reg->entry(&reg->ca, reg->args);
reg->result = reg->entry(reg->args);
sus_exit();
}

Expand Down
7 changes: 1 addition & 6 deletions co/comultitask.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

enum fdt { FDT_READ, FDT_WRITE, FDT_EXCEPT };

struct coro_args {
const int* fd, * idx;
};

typedef int (* sus_entry)(const struct coro_args*, void*);
typedef int (* sus_entry)(void*);

struct sus_coroutine_reg {
const size_t stack_size;
struct coro_args ca;
int result;
const sus_entry entry;
void* const args;
Expand Down
2 changes: 1 addition & 1 deletion co/frob.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct args_frontend_timer {
int cs;
};

int fsm_wireformat(const struct coro_args*, void*);
int fsm_wireformat(void*);
int fsm_frontend_foreign(struct args_frontend_foreign*);
int fsm_frontend_internal(struct args_frontend_internal*);
int fsm_frontend_timer(struct args_frontend_timer*);
3 changes: 2 additions & 1 deletion co/frontend.rl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "frob.h"
#include <stdbool.h>
#include <sys/timerfd.h>
#include <unistd.h>

static int cs;

Expand All @@ -23,7 +24,7 @@ static int cs;

action Confirm { acknak = 0x06; }
action Reject { acknak = 0x15; }
action Send { sus_write(2, &acknak, 1); }
action Send { sus_write(STDOUT_FILENO, &acknak, 1); }

foreign = (OK @Confirm | NAK @Reject) @Send;
internal = IDEMPOTENT ACK | IDEMPOTENT TIMEOUT{1,3} ACK;
Expand Down
20 changes: 4 additions & 16 deletions co/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ struct args_io_loop {
time_t timeout;
};

int co_io_loop(const struct coro_args* const ca, const struct args_io_loop* const args) {
struct io_params iop = { .maxfd = ca->fd[0] + 1 };
FD_SET(ca->fd[0], &iop.set[0]);
LOGDX("start with fd[0] %d", ca->fd[0]);
int co_io_loop(const struct args_io_loop* const args) {
struct io_params iop = { .maxfd = STDIN_FILENO + 1 };
FD_SET(STDIN_FILENO, &iop.set[0]);
LOGDX("start with fd[0] %d", STDIN_FILENO);
io_wait_f* const waitio = get_io_wait(args->timeout);
while (waitio(&iop)) {
LOGDX("data received");
Expand All @@ -33,28 +33,16 @@ int main() {
struct sus_coroutine_reg tasks[] = {
{
.stack_size = 0,
.ca = {
.fd = (int[]){ STDIN_FILENO },
.idx = NULL
},
.entry = fsm_wireformat,
.args = NULL
},
{
.stack_size = 0,
.ca = {
.fd = (int[]){ STDIN_FILENO },
.idx = NULL
},
.entry = (sus_entry)co_io_loop,
.args = &(struct args_io_loop){ .timeout = -1, .s6_notification_fd = -1 }
},
{
.stack_size = 0,
.ca = {
.fd = NULL,
.idx = (int[]){ 0 }
},
.entry = (sus_entry)fsm_frontend_foreign,
.args = &(struct args_frontend_foreign){}
}
Expand Down
6 changes: 3 additions & 3 deletions co/wireprotocol.rl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

%% write data;

int fsm_wireformat(const struct coro_args* const ca, void*) {
int fsm_wireformat(void*) {
char* start = NULL, * end = NULL;
(void)end, (void)start, (void)wireformat_en_main, (void)wireformat_error, (void)wireformat_first_final;
char lrc;
Expand All @@ -32,9 +32,9 @@ int fsm_wireformat(const struct coro_args* const ca, void*) {
int cs;
char* p = buf, * pe = p;
%% write init;
while ((bytes = sus_read(ca->fd[0], buf, sizeof buf)) > 0) {
while ((bytes = sus_read(STDIN_FILENO, buf, sizeof buf)) > 0) {
%% write exec;
}
close(ca->fd[0]);
close(STDIN_FILENO);
return 0;
}

0 comments on commit aacff36

Please sign in to comment.