Add a timer to the PAL
This adds a way to periodically pool the PAL to see if any timers have expired. Timers can be used to periodically provide callbacks to the rest of snmalloc.
This commit is contained in:
committed by
Matthew Parkinson
parent
c1062e629e
commit
20a114cb62
32
src/pal/pal_timer_default.h
Normal file
32
src/pal/pal_timer_default.h
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pal_consts.h"
|
||||
#include "pal_ds.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
template<typename PalTime>
|
||||
class PalTimerDefaultImpl
|
||||
{
|
||||
inline static PalTimer timers{};
|
||||
|
||||
public:
|
||||
static uint64_t time_in_ms()
|
||||
{
|
||||
auto time = PalTime::internal_time_in_ms();
|
||||
|
||||
// Process timers
|
||||
timers.check(time);
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
static void register_timer(PalTimerObject* timer)
|
||||
{
|
||||
timers.register_timer(timer);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user