mirror of https://github.com/F-Stack/f-stack.git
132 lines
2.6 KiB
C
132 lines
2.6 KiB
C
|
|
|||
|
/**
|
|||
|
* Tencent is pleased to support the open source community by making MSEC available.
|
|||
|
*
|
|||
|
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
|||
|
*
|
|||
|
* Licensed under the GNU General Public License, Version 2.0 (the "License");
|
|||
|
* you may not use this file except in compliance with the License. You may
|
|||
|
* obtain a copy of the License at
|
|||
|
*
|
|||
|
* https://opensource.org/licenses/GPL-2.0
|
|||
|
*
|
|||
|
* Unless required by applicable law or agreed to in writing, software distributed under the
|
|||
|
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|||
|
* either express or implied. See the License for the specific language governing permissions
|
|||
|
* and limitations under the License.
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @file heap_timer.h
|
|||
|
*/
|
|||
|
|
|||
|
#ifndef _MICRO_THREAD_TIMER_H_
|
|||
|
#define _MICRO_THREAD_TIMER_H_
|
|||
|
|
|||
|
#include <stdint.h>
|
|||
|
#include "heap.h"
|
|||
|
|
|||
|
namespace NS_MICRO_THREAD
|
|||
|
{
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
class CTimerNotify : public HeapEntry
|
|||
|
{
|
|||
|
public:
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ֪ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
virtual void timer_notify() { return;};
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>Ƚ<EFBFBD>, <EFBFBD><EFBFBD><EFBFBD>Ӻ<EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @return <EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
*/
|
|||
|
virtual unsigned long long HeapValue() {
|
|||
|
return (unsigned long long)_time_expired;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
CTimerNotify() : _time_expired(0) {};
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
virtual ~CTimerNotify(){};
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD>þ<EFBFBD><EFBFBD>Գ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>λms
|
|||
|
* @param expired <EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD>ʱʱ<EFBFBD><EFBFBD> ms<EFBFBD><EFBFBD>λ
|
|||
|
*/
|
|||
|
void set_expired_time(uint64_t expired) {
|
|||
|
_time_expired = expired;
|
|||
|
};
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>λms
|
|||
|
* @return <EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD>ʱʱ<EFBFBD><EFBFBD> ms<EFBFBD><EFBFBD>λ
|
|||
|
*/
|
|||
|
uint64_t get_expired_time() {
|
|||
|
return _time_expired;
|
|||
|
};
|
|||
|
|
|||
|
private:
|
|||
|
|
|||
|
uint64_t _time_expired; // <20><><EFBFBD>Եij<D4B5>ʱʱ<CAB1><CAB1>ms<6D><73>λ
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
class CTimerMng
|
|||
|
{
|
|||
|
public:
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|||
|
* @param max_item <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ(ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ)
|
|||
|
*/
|
|||
|
explicit CTimerMng(uint32_t max_item = 100000);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
~CTimerMng();
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param timerable <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param interval <EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD> ms<EFBFBD><EFBFBD>λ
|
|||
|
* @return <EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>true, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
bool start_timer(CTimerNotify* timerable, uint32_t interval);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ֹͣ<EFBFBD>ӿں<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param timerable <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void stop_timer(CTimerNotify* timerable);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>⺯<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void check_expired();
|
|||
|
|
|||
|
private:
|
|||
|
|
|||
|
HeapList* _heap; // <20><>С<EFBFBD><D0A1>ָ<EFBFBD><D6B8>
|
|||
|
};
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#endif
|
|||
|
|