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