aboutsummaryrefslogtreecommitdiff
path: root/backends/rng.c
diff options
context:
space:
mode:
authorLadi Prosek <lprosek@redhat.com>2016-03-03 14:16:11 +0100
committerAmit Shah <amit.shah@redhat.com>2016-03-08 12:54:14 +0530
commit443590c2044968a97f5e7cddd35100c6075856a4 (patch)
tree55fffa1528d3d3e52f9d2f64afb750d380927910 /backends/rng.c
parent97556fe80e4f7252300b3498b3477fb4295153a3 (diff)
rng: switch request queue to QSIMPLEQ
QSIMPLEQ supports appending to tail in O(1) and is intrusive so it doesn't require extra memory allocations for the bookkeeping data. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Ladi Prosek <lprosek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Amit Shah <amit.shah@redhat.com> Message-Id: <1457010971-24771-1-git-send-email-lprosek@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com>
Diffstat (limited to 'backends/rng.c')
-rw-r--r--backends/rng.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/backends/rng.c b/backends/rng.c
index 277a41bb0f..e57e2b4b52 100644
--- a/backends/rng.c
+++ b/backends/rng.c
@@ -33,7 +33,7 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,
k->request_entropy(s, req);
- s->requests = g_slist_append(s->requests, req);
+ QSIMPLEQ_INSERT_TAIL(&s->requests, req, next);
}
}
@@ -83,24 +83,27 @@ static void rng_backend_free_request(RngRequest *req)
static void rng_backend_free_requests(RngBackend *s)
{
- GSList *i;
+ RngRequest *req, *next;
- for (i = s->requests; i; i = i->next) {
- rng_backend_free_request(i->data);
+ QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) {
+ rng_backend_free_request(req);
}
- g_slist_free(s->requests);
- s->requests = NULL;
+ QSIMPLEQ_INIT(&s->requests);
}
void rng_backend_finalize_request(RngBackend *s, RngRequest *req)
{
- s->requests = g_slist_remove(s->requests, req);
+ QSIMPLEQ_REMOVE(&s->requests, req, RngRequest, next);
rng_backend_free_request(req);
}
static void rng_backend_init(Object *obj)
{
+ RngBackend *s = RNG_BACKEND(obj);
+
+ QSIMPLEQ_INIT(&s->requests);
+
object_property_add_bool(obj, "opened",
rng_backend_prop_get_opened,
rng_backend_prop_set_opened,