99 lines
3.0 KiB
C
99 lines
3.0 KiB
C
/***
|
|
* @Author: shenghao.xu
|
|
* @Date: 2023-04-17 10:51:38
|
|
* @LastEditors: shenghao.xu
|
|
* @LastEditTime: 2023-04-17 10:53:09
|
|
* @Description:
|
|
* @email:545403892@qq.com
|
|
* @Copyright (c) 2023 by shenghao.xu, All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef __FLOW_CORE_
|
|
#define __FLOW_CORE_
|
|
|
|
#include "flow_def.h"
|
|
|
|
// 在定时器中断中调用
|
|
#define FLOW_TICK_UPDATE() \
|
|
do \
|
|
{ \
|
|
flow_tick++; \
|
|
} while (0);
|
|
|
|
#define FLOW_INIT(f) ((f)->line = 0)
|
|
|
|
#define FLOW_HEAD(f) \
|
|
{ \
|
|
volatile char lock_once_flag = 0; \
|
|
switch ((f)->line) \
|
|
{ \
|
|
case 0:
|
|
|
|
#define FLOW_TAIL(f) \
|
|
} \
|
|
; \
|
|
lock_once_flag = (f)->line = 0; \
|
|
return FLOW_END; \
|
|
} \
|
|
;
|
|
|
|
#define FLOW_LOCK_WAIT(f, judge) \
|
|
do \
|
|
{ \
|
|
(f)->line = __LINE__; \
|
|
case __LINE__:; \
|
|
if (!(judge)) \
|
|
return FLOW_WAIT; \
|
|
} while (0)
|
|
|
|
#define FLOW_LOCK_WHILE(f, judge) \
|
|
do \
|
|
{ \
|
|
(f)->line = __LINE__; \
|
|
case __LINE__:; \
|
|
if (judge) \
|
|
return FLOW_WAIT; \
|
|
} while (0)
|
|
|
|
#define FLOW_EXIT(f) \
|
|
do \
|
|
{ \
|
|
(f)->line = 0; \
|
|
return FLOW_FINISH; \
|
|
} while (0)
|
|
|
|
#define FLOW_LOCK_ONCE(f) \
|
|
do \
|
|
{ \
|
|
lock_once_flag = 1; \
|
|
(f)->line = __LINE__; \
|
|
case __LINE__:; \
|
|
if (lock_once_flag) \
|
|
return FLOW_LOCK; \
|
|
} while (0)
|
|
|
|
#define FLOW_WAIT_PROCESS_END(f, process) FLOW_LOCK_WHILE(f, (process) < FLOW_FINISH)
|
|
|
|
#define FLOW_WAIT_CHILD_PROCESS_END(f, cf, process) \
|
|
do \
|
|
{ \
|
|
FLOW_INIT((cf)); \
|
|
FLOW_WAIT_PROCESS_END((f), (process)); \
|
|
} while (0)
|
|
|
|
#define FLOW_LOCK_DELAY(f, t) \
|
|
do \
|
|
{ \
|
|
(f)->time = flow_tick; \
|
|
FLOW_LOCK_WAIT((f), ((flow_tick - (f)->time) >= (t))); \
|
|
} while (0)
|
|
|
|
#define FLOW_LOCK_DELAY_OR_WAIT(f, judge, t) \
|
|
do \
|
|
{ \
|
|
(f)->time = flow_tick; \
|
|
FLOW_LOCK_WAIT((f), ((judge) || ((flow_tick - (f)->time) >= (t)))); \
|
|
} while (0)
|
|
|
|
#endif /* __FLOW_CORE_ */
|