Skip to content

Commit

Permalink
Stuff from model.h/c moved to cr and chan
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information
sustrik committed Jun 18, 2015
1 parent abc3837 commit 4d3e3e0
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 123 deletions.
5 changes: 1 addition & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ millinclude_HEADERS = libmill.h
lib_LTLIBRARIES = libmill.la

libmill_la_SOURCES = \
chan.h\
chan.c\
cr.h\
cr.c\
debug.h\
debug.c\
list.h\
list.c\
model.h\
model.c\
poller.h\
poller.c\
slist.h\
Expand Down Expand Up @@ -96,8 +95,6 @@ noinst_PROGRAMS = \
perf/chs\
perf/chr

LDADD = libmill.la

################################################################################
# additional packaging-related stuff #
################################################################################
Expand Down
13 changes: 12 additions & 1 deletion chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/

#include "chan.h"
#include "cr.h"
#include "debug.h"
#include "libmill.h"
#include "model.h"
#include "utils.h"

#include <assert.h>
Expand All @@ -38,6 +38,17 @@ MILL_CT_ASSERT(MILL_CLAUSELEN == sizeof(struct mill_clause));

static int mill_choose_seqnum = 0;

struct mill_chan *mill_getchan(struct mill_ep *ep) {
switch(ep->type) {
case MILL_SENDER:
return mill_cont(ep, struct mill_chan, sender);
case MILL_RECEIVER:
return mill_cont(ep, struct mill_chan, receiver);
default:
assert(0);
}
}

chan mill_chmake(size_t sz, size_t bufsz, const char *created) {
/* If there's at least one channel created in the user's code
we want the debug functions to get into the binary. */
Expand Down
72 changes: 3 additions & 69 deletions model.h → chan.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,80 +22,14 @@
*/

#ifndef MILL_MODEL_INCLUDED
#define MILL_MODEL_INCLUDED
#ifndef MILL_CHAN_INCLUDED
#define MILL_CHAN_INCLUDED

#include "debug.h"
#include "model.h"
#include "list.h"
#include "poller.h"
#include "slist.h"
#include "utils.h"
#include "valbuf.h"

#include <stdint.h>

enum mill_state {
MILL_READY,
MILL_MSLEEP,
MILL_FDWAIT,
MILL_CHR,
MILL_CHS,
MILL_CHOOSE
};

struct mill_ready {
struct mill_slist_item item;
};

/* This structure covers fdwait and msleep operations. */
struct mill_fdwait {
/* Item in the global list of timers. */
struct mill_list_item item;
/* The timepoint when the timer expires. */
uint64_t expiry;
};

/* This structure covers chr, chs and choose operations. */
struct mill_choose {
/* List of clauses in the 'choose' statement. */
struct mill_slist clauses;
/* 1 if there is 'otherwise' clause. 0 if there is not. */
int othws;
/* Number of clauses that are immediately available. */
int available;
};

/* The coroutine. This structure is held on the top of the coroutine's stack. */
struct mill_cr {
/* Status of the coroutine. Used for debugging purposes. */
enum mill_state state;

struct mill_ready u_ready;
struct mill_fdwait u_fdwait;
struct mill_choose u_choose;

/* Stored coroutine context while it is not executing. */
struct mill_ctx ctx;

/* Place to temporarily store the value received from a channel. */
struct mill_valbuf valbuf;

/* Argument to resume() call being passed to the blocked suspend() call. */
int result;

/* Coroutine-local storage. */
void *cls;

/* Debugging info. */
struct mill_debug_cr debug;
};

/* Fake coroutine corresponding to the main thread of execution. */
extern struct mill_cr mill_main;

/* The coroutine that is running at the moment. */
extern struct mill_cr *mill_running;
#include <stddef.h>

/* Channel endpoint. */
struct mill_ep {
Expand Down
5 changes: 4 additions & 1 deletion cr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "cr.h"
#include "debug.h"
#include "libmill.h"
#include "model.h"
#include "poller.h"
#include "stack.h"
#include "utils.h"

Expand All @@ -36,6 +36,9 @@
volatile int mill_unoptimisable1 = 1;
volatile void *mill_unoptimisable2 = NULL;

struct mill_cr mill_main = {0};
struct mill_cr *mill_running = &mill_main;

/* Queue of coroutines scheduled for execution. */
static struct mill_slist mill_ready = {0};

Expand Down
70 changes: 69 additions & 1 deletion cr.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,75 @@
#ifndef MILL_CR_INCLUDED
#define MILL_CR_INCLUDED

struct mill_cr;
#include "debug.h"
#include "list.h"
#include "slist.h"
#include "utils.h"
#include "valbuf.h"

#include <stdint.h>

enum mill_state {
MILL_READY,
MILL_MSLEEP,
MILL_FDWAIT,
MILL_CHR,
MILL_CHS,
MILL_CHOOSE
};

struct mill_ready {
struct mill_slist_item item;
};

/* This structure covers fdwait and msleep operations. */
struct mill_fdwait {
/* Item in the global list of timers. */
struct mill_list_item item;
/* The timepoint when the timer expires. */
uint64_t expiry;
};

/* This structure covers chr, chs and choose operations. */
struct mill_choose {
/* List of clauses in the 'choose' statement. */
struct mill_slist clauses;
/* 1 if there is 'otherwise' clause. 0 if there is not. */
int othws;
/* Number of clauses that are immediately available. */
int available;
};

/* The coroutine. This structure is held on the top of the coroutine's stack. */
struct mill_cr {
/* Status of the coroutine. Used for debugging purposes. */
enum mill_state state;

struct mill_ready u_ready;
struct mill_fdwait u_fdwait;
struct mill_choose u_choose;

/* Stored coroutine context while it is not executing. */
struct mill_ctx ctx;

/* Place to temporarily store the value received from a channel. */
struct mill_valbuf valbuf;

/* Argument to resume() call being passed to the blocked suspend() call. */
int result;

/* Coroutine-local storage. */
void *cls;

/* Debugging info. */
struct mill_debug_cr debug;
};

/* Fake coroutine corresponding to the main thread of execution. */
extern struct mill_cr mill_main;

/* The coroutine that is running at the moment. */
extern struct mill_cr *mill_running;

/* Suspend running coroutine. Move to executing different coroutines. Once
someone resumes this coroutine using mill_resume function 'result' argument
Expand Down
4 changes: 3 additions & 1 deletion debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*/

#include "chan.h"
#include "cr.h"
#include "libmill.h"
#include "model.h"
#include "list.h"
#include "utils.h"

#include <assert.h>
Expand Down
1 change: 0 additions & 1 deletion libmill.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ MILL_EXPORT void tcpclose(tcpsock s);
/******************************************************************************/

MILL_EXPORT void goredump(void);

MILL_EXPORT void trace(int level);

#endif
Expand Down
43 changes: 0 additions & 43 deletions model.c

This file was deleted.

1 change: 0 additions & 1 deletion poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "cr.h"
#include "libmill.h"
#include "list.h"
#include "model.h"
#include "poller.h"
#include "utils.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/choose.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ int main() {
chan ch15 = chmake(struct large, 1);
chan ch16 = chmake(int, 1);
go(sender2(chdup(ch16), 1111));
// goredump();
goredump();
choose {
in(ch16, int, val):
assert(val == 1111);
Expand Down

0 comments on commit 4d3e3e0

Please sign in to comment.