this is a demonstration of using TIMEOUT_INITIALIZED().
because we know the timeout is always set up correctly, we dont
have to test for it all over the place.
Index: rnd.c
===================================================================
RCS file: /cvs/src/sys/dev/rnd.c,v
retrieving revision 1.145
diff -u -p -r1.145 rnd.c
--- rnd.c 2 Nov 2013 19:37:25 -0000 1.145
+++ rnd.c 9 Dec 2013 03:53:45 -0000
@@ -212,6 +212,10 @@ struct timer_rand_state { /* There is on
#define QEVSLOW (QEVLEN * 3 / 4) /* yet another 0.75 for 60-minutes hour /-; */
#define QEVSBITS 10
+void dequeue_randomness(void *);
+void add_entropy_words(const u_int32_t *, u_int);
+void extract_entropy(u_int8_t *, int);
+
struct rand_event {
struct timer_rand_state *re_state;
u_int re_nbits;
@@ -221,17 +225,13 @@ struct rand_event {
struct rand_event *rnd_event_head = rnd_event_space;
struct rand_event *rnd_event_tail = rnd_event_space;
-struct timeout rnd_timeout;
+struct timeout rnd_timeout = TIMEOUT_INITIALIZER(dequeue_randomness, NULL);
struct rndstats rndstats;
u_int32_t entropy_pool[POOLWORDS];
u_int entropy_add_ptr;
u_char entropy_input_rotate;
-void dequeue_randomness(void *);
-void add_entropy_words(const u_int32_t *, u_int);
-void extract_entropy(u_int8_t *, int);
-
int filt_randomread(struct knote *, long);
void filt_randomdetach(struct knote *);
int filt_randomwrite(struct knote *, long);
@@ -303,8 +303,7 @@ enqueue_randomness(int state, int val)
return;
#endif
- if (timeout_initialized(&rnd_timeout))
- nanotime(&ts);
+ nanotime(&ts);
p = &rnd_states[state];
val += state << 13;
@@ -392,8 +391,7 @@ enqueue_randomness(int state, int val)
rndstats.rnd_sc[state]++;
rndstats.rnd_sb[state] += nbits;
- if (rnd_qlen() > QEVSLOW/2 && timeout_initialized(&rnd_timeout) &&
- !timeout_pending(&rnd_timeout))
+ if (rnd_qlen() > QEVSLOW/2 && !timeout_pending(&rnd_timeout))
timeout_add(&rnd_timeout, 1);
done:
mtx_leave(&entropylock);
@@ -461,8 +459,7 @@ dequeue_randomness(void *v)
mtx_enter(&entropylock);
- if (timeout_initialized(&rnd_timeout))
- timeout_del(&rnd_timeout);
+ timeout_del(&rnd_timeout);
rndstats.rnd_deqs++;
while ((rep = rnd_get())) {
@@ -778,7 +775,6 @@ random_start(void)
task_set(&arc4_task, arc4_init, NULL, NULL);
timeout_set(&arc4_timeout, arc4_reinit, NULL);
arc4_reinit(NULL);
- timeout_set(&rnd_timeout, dequeue_randomness, NULL);
}
void