Service_NSSM/CC_SDK/Include/basic/CCTimer.h

34 lines
657 B
C
Raw Normal View History

2025-09-27 14:24:18 +08:00
#ifndef CC_TIMER_H
#define CC_TIMER_H
#pragma once
#include <CCThread.h>
#include "CC.h"
namespace CTL {
enum TimeType {
Microsecond = 0,
Millisecond = 1,
Second = 2,
Minute = 3,
Hour = 4,
};
class Timer {
public:
Timer();
~Timer();
// 启动定时器
void Start(const std::function<void()>& callback,unsigned long count,TimeType interval = TimeType::Millisecond);
// 停止定时器
void Stop();
private:
IntSleep m_sleep;
std::atomic<bool> m_running{};
std::thread m_thread;
std::mutex m_mutex;
};
}
#endif