1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef EVENT_H
17 #define EVENT_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define MS_PER_SECOND 1000
27 #define NS_PER_MS 1000000
28 
29 #define EVENT_WAIT_TIMEOUT_ERR -1
30 #define EVENT_WAIT_OTHER_ERR -2
31 
32 typedef struct Event Event;
33 
34 /**
35  * @brief Perform instantiation of the Event, set Event Attributes isAutoClear.
36  *
37  * @param isAutoClear Event isAutoClear or not. If Event is not autoClear,
38  *            should perform EventClear after EventSet Manually.
39  * @return Event pointer.
40  * @since 6
41  */
42 Event *EventCreate(bool isAutoClear);
43 
44 /**
45  * @brief Delete an Event object.
46  *
47  * @param event Event pointer.
48  * @since 6
49  */
50 void EventDelete(Event *event);
51 
52 /**
53  * @brief Set an Event.
54  *
55  * @param event Event pointer.
56  * @since 6
57  */
58 void EventSet(Event *event);
59 
60 /**
61  * @brief Clear an Event.
62  *
63  * @param event Event pointer.
64  * @since 6
65  */
66 void EventClear(Event *event);
67 
68 /**
69  * @brief Wait an Event object, wait for Fixed time or block waiting.
70  *
71  * @param event Event pointer.
72  * @param ms Countdown time. If countdown time less than 0, block waiting.
73  * @return Success return 0, timeout return -1, failed return -2.
74  * @since 6
75  */
76 int32_t EventWait(Event *event, int64_t ms);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif  // EVENT_H