aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/rng-egd.c9
-rw-r--r--backends/rng-random.c6
-rw-r--r--backends/rng.c17
-rw-r--r--include/sysemu/rng.h3
4 files changed, 19 insertions, 16 deletions
diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index 30332edb81..6e0ba22241 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -49,11 +49,10 @@ static void rng_egd_request_entropy(RngBackend *b, RngRequest *req)
static int rng_egd_chr_can_read(void *opaque)
{
RngEgd *s = RNG_EGD(opaque);
- GSList *i;
+ RngRequest *req;
int size = 0;
- for (i = s->parent.requests; i; i = i->next) {
- RngRequest *req = i->data;
+ QSIMPLEQ_FOREACH(req, &s->parent.requests, next) {
size += req->size - req->offset;
}
@@ -65,8 +64,8 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
RngEgd *s = RNG_EGD(opaque);
size_t buf_offset = 0;
- while (size > 0 && s->parent.requests) {
- RngRequest *req = s->parent.requests->data;
+ while (size > 0 && !QSIMPLEQ_EMPTY(&s->parent.requests)) {
+ RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
int len = MIN(size, req->size - req->offset);
memcpy(req->data + req->offset, buf + buf_offset, len);
diff --git a/backends/rng-random.c b/backends/rng-random.c
index a6cb3858e3..122e8d494d 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -35,8 +35,8 @@ static void entropy_available(void *opaque)
{
RndRandom *s = RNG_RANDOM(opaque);
- while (s->parent.requests != NULL) {
- RngRequest *req = s->parent.requests->data;
+ while (!QSIMPLEQ_EMPTY(&s->parent.requests)) {
+ RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
ssize_t len;
len = read(s->fd, req->data, req->size);
@@ -58,7 +58,7 @@ static void rng_random_request_entropy(RngBackend *b, RngRequest *req)
{
RndRandom *s = RNG_RANDOM(b);
- if (s->parent.requests == NULL) {
+ if (QSIMPLEQ_EMPTY(&s->parent.requests)) {
/* If there are no pending requests yet, we need to
* install our fd handler. */
qemu_set_fd_handler(s->fd, entropy_available, NULL, s);
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,
diff --git a/include/sysemu/rng.h b/include/sysemu/rng.h
index 4fffd681a6..45629c4c53 100644
--- a/include/sysemu/rng.h
+++ b/include/sysemu/rng.h
@@ -39,6 +39,7 @@ struct RngRequest
void *opaque;
size_t offset;
size_t size;
+ QSIMPLEQ_ENTRY(RngRequest) next;
};
struct RngBackendClass
@@ -56,7 +57,7 @@ struct RngBackend
/*< protected >*/
bool opened;
- GSList *requests;
+ QSIMPLEQ_HEAD(requests, RngRequest) requests;
};