-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_task_mgr.h
109 lines (93 loc) · 3.77 KB
/
thread_task_mgr.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef THREAD_TASK_MGR_H_INCLUDED
#define THREAD_TASK_MGR_H_INCLUDED
////////////////////////////////////////////////////////////////////////////////////////////
// libraries
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
//////////////////////////////////////////////////////////////////////////////////
// definitions
/** what to do next ?
1. Check the LINE store point, and how it should work.
2. How to manage the sequence order inside functions and tasks.
*/
//////////////////////////////////////////////////////////////////////////////////
// enumerations
typedef enum { BitClear = 0, BitSet = 1, FunctionFinished = 2 } FunctionState;
typedef enum { TaskStart = 0, TaskBusy = 1, TaskFinished = 2 } TaskState;
/// Basic function state check
#define \
FunctionStart \
static int function_state = 0; \
static int bit_counter = 0; \
switch(function_state) \
{ \
case 0:
#define \
FunctionCheck(bit, bit_state) \
do \
{ \
case __LINE__: \
if(bit == bit_state && bit_counter < 2)\
{ \
bit_counter++; \
printf("function return BitSet bit_counter %d\n", bit_counter);\
function_state = __LINE__; \
return BitSet; \
} \
else{ \
bit = 0; \
bit_counter = 0; \
printf("function return BitClear\n");\
} \
}while(0)
#define \
FunctionEnd \
} \
function_state = 0; \
bit_counter = 0; \
printf("FUNC DONE# %s = %d\n", __func__, FunctionFinished);\
return FunctionFinished; \
printf("print after FUNC DONE#\n")
/// Task sequence manager
#define \
TaskStart \
static int task_state = 0; \
printf("TASK STARTED# %d\n", task_state);\
switch(task_state) \
{ \
case 0:
#define \
TaskFunctionSet \
task_state = __LINE__; \
case __LINE__: \
printf("TASK STORE POINT# %d\n", task_state)
#define \
CheckTask(bit, bit_state) \
do \
{ \
if(bit == bit_state) \
{ \
printf("CheckTask = TaskBusy func# %s, line# %d\n\n",__func__, __LINE__); \
return TaskBusy; \
} \
else{ \
printf("CheckTask = TaskFinished func# %s, line# %d\n\n",__func__, __LINE__); \
} \
}while(0)
#define \
TaskEnd \
} \
task_state = 0; \
printf("TASK DONE# %s = %d\n", __func__, TaskFinished);\
return TaskFinished; \
printf("print after TASK DONE#\n")
// function pointer
// pointers
// variables
//////////////////////////////////////////////////////////////////////////////////
// functions
#endif // THREAD_TASK_MGR_H_INCLUDED