#include <isc/app.h>
#include <isc/buffer.h>
+#include <isc/refcount.h>
#include <isc/socket.h>
#include <isc/task.h>
#include <isc/timer.h>
static dns_dispatch_t *dispatch = NULL;
static dns_dispentry_t *dispentry = NULL;
-static bool first = true;
-static isc_mutex_t lock;
+static atomic_bool first = ATOMIC_VAR_INIT(true);
static isc_sockaddr_t local;
-static unsigned int responses = 0;
+static isc_refcount_t responses;
static void
response(isc_task_t *task, isc_event_t *event) {
dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event;
- isc_result_t result;
- bool wasfirst;
+ bool exp_true = true;
UNUSED(task);
- LOCK(&lock);
- wasfirst = first;
- first = false;
- responses++;
- UNLOCK(&lock);
-
- if (wasfirst) {
- result = dns_dispatch_getnext(dispentry, &devent);
+ isc_refcount_increment(&responses);
+ if (atomic_compare_exchange_strong(&first, &exp_true, false)) {
+ isc_result_t result = dns_dispatch_getnext(dispentry, &devent);
assert_int_equal(result, ISC_R_SUCCESS);
} else {
dns_dispatch_removeresponse(&dispentry, &devent);
UNUSED(state);
- isc_mutex_init(&lock);
+ isc_refcount_init(&responses, 0);
result = isc_task_create(taskmgr, 0, &task);
assert_int_equal(result, ISC_R_SUCCESS);
result = isc_socket_getsockname(sock, &local);
assert_int_equal(result, ISC_R_SUCCESS);
- first = true;
region.base = rbuf;
region.length = sizeof(rbuf);
result = isc_socket_recv(sock, ®ion, 1, task, nameserver, sock);
result = isc_app_run();
assert_int_equal(result, ISC_R_SUCCESS);
- assert_int_equal(responses, 2);
+ assert_int_equal(isc_refcount_current(&responses), 2);
/*
* Shutdown nameserver.