Skip to content

Commit e1dbe77

Browse files
committed
Modify README.md
Following modifications are performed: * Add hyperlink to coroutine. * Use word "Internal" instead of "Usage" * Change to C-style comment. * Modify the description in Coroutine Context section.
1 parent efa8f73 commit e1dbe77

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

tinync/README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Tinync
2-
Tinync is a simplified version of [nc](https://en.wikipedia.org/wiki/Netcat), which aims to demonstrate the usage of coroutine macros and their effects.
2+
Tinync is a simplified version of [nc](https://en.wikipedia.org/wiki/Netcat), which aims to demonstrate the usage of [coroutine](https://en.wikipedia.org/wiki/Coroutine) macros and their effects.
33

4-
## Usage
4+
## Internals
55
### Declaring a Coroutine Function
66
At the very beginning, a coroutine function should be declared first, coroutine function is part of program that will be executed simultaneously with other coroutines. All coroutines should be specified with the macro `cr_proto`, following shows the example:
77
```cpp
@@ -30,22 +30,29 @@ static void cr_proto(stdin_loop, byte_queue_t *out)
3030
cr_local uint8_t b;
3131
cr_local int r;
3232
33-
cr_begin(); // Initiates the context of this coroutine.
33+
/* Initiates the context of this coroutine. */
34+
cr_begin();
3435
for (;;) {
35-
cr_sys(r = read(STDIN_FILENO, &b, 1)); // Wait for read system call to be success.
36+
/* Wait for read system call to be success. */
37+
cr_sys(r = read(STDIN_FILENO, &b, 1));
3638
if (r == 0) {
37-
cr_wait(cr_queue_empty(out)); // Wait until queue out is flushed.
38-
cr_exit(1); // Exit the coroutine with status update as finished.
39+
/* Wait until queue out is flushed. */
40+
cr_wait(cr_queue_empty(out));
41+
42+
/* Exit the coroutine with status update as finished. */
43+
cr_exit(1);
3944
}
40-
cr_wait(!cr_queue_full(out)); // Wait until there is place in queue out.
45+
/* Wait until there is place in queue out. */
46+
cr_wait(!cr_queue_full(out));
4147
cr_queue_push(out, b);
4248
}
43-
cr_end(); // End up this coroutine, status will be updated as finished.
49+
/* End up this coroutine, status will be updated as finished. */
50+
cr_end();
4451
}
4552
```
4653

4754
### Coroutine Context
48-
There is another important part of coroutine, that is, context. Context of a coroutine will preserve its execution point which could be resumed later. To define a context for a coroutine, use `cr_context` macro and initiates it with macro `cr_context_init`. It is important to **assign an identical name to context and its corresponding function**. With example presented at the beginning, its corresponding context should be specified as follows:
55+
Context is an important part for coroutine, which will preserve the execution point of a coroutine that could be resumed later. To define a context for a coroutine, use `cr_context` macro and initiates it with macro `cr_context_init`. It is important to **assign an identical name to context and its corresponding function**. With example presented at the beginning, its corresponding context should be specified as follows:
4956
```cpp
5057
cr_context(coroutine_name) = cr_context_init();
5158
```

0 commit comments

Comments
 (0)