#include <isc/print.h>
#include <isc/string.h>
#include <isc/random.h>
+#include <isc/refcount.h>
#include <isc/task.h>
#include <isc/thread.h>
#include <isc/time.h>
isc_task_t common;
isc__taskmgr_t * manager;
isc_mutex_t lock;
+ isc_refcount_t references;
/* Locked by task lock. */
task_state_t state;
- unsigned int references;
isc_eventlist_t events;
isc_eventlist_t on_shutdown;
unsigned int nevents;
REQUIRE(EMPTY(task->events));
REQUIRE(task->nevents == 0);
REQUIRE(EMPTY(task->on_shutdown));
- REQUIRE(task->references == 0);
+ REQUIRE(isc_refcount_current(&task->references) == 0);
REQUIRE(task->state == task_state_done);
XTRACE("task_finished");
isc_mutex_init(&task->lock);
task->state = task_state_idle;
- task->references = 1;
+ isc_refcount_init(&task->references, 1);
INIT_LIST(task->events);
INIT_LIST(task->on_shutdown);
task->nevents = 0;
XTTRACE(source, "isc_task_attach");
- LOCK(&source->lock);
- source->references++;
- UNLOCK(&source->lock);
+ isc_refcount_increment(&source->references);
*targetp = (isc_task_t *)source;
}
* Caller must be holding the task lock.
*/
- REQUIRE(task->references > 0);
+ REQUIRE(isc_refcount_current(&task->references) > 0);
XTRACE("detach");
- task->references--;
- if (task->references == 0 && task->state == task_state_idle) {
+ if (isc_refcount_decrement(&task->references) == 1 &&
+ task->state == task_state_idle) {
INSIST(EMPTY(task->events));
/*
* There are no references to this task, and no
dispatch_count++;
}
- if (task->references == 0 &&
+ if (isc_refcount_current(&task->references) == 0 &&
EMPTY(task->events) &&
!TASK_SHUTTINGDOWN(task)) {
bool was_idle;
* right now.
*/
XTRACE("empty");
- if (task->references == 0 &&
+ if (isc_refcount_current(&task->references) == 0 &&
TASK_SHUTTINGDOWN(task)) {
/*
* The task is done.
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
- task->references));
+ isc_refcount_current(&task->references)));
TRY0(xmlTextWriterEndElement(writer)); /* references */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
json_object_object_add(taskobj, "name", obj);
}
- obj = json_object_new_int(task->references);
+ obj = json_object_new_int(isc_refcount_current(&task->references));
CHECKMEM(obj);
json_object_object_add(taskobj, "references", obj);