Skip to content

Commit c23c0a1

Browse files
committed
Rename macros and variables
To make the name of macros and variables indicate purpose of themself more clearly, some of them were renamed. Following lists the modified macros and variables: * Macro cr_func_def is renamed as cr_define, which will avoid confusing and make programmers focus on dealing body of coroutine. * Hardcoded __ct is renamed as ctx which stands for context.\ * The name of structure sock_w_loc_t is changed to conn_data_t, since it aims to hold data used for connection.
1 parent 6356cb5 commit c23c0a1

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tinync/tinync.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,40 @@ struct cr {
2525
}
2626

2727
#define cr_func_name(name) __cr_func_##name
28-
#define cr_func_def(name) static void cr_func_name(name)(struct cr * __ct)
28+
#define cr_define(name) static void cr_func_name(name)(struct cr * ctx)
2929

3030
#define cr_run(name) cr_func_name(name)(&cr_context_name(name))
3131

32-
#define cr_arg(type) (type *) (__ct->arg)
33-
#define cr_arg_member(type, memb) &((type *) (__ct->arg))->memb;
32+
#define cr_arg(type) (type *) (ctx->arg)
33+
#define cr_arg_member(type, memb) &((type *) (ctx->arg))->memb;
3434
#define cr_local static
3535

3636
#define cr_begin() \
3737
do { \
38-
if ((__ct)->status == CR_FINISHED) \
38+
if ((ctx)->status == CR_FINISHED) \
3939
return; \
40-
if ((__ct)->label) \
41-
goto *(__ct)->label; \
40+
if ((ctx)->label) \
41+
goto *(ctx)->label; \
4242
} while (0)
4343
#define cr_label(o, stat) \
4444
do { \
4545
(o)->status = (stat); \
4646
__cr_line(label) : (o)->label = &&__cr_line(label); \
4747
} while (0)
48-
#define cr_end() cr_label(__ct, CR_FINISHED)
48+
#define cr_end() cr_label(ctx, CR_FINISHED)
4949

5050
#define cr_status(name) cr_context_name(name).status
5151

5252
#define cr_wait(cond) \
5353
do { \
54-
cr_label(__ct, CR_BLOCKED); \
54+
cr_label(ctx, CR_BLOCKED); \
5555
if (!(cond)) \
5656
return; \
5757
} while (0)
5858

5959
#define cr_exit(stat) \
6060
do { \
61-
cr_label(__ct, stat); \
61+
cr_label(ctx, stat); \
6262
return; \
6363
} while (0)
6464

@@ -102,9 +102,9 @@ typedef cr_queue(uint8_t, 4096) byte_queue_t;
102102
typedef struct {
103103
int fd;
104104
byte_queue_t *queue;
105-
} sock_w_loc_t;
105+
} conn_data_t;
106106

107-
cr_func_def(stdin_loop)
107+
cr_define(stdin_loop)
108108
{
109109
byte_queue_t *out = cr_arg(byte_queue_t);
110110
cr_local uint8_t b;
@@ -122,10 +122,10 @@ cr_func_def(stdin_loop)
122122
cr_end();
123123
}
124124

125-
cr_func_def(socket_write_loop)
125+
cr_define(socket_write_loop)
126126
{
127-
byte_queue_t *in = *cr_arg_member(sock_w_loc_t, queue);
128-
int fd = *cr_arg_member(sock_w_loc_t, fd);
127+
byte_queue_t *in = *cr_arg_member(conn_data_t, queue);
128+
int fd = *cr_arg_member(conn_data_t, fd);
129129
cr_local uint8_t *b;
130130
cr_begin();
131131
for (;;) {
@@ -136,7 +136,7 @@ cr_func_def(socket_write_loop)
136136
cr_end();
137137
}
138138

139-
cr_func_def(socket_read_loop)
139+
cr_define(socket_read_loop)
140140
{
141141
int fd = *cr_arg(int);
142142
cr_local uint8_t b;
@@ -198,14 +198,14 @@ int main(int argc, char *argv[])
198198
connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
199199

200200
byte_queue_t queue = cr_queue_init();
201-
sock_w_loc_t sock_w_loc = {
201+
conn_data_t conn_data = {
202202
.fd = fd,
203203
.queue = &queue,
204204
};
205205

206206
cr_context(stdin_loop) = cr_context_init(&queue);
207207
cr_context(socket_read_loop) = cr_context_init(&fd);
208-
cr_context(socket_write_loop) = cr_context_init(&sock_w_loc);
208+
cr_context(socket_write_loop) = cr_context_init(&conn_data);
209209

210210
while (cr_status(stdin_loop) == CR_BLOCKED &&
211211
cr_status(socket_read_loop) == CR_BLOCKED) {

0 commit comments

Comments
 (0)