-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.c
More file actions
42 lines (36 loc) · 672 Bytes
/
03.c
File metadata and controls
42 lines (36 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "coro.h"
#include "test.h"
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
static int hit = 0;
#define HITCHECK(k) do { EXPECT(hit == k); hit = k + 1; } while (0)
static void f2()
{
void *ret;
HITCHECK(2);
assert(!coro_yield(&ret));
}
static void *f1(void *data)
{
void *ret;
HITCHECK(0);
assert(!coro_yield(&ret));
f2();
HITCHECK(4);
return NULL;
}
int main(int argc, char *argv[])
{
struct coro *co;
void *ret;
assert(!coro_create(&co, f1, 0x10000U));
assert(!coro_resume(co, &ret));
HITCHECK(1);
assert(!coro_resume(co, &ret));
HITCHECK(3);
assert(!coro_resume(co, &ret));
HITCHECK(5);
assert(!coro_free(co));
return 0;
}