1 contributor
34 lines998 bytes
Newer
Older
-
+
commited
{line.log.rev}
on
8 months ago
1
#ifndef GENERATOR_H
2
#define GENERATOR_H
8 months ago
3
#include "coroutine.h"
9 months ago
2
4
#include <stdbool.h>
5
8 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;
14
Coroutine *caller;
15
void *(*start)(void *);
16
void *param;
17
Generator_State state;
18
} Generator;
19
5 months ago
20
extern void Generator_ctor(Generator *gen, size_t stack_size, void *(*start)(void *), void *param);
21
extern Generator *Generator_New(size_t stack_size, void *(*)(void *), void *);
7 months ago
22
extern void Generator_dtor(Generator *gen);
23
extern void Generator_Delete(Generator *);
9 months ago
2
24
25
// Returns true if generator yielded a value, false if generator is complete
26
// *value is set to generator's value (yield / return value from exit)
7 months ago
27
extern bool Generator_Next(Generator *, void **value);
9 months ago
2
28
29
// Yield a value from the generator
30
// Returns true if generator should continue, false for generator to exit PDQ
7 months ago
31
extern bool Generator_Yield(void *);
8 months ago
32
33
#endif
34