Procházet zdrojové kódy

Add portable get_ticks function.

tags/0.9.0
Vsevolod Stakhov před 9 roky
rodič
revize
f2d8ad8d00
2 změnil soubory, kde provedl 27 přidání a 0 odebrání
  1. 21
    0
      src/libutil/util.c
  2. 6
    0
      src/libutil/util.h

+ 21
- 0
src/libutil/util.c Zobrazit soubor

@@ -45,6 +45,10 @@
#include <readpassphrase.h>
#endif

#ifdef __APPLE__
#include <mach/mach_time.h>
#endif

/* Check log messages intensity once per minute */
#define CHECK_TIME 60
/* More than 2 log messages per second */
@@ -2233,6 +2237,23 @@ rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen)
return res;
}

gdouble
rspamd_get_ticks (void)
{
gdouble res;

#ifdef __APPLE__
res = mach_absolute_time () / 1000000000.;
#else
struct timespec ts;
clock_gettime (CLOCK_MONOTONIC, &ts);

res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
#endif

return res;
}

/* Required for tweetnacl */
void
randombytes (guchar *buf, guint64 len)

+ 6
- 0
src/libutil/util.h Zobrazit soubor

@@ -435,4 +435,10 @@ gchar * rspamd_encode_base32 (const guchar *in, gsize inlen);
*/
guchar* rspamd_decode_base32 (const gchar *in, gsize inlen, gsize *outlen);

/**
* Portably return the current clock ticks as seconds
* @return
*/
gdouble rspamd_get_ticks (void);

#endif

Načítá se…
Zrušit
Uložit