xref: /f-stack/app/micro_thread/heap_timer.h (revision 02610d58)
1 
2 /**
3  * Tencent is pleased to support the open source community by making MSEC available.
4  *
5  * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
6  *
7  * Licensed under the GNU General Public License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License. You may
9  * obtain a copy of the License at
10  *
11  *     https://opensource.org/licenses/GPL-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the
14  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language governing permissions
16  * and limitations under the License.
17  */
18 
19 
20 /**
21  * @file  heap_timer.h
22  */
23 
24 #ifndef _MICRO_THREAD_TIMER_H_
25 #define _MICRO_THREAD_TIMER_H_
26 
27 #include <stdint.h>
28 #include "heap.h"
29 
30 namespace NS_MICRO_THREAD
31 {
32 
33 class CTimerNotify : public HeapEntry
34 {
35 public:
36 
37     virtual void timer_notify() { return;};
38 
39     virtual unsigned long long HeapValue() {
40         return (unsigned long long)_time_expired;
41     };
42 
43     CTimerNotify() : _time_expired(0) {};
44 
45     virtual ~CTimerNotify(){};
46 
47     void set_expired_time(uint64_t expired) {
48         _time_expired = expired;
49     };
50 
51     uint64_t get_expired_time() {
52         return _time_expired;
53     };
54 
55 private:
56 
57     uint64_t        _time_expired;
58 };
59 
60 
61 class CTimerMng
62 {
63 public:
64 
65 
66     explicit CTimerMng(uint32_t max_item = 100000);
67 
68     ~CTimerMng();
69 
70     bool start_timer(CTimerNotify* timerable, uint32_t interval);
71 
72     void stop_timer(CTimerNotify* timerable);
73 
74     void check_expired();
75 
76 private:
77 
78     HeapList*           _heap;
79 };
80 
81 }
82 
83 #endif
84 
85