summaryrefslogtreecommitdiff
path: root/includes/StacklessTask.h
blob: d21c63a8f7d22ad4efc78af2090d6704fdf31b37 (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
#pragma once

#include <Task.h>

namespace Balau {

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

};

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


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


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


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


#define StacklessYield() \
        m_state = __LINE__; \
        try { \
            yield(true); \
        } \
        catch (Balau::EAgain & e) { \
            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); \
    }