40 lines
1.4 KiB
C
40 lines
1.4 KiB
C
/***
|
|
* @Author:
|
|
* @Date: 2023-04-17 10:51:38
|
|
* @LastEditors: xxx
|
|
* @LastEditTime: 2023-04-17 22:20:58
|
|
* @Description:
|
|
* @email:
|
|
* @Copyright (c) 2023 by xxx, All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef __FLOW_SEM_H__
|
|
#define __FLOW_SEM_H__
|
|
|
|
#include "flow_def.h"
|
|
#include "flow_core.h"
|
|
|
|
#define FLOW_SEM_INIT(s, c) ((s)->count = c)
|
|
|
|
#define FLOW_LOCK_WAIT_SEM(f, s) \
|
|
do \
|
|
{ \
|
|
FLOW_LOCK_WAIT(f, (s)->count > 0); \
|
|
--(s)->count; \
|
|
} while (0)
|
|
|
|
#define FLOW_LOCK_WAIT_SEM_OR_TIMEOUT(f, s, t) \
|
|
do \
|
|
{ \
|
|
(f)->time = flow_tick; \
|
|
(s)->time = (t); \
|
|
FLOW_LOCK_WAIT(f, (((s)->count > 0) || ((flow_tick - (f)->time) >= ((s)->time)))); \
|
|
if (((s)->count > 0) && ((flow_tick - (f)->time) < ((s)->time))) \
|
|
--(s)->count; \
|
|
} while (0)
|
|
|
|
#define FLOW_SEM_RELEASE(s) (++(s)->count)
|
|
|
|
#define FLOW_SEM_IS_RELEASE(f, s) (flow_tick - (f)->time) < ((s)->time)
|
|
#endif /* __FLOW_SEM_H__ */
|