summaryrefslogtreecommitdiffstats
path: root/src/coroutine.h
blob: a0543083c36f4e957c8f47a096a0f59faee808ce (plain)
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
43
44
45
46
47
48
49
#ifndef INCLUDE_COROUTINE_H
#define INCLUDE_COROUTINE_H

class Coroutine
{
public:
    enum Status
    {
        NotStarted,
        Running,
        Stopped,
        Terminated
    };

public:
    explicit Coroutine(int stackSize = 32768);
    virtual ~Coroutine();
    
    bool cont();
    static void yield();
    
    Status status()
    { return _status; }

    static Coroutine *currentCoroutine();

// add declarations for static build(...) function
#include "coroutinebuilddeclaration_p.h"

protected:
    virtual void run() {}

private:
    // for the original coroutine
    Coroutine(bool);

    static void yieldHelper(Status stopStatus);
    static void entryPoint();

    void *_stackData;
    void *_stackPointer;
    Coroutine *_previousCoroutine;
    Status _status;
};

// add definitions for static build(...) function
#include "coroutinebuilddefinition_p.h"

#endif // INCLUDE_COROUTINE_H