#include <ccan/timer/timer.h>
#include <ccan/array_size/array_size.h>
#include <ccan/ilog/ilog.h>
-#include <ccan/likely/likely.h>
#include <stdlib.h>
#include <stdio.h>
struct list_head list[PER_LEVEL];
};
+static void *timer_default_alloc(struct timers *timers, size_t len)
+{
+ return malloc(len);
+}
+
+static void timer_default_free(struct timers *timers, void *p)
+{
+ free(p);
+}
+
+static void *(*timer_alloc)(struct timers *, size_t) = timer_default_alloc;
+static void (*timer_free)(struct timers *, void *) = timer_default_free;
+
+void timers_set_allocator(void *(*alloc)(struct timers *, size_t len),
+ void (*free)(struct timers *, void *p))
+{
+ if (!alloc)
+ alloc = timer_default_alloc;
+ if (!free)
+ free = timer_default_free;
+ timer_alloc = alloc;
+ timer_free = free;
+}
+
static uint64_t time_to_grains(struct timemono t)
{
return t.ts.tv_sec * ((uint64_t)1000000000 / TIMER_GRANULARITY)
unsigned int i;
struct list_head from_far;
- l = malloc(sizeof(*l));
+ l = timer_alloc(timers, sizeof(*l));
if (!l)
return;
unsigned int l;
for (l = 0; l < ARRAY_SIZE(timers->level); l++)
- free(timers->level[l]);
+ timer_free(timers, timers->level[l]);
}