|
Hi All,
I need some help writing a library for a fedora box.
What I need to do is intercept timer calls, and cache the results that are
within 1ms.
eg: first call, get time. Second call, check if its within 1ms, if so, then
return stored time, else call gettime.
I have an example of such a function for solarice, but I need to have tis
built for fedora.
Could someone write this up for me?
thanks so much!
Chumly
Example:
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <dlfcn.h>
/* time in nanoseconds to cache the time system call */
#define DELTA 1000000 /* 1 millisecond */
static time_t (*func) (time_t *);
time_t time(time_t *tloc)
{
static time_t global = 0;
static hrtime_t old = 0;
hrtime_t new = gethrtime();
if(new - old DELTA ){
global = func(tloc);
old = new;
}
return global;
}
#pragma init (init_func)
void init_func()
{
func = (time_t (*) (time_t *)) dlsym (RTLD_NEXT, "time");
if (!func)
{
fprintf(stderr, "Error initializing library\n");
}
} |