35 lines1.1 KB
Newer
Older
-
+
commited
{line.log.rev}
on
9 months ago
1
#ifndef GENERATOR_H
2
#define GENERATOR_H
9 months ago
3
#include "coroutine.h"
10 months ago
2
4
#include <stdbool.h>
5
9 months ago
6
typedef enum Generator_State {
7
Generator_Running,
8
Generator_Deleting,
9
Generator_Complete
10
} Generator_State;
11
12
typedef struct Generator {
13
Coroutine *coroutine;
7 days ago
14
Coroutine *yielded_coroutine;
9 months ago
15
Coroutine *caller;
16
void *(*start)(void *);
17
void *param;
18
Generator_State state;
19
} Generator;
20
1 weeks ago
21
extern void Generator_ctor(Generator *gen, size_t min_stack, size_t min_stack_headroom, void *(*start)(void *), void *param);
22
extern Generator *Generator_New(size_t min_stack, size_t min_stack_headroom, void *(*)(void *), void *);
8 months ago
23
extern void Generator_dtor(Generator *gen);
24
extern void Generator_Delete(Generator *);
10 months ago
2
25
26
// Returns true if generator yielded a value, false if generator is complete
27
// *value is set to generator's value (yield / return value from exit)
8 months ago
28
extern bool Generator_Next(Generator *, void **value);
10 months ago
2
29
30
// Yield a value from the generator
31
// Returns true if generator should continue, false for generator to exit PDQ
8 months ago
32
extern bool Generator_Yield(void *);
9 months ago
33
34
#endif
35