• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 LOOP_TIMER_H
17 #define LOOP_TIMER_H
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include "le_task.h"
21 #include "loop_event.h"
22 #include "le_loop.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define LE_MSEC_TO_NSEC 1000000
29 #define LE_SEC_TO_MSEC 1000
30 
31 typedef struct TimeNode {
32     uint32_t flags;
33     ListNode node;
34 #ifdef LOOP_EVENT_USE_MUTEX
35     LoopMutex mutex;
36 #else
37     uint8_t mutex;
38 #endif
39     uint64_t timeout;
40     uint64_t repeat;
41     uint64_t endTime;
42     LE_ProcessTimer process;
43     void *context;
44 } TimerNode;
45 
46 uint64_t GetCurrentTimespec(uint64_t timeout);
47 void CheckTimeoutOfTimer(EventLoop *loop, uint64_t currTime);
48 void DestroyTimerList(EventLoop *loop);
49 uint64_t GetMinTimeoutPeriod(const EventLoop *loop);
50 void CancelTimer(TimerHandle timerHandle);
51 #ifdef __cplusplus
52 }
53 #endif
54 #endif