summaryrefslogtreecommitdiff
path: root/includes/StacklessTask.h
blob: 3c86c0e51707c65d40874c10e7c9effb8bd74dcb (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once

#include <Task.h>

namespace Balau {

class StacklessTask : public Task {
  public:
      StacklessTask() { setStackless(); }
  protected:
    void taskSwitch() throw (GeneralException) { throw TaskSwitch(); }
    unsigned int m_state = 0;
};

};

#define StacklessBegin() \
    switch(m_state) { \
    case 0: { \


#define StacklessOperation(operation) \
        m_state = __LINE__; \
    } \
    case __LINE__: { \
        try { \
            operation; \
        } \
        catch (Balau::EAgain &) { \
            taskSwitch(); \
        } \


#define StacklessOperationOrCond(operation, cond) \
        m_state = __LINE__; \
    } \
    case __LINE__: { \
        try { \
            if (!(cond)) { \
                operation; \
            } \
        } \
        catch (Balau::EAgain &) { \
            taskSwitch(); \
        } \


#define StacklessWaitFor(evt) \
        m_state = __LINE__; \
        waitFor(evt); \
        taskSwitch(); \
    } \
    case __LINE__: { \


#define StacklessWaitCond(cond) \
        m_state = __LINE__; \
    } \
    case __LINE__: { \
        if (!(cond)) \
            taskSwitch(); \


#define StacklessYield() \
        m_state = __LINE__; \
        try { \
            yieldNoWait(); \
        } \
        catch (Balau::EAgain &) { \
            taskSwitch(); \
        } \
    } \
    case __LINE__: { \


#define StacklessEnd() \
        break; \
    } \
    default: \
        AssertHelper("unknown state", "State %i is out of range in task %s at %p", m_state, getName(), this); \
    }