-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhstacklesscoroutine.c
93 lines (82 loc) · 1.96 KB
/
hstacklesscoroutine.c
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
/***************************************************************
* Name: hstacklesscoroutine.c
* Purpose: 实现hstacklesscoroutine接口
* Author: HYH (hyhsystem.cn)
* Created: 2024-08-24
* Copyright: HYH (hyhsystem.cn)
* License: MIT
**************************************************************/
#include "hstacklesscoroutine.h"
#include "stdlib.h"
bool hstacklesscoroutine_is_finished(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
return (ccb->flags&(0x1ULL<<1))!=0;
}
return true;
}
void hstacklesscoroutine_coroutine_restart(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
if(hstacklesscoroutine_is_finished(ccb))
{
ccb->flags=0;
ccb->corevalue=0;
}
}
}
void hstacklesscoroutine_coroutine_force_restart(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
ccb->flags=0;
ccb->corevalue=0;
}
}
bool hstacklesscoroutine_is_suspend(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
return (ccb->flags &(0x1ULL<<0))!=0;
}
return false;
}
void hstacklesscoroutine_coroutine_suspend(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
ccb->flags|=(0x1ULL << 0);
}
}
void hstacklesscoroutine_coroutine_resume(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
ccb->flags&=~(0x1ULL << 0);
}
}
bool hstacklesscoroutine_is_await(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
return ccb->awaiter.wait_for_ready!=NULL;
}
return false;
}
int hstacklesscoroutine_coroutine_get_current_nested(hstacklesscoroutine_control_block_t *ccb)
{
if(ccb!=NULL)
{
return ccb->nested;
}
return 0;
}
void hstacklesscoroutine_coroutine_set_max_nested(hstacklesscoroutine_control_block_t *ccb,int max_nested)
{
if(ccb!=NULL &&max_nested > 0)
{
ccb->max_nested=max_nested;
}
}