chiark
/
gitweb
/
~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rand/noise.c: Make the high-res timer function be a bit more abstract.
[catacomb]
/
rand
/
noise.c
diff --git
a/rand/noise.c
b/rand/noise.c
index 2c30c13c0db79b570ae94f8b09b7ac81fcf3b169..f01af65187d639e6c3cf5b71b0429b100e022f68 100644
(file)
--- a/
rand/noise.c
+++ b/
rand/noise.c
@@
-64,7
+64,13
@@
/*----- Magical numbers ---------------------------------------------------*/
#define NOISE_KIDLIFE 100000 /* @noise_filter@ child lifetime */
/*----- Magical numbers ---------------------------------------------------*/
#define NOISE_KIDLIFE 100000 /* @noise_filter@ child lifetime */
-#define MILLION 1000000 /* One million */
+
+# define TIMESTRUCT timeval
+# define tv_SEC tv_sec
+# define tv_FRAC tv_usec
+# define TIMERES 1000000
+# define GETTIME(tv) (gettimeofday((tv), 0))
+# define TOTIMEVAL(tv, xx) (*(tv) = *(xx))
/*----- Noise source definition -------------------------------------------*/
/*----- Noise source definition -------------------------------------------*/
@@
-106,20
+112,20
@@
static int bitcount(unsigned long x)
/* --- @timer@ --- *
*
* Arguments: @rand_pool *r@ = pointer to randomness pool
/* --- @timer@ --- *
*
* Arguments: @rand_pool *r@ = pointer to randomness pool
- * @
struct timeval
*tv@ = pointer to time block
+ * @
const struct TIMESTRUCT
*tv@ = pointer to time block
*
* Returns: Nonzero if some randomness was contributed.
*
* Use: Low-level timer contributor.
*/
*
* Returns: Nonzero if some randomness was contributed.
*
* Use: Low-level timer contributor.
*/
-static int timer(rand_pool *r,
struct timeval
*tv)
+static int timer(rand_pool *r,
const struct TIMESTRUCT
*tv)
{
unsigned long x, d, dd;
int de, dde;
int ret;
{
unsigned long x, d, dd;
int de, dde;
int ret;
- x = tv->tv_
usec + MILLION * tv->tv_sec
;
+ x = tv->tv_
FRAC + TIMERES*tv->tv_SEC
;
d = x ^ noise_last;
dd = d ^ noise_diff;
noise_last = x;
d = x ^ noise_last;
dd = d ^ noise_diff;
noise_last = x;
@@
-146,9
+152,8
@@
static int timer(rand_pool *r, struct timeval *tv)
int noise_timer(rand_pool *r)
{
int noise_timer(rand_pool *r)
{
- struct timeval tv;
- gettimeofday(&tv, 0);
- return (timer(r, &tv));
+ struct TIMESTRUCT tv;
+ GETTIME(&tv); return (timer(r, &tv));
}
/* --- @noise_devrandom@ --- *
}
/* --- @noise_devrandom@ --- *
@@
-319,6
+324,7
@@
int noise_filter(rand_pool *r, int good, const char *c)
pid_t kid;
int fd[2];
struct timeval dead;
pid_t kid;
int fd[2];
struct timeval dead;
+ struct TIMESTRUCT now;
int ret = 0;
struct noisekid nk = { 0 };
sel_state sel;
int ret = 0;
struct noisekid nk = { 0 };
sel_state sel;
@@
-331,8
+337,8
@@
int noise_filter(rand_pool *r, int good, const char *c)
/* --- Remember when this business started --- */
/* --- Remember when this business started --- */
-
gettimeofday(&dead, 0
);
-
timer(r, &dead
);
+
GETTIME(&now); timer(r, &now
);
+
TOTIMEVAL(&dead, &now
);
/* --- Create a pipe --- */
/* --- Create a pipe --- */