Commit f47bb8d1 authored by Bob Halley's avatar Bob Halley

many name conversions

parent 8b935d4a
......@@ -13,7 +13,7 @@
mem_context_t mctx = NULL;
static boolean_t
static isc_boolean_t
my_callback(task_t task, task_event_t event)
{
int i, j;
......@@ -24,24 +24,24 @@ my_callback(task_t task, task_event_t event)
j += 100;
printf("task %s: %d\n", name, j);
return (FALSE);
return (ISC_FALSE);
}
static boolean_t
static isc_boolean_t
my_shutdown(task_t task, task_event_t event) {
char *name = event->arg;
printf("shutdown %s\n", name);
return (TRUE);
return (ISC_TRUE);
}
static boolean_t
static isc_boolean_t
my_tick(task_t task, task_event_t event)
{
char *name = event->arg;
printf("task %p tick %s\n", task, name);
return (FALSE);
return (ISC_FALSE);
}
void
......
......@@ -16,15 +16,15 @@ task_t t1, t2, t3;
timer_t ti1, ti2, ti3;
int tick_count = 0;
static boolean_t
static isc_boolean_t
shutdown_task(task_t task, task_event_t event) {
char *name = event->arg;
printf("shutdown %s\n", name);
return (TRUE);
return (ISC_TRUE);
}
static boolean_t
static isc_boolean_t
tick(task_t task, task_event_t event)
{
char *name = event->arg;
......@@ -48,14 +48,14 @@ tick(task_t task, task_event_t event)
interval.nanoseconds = 0;
printf("*** resetting ti3 ***\n");
INSIST(timer_reset(ti3, timer_type_once, expires, interval,
TRUE)
ISC_TRUE)
== ISC_R_SUCCESS);
}
return (FALSE);
return (ISC_FALSE);
}
static boolean_t
static isc_boolean_t
timeout(task_t task, task_event_t event)
{
char *name = event->arg;
......@@ -72,9 +72,9 @@ timeout(task_t task, task_event_t event)
if (strcmp(name, "3") == 0) {
printf("*** saving task 3 ***\n");
return (FALSE);
return (ISC_FALSE);
}
return (TRUE);
return (ISC_TRUE);
}
void
......
......@@ -28,7 +28,6 @@
#include <stdlib.h>
#include <isc/assertions.h>
#include <isc/boolean.h>
#include <isc/heap.h>
/*
......@@ -45,26 +44,26 @@
#define VALID_HEAP(h) ((h) != NULL && \
(h)->magic == HEAP_MAGIC)
struct heap_context {
struct isc_heap {
unsigned int magic;
mem_context_t mctx;
unsigned int size;
unsigned int size_increment;
unsigned int last;
void **array;
heap_higher_priority_func higher_priority;
heap_index_func index;
isc_heapcompare_t compare;
isc_heapindex_t index;
};
isc_result
heap_create(mem_context_t mctx, heap_higher_priority_func higher_priority,
heap_index_func index, unsigned int size_increment,
heap_t *heapp)
isc_heap_create(mem_context_t mctx, isc_heapcompare_t compare,
isc_heapindex_t index, unsigned int size_increment,
isc_heap_t *heapp)
{
heap_t heap;
isc_heap_t heap;
REQUIRE(heapp != NULL && *heapp == NULL);
REQUIRE(higher_priority != NULL);
REQUIRE(compare != NULL);
heap = mem_get(mctx, sizeof *heap);
if (heap == NULL)
......@@ -78,7 +77,7 @@ heap_create(mem_context_t mctx, heap_higher_priority_func higher_priority,
heap->size_increment = size_increment;
heap->last = 0;
heap->array = NULL;
heap->higher_priority = higher_priority;
heap->compare = compare;
heap->index = index;
*heapp = heap;
......@@ -87,8 +86,8 @@ heap_create(mem_context_t mctx, heap_higher_priority_func higher_priority,
}
void
heap_destroy(heap_t *heapp) {
heap_t heap;
isc_heap_destroy(isc_heap_t *heapp) {
isc_heap_t heap;
REQUIRE(heapp != NULL);
heap = *heapp;
......@@ -103,8 +102,8 @@ heap_destroy(heap_t *heapp) {
*heapp = NULL;
}
static boolean_t
resize(heap_t heap) {
static isc_boolean_t
resize(isc_heap_t heap) {
void **new_array;
size_t new_size;
......@@ -113,7 +112,7 @@ resize(heap_t heap) {
new_size = heap->size + heap->size_increment;
new_array = mem_get(heap->mctx, new_size * sizeof (void *));
if (new_array == NULL)
return (FALSE);
return (ISC_FALSE);
if (heap->array != NULL) {
memcpy(new_array, heap->array, heap->size);
mem_put(heap->mctx, heap->array,
......@@ -122,15 +121,15 @@ resize(heap_t heap) {
heap->size = new_size;
heap->array = new_array;
return (TRUE);
return (ISC_TRUE);
}
static void
float_up(heap_t heap, unsigned int i, void *elt) {
float_up(isc_heap_t heap, unsigned int i, void *elt) {
unsigned int p;
for ( p = heap_parent(i);
i > 1 && heap->higher_priority(elt, heap->array[p]);
i > 1 && heap->compare(elt, heap->array[p]);
i = p, p = heap_parent(i) ) {
heap->array[i] = heap->array[p];
if (heap->index != NULL)
......@@ -142,7 +141,7 @@ float_up(heap_t heap, unsigned int i, void *elt) {
}
static void
sink_down(heap_t heap, unsigned int i, void *elt) {
sink_down(isc_heap_t heap, unsigned int i, void *elt) {
unsigned int j, size, half_size;
size = heap->last;
......@@ -150,10 +149,10 @@ sink_down(heap_t heap, unsigned int i, void *elt) {
while (i <= half_size) {
/* find smallest of the (at most) two children */
j = heap_left(i);
if (j < size && heap->higher_priority(heap->array[j+1],
if (j < size && heap->compare(heap->array[j+1],
heap->array[j]))
j++;
if (heap->higher_priority(elt, heap->array[j]))
if (heap->compare(elt, heap->array[j]))
break;
heap->array[i] = heap->array[j];
if (heap->index != NULL)
......@@ -166,7 +165,7 @@ sink_down(heap_t heap, unsigned int i, void *elt) {
}
isc_result
heap_insert(heap_t heap, void *elt) {
isc_heap_insert(isc_heap_t heap, void *elt) {
unsigned int i;
REQUIRE(VALID_HEAP(heap));
......@@ -181,7 +180,7 @@ heap_insert(heap_t heap, void *elt) {
}
void
heap_delete(heap_t heap, unsigned int i) {
isc_heap_delete(isc_heap_t heap, unsigned int i) {
void *elt;
REQUIRE(VALID_HEAP(heap));
......@@ -193,7 +192,7 @@ heap_delete(heap_t heap, unsigned int i) {
}
void
heap_increased(heap_t heap, unsigned int i) {
isc_heap_increased(isc_heap_t heap, unsigned int i) {
REQUIRE(VALID_HEAP(heap));
REQUIRE(i >= 1 && i <= heap->last);
......@@ -201,7 +200,7 @@ heap_increased(heap_t heap, unsigned int i) {
}
void
heap_decreased(heap_t heap, unsigned int i) {
isc_heap_decreased(isc_heap_t heap, unsigned int i) {
REQUIRE(VALID_HEAP(heap));
REQUIRE(i >= 1 && i <= heap->last);
......@@ -209,7 +208,7 @@ heap_decreased(heap_t heap, unsigned int i) {
}
void *
heap_element(heap_t heap, unsigned int i) {
isc_heap_element(isc_heap_t heap, unsigned int i) {
REQUIRE(VALID_HEAP(heap));
REQUIRE(i >= 1 && i <= heap->last);
......@@ -217,7 +216,7 @@ heap_element(heap_t heap, unsigned int i) {
}
void
heap_for_each(heap_t heap, heap_for_each_func action, void *uap) {
isc_heap_foreach(isc_heap_t heap, isc_heapaction_t action, void *uap) {
unsigned int i;
REQUIRE(VALID_HEAP(heap));
......
#ifndef BOOLEAN_H
#define BOOLEAN_H 1
#ifndef ISC_BOOLEAN_H
#define ISC_BOOLEAN_H 1
#ifndef SOLARIS
typedef enum { isc_boolean_false = 0, isc_boolean_true = 1 } isc_boolean_t;
#ifndef TRUE
#define TRUE 1
#endif
#define ISC_FALSE isc_boolean_false
#define ISC_TRUE isc_boolean_true
#ifndef FALSE
#define FALSE 0
#endif
typedef enum { false=FALSE, true=TRUE } boolean_t;
#else
#define true B_TRUE
#define false B_FALSE
#endif
#endif /* BOOLEAN_H */
#endif /* ISC_BOOLEAN_H */
......@@ -19,7 +19,7 @@
#define EVENT_CLASS_TASK EVENT_CLASS(0)
#define EVENT_CLASS_TIMER EVENT_CLASS(1)
#define EVENT_CLASS_NET EVENT_CLASS(2)
#define EVENT_CLASS_SOCKET EVENT_CLASS(2)
#define EVENT_CLASS_FILE EVENT_CLASS(3)
/*
......
......@@ -19,27 +19,32 @@
#include <isc/boolean.h>
#include <isc/memcluster.h>
typedef boolean_t (*heap_higher_priority_func)(void *, void *);
typedef void (*heap_index_func)(void *, unsigned int);
typedef void (*heap_for_each_func)(void *, void *);
/*
* The comparision function returns ISC_TRUE if the first argument has
* higher priority than the second argument, and ISC_FALSE otherwise.
*/
typedef isc_boolean_t (*isc_heapcompare_t)(void *, void *);
typedef void (*isc_heapindex_t)(void *, unsigned int);
typedef void (*isc_heapaction_t)(void *, void *);
typedef struct heap_context *heap_t;
typedef struct isc_heap *isc_heap_t;
#define heap_create __heap_create
#define heap_destroy __heap_destroy
#define heap_insert __heap_insert
#define heap_delete __heap_delete
#define heap_increased __heap_increased
#define heap_decreased __heap_decreased
#define heap_element __heap_element
#define heap_for_each __heap_for_each
#define isc_heap_create __isc_heap_create
#define isc_heap_destroy __isc_heap_destroy
#define isc_heap_insert __isc_heap_insert
#define isc_heap_delete __isc_heap_delete
#define isc_heap_increased __isc_heap_increased
#define isc_heap_decreased __isc_heap_decreased
#define isc_heap_element __isc_heap_element
#define isc_heap_foreach __isc_heap_foreach
isc_result heap_create(mem_context_t, heap_higher_priority_func,
heap_index_func, unsigned int, heap_t *);
void heap_destroy(heap_t *);
isc_result heap_insert(heap_t, void *);
void heap_delete(heap_t, unsigned int);
void heap_increased(heap_t, unsigned int);
void heap_decreased(heap_t, unsigned int);
void * heap_element(heap_t, unsigned int);
void heap_for_each(heap_t, heap_for_each_func, void *);
isc_result isc_heap_create(mem_context_t, isc_heapcompare_t,
isc_heapindex_t, unsigned int, isc_heap_t *);
void isc_heap_destroy(isc_heap_t *);
isc_result isc_heap_insert(isc_heap_t, void *);
void isc_heap_delete(isc_heap_t, unsigned int);
void isc_heap_increased(isc_heap_t, unsigned int);
void isc_heap_decreased(isc_heap_t, unsigned int);
void * isc_heap_element(isc_heap_t, unsigned int);
void isc_heap_foreach(isc_heap_t, isc_heapaction_t, void *);
......@@ -30,7 +30,7 @@ typedef struct task_manager * task_manager_t;
*/
typedef int task_eventtype_t;
typedef boolean_t (*task_action_t)(task_t, task_event_t);
typedef isc_boolean_t (*task_action_t)(task_t, task_event_t);
/*
* This structure is public because "subclassing" it may be useful when
......@@ -64,14 +64,14 @@ void task_event_free(task_event_t *);
*** Tasks.
***/
boolean_t task_create(task_manager_t,
isc_boolean_t task_create(task_manager_t,
task_action_t,
void *,
unsigned int,
task_t *);
void task_attach(task_t, task_t *);
void task_detach(task_t *);
boolean_t task_send_event(task_t,
isc_boolean_t task_send_event(task_t,
task_event_t *);
void task_purge_events(task_t, void *,
task_eventtype_t);
......
......@@ -148,7 +148,7 @@ timer_reset(timer_t timer,
timer_type_t type,
os_time_t expires,
os_time_t interval,
boolean_t purge);
isc_boolean_t purge);
/*
* Change the timer's type, expires, and interval values to the given
* values. If 'purge' is TRUE, any pending events from this timer
......
......@@ -2,9 +2,9 @@
#include <isc/condition.h>
#include <errno.h>
boolean_t
isc_boolean_t
os_condition_waituntil(os_condition_t *c, os_mutex_t *m, os_time_t *t,
boolean_t *timeout)
isc_boolean_t *timeout)
{
int result;
struct timespec ts;
......@@ -13,11 +13,11 @@ os_condition_waituntil(os_condition_t *c, os_mutex_t *m, os_time_t *t,
ts.tv_nsec = t->nanoseconds;
result = pthread_cond_timedwait(c, m, &ts);
if (result == 0) {
*timeout = FALSE;
return (TRUE);
*timeout = ISC_FALSE;
return (ISC_TRUE);
} else if (result == ETIMEDOUT) {
*timeout = TRUE;
return (TRUE);
*timeout = ISC_TRUE;
return (ISC_TRUE);
}
return (FALSE);
return (ISC_FALSE);
}
......@@ -17,9 +17,9 @@ typedef pthread_cond_t os_condition_t;
#define os_condition_broadcast(cp) (pthread_cond_broadcast((cp)) == 0)
#define os_condition_destroy(cp) (pthread_cond_destroy((cp)) == 0)
boolean_t os_condition_waituntil(os_condition_t *,
isc_boolean_t os_condition_waituntil(os_condition_t *,
os_mutex_t *,
os_time_t *,
boolean_t *);
isc_boolean_t *);
#endif /* CONDITION_H */
......@@ -57,7 +57,7 @@ struct task {
unsigned int references;
task_eventlist_t events;
unsigned int quantum;
boolean_t enqueue_allowed;
isc_boolean_t enqueue_allowed;
task_event_t shutdown_event;
/* Locked by task manager lock. */
LINK(struct task) link;
......@@ -78,7 +78,7 @@ struct task_manager {
LIST(struct task) tasks;
LIST(struct task) ready_tasks;
os_condition_t work_available;
boolean_t exiting;
isc_boolean_t exiting;
unsigned int workers;
os_condition_t no_workers;
};
......@@ -167,7 +167,7 @@ task_free(task_t task) {
mem_put(manager->mctx, task, sizeof *task);
}
boolean_t
isc_boolean_t
task_create(task_manager_t manager, task_action_t shutdown_action,
void *shutdown_arg, unsigned int quantum, task_t *taskp)
{
......@@ -178,19 +178,19 @@ task_create(task_manager_t manager, task_action_t shutdown_action,
task = mem_get(manager->mctx, sizeof *task);
if (task == NULL)
return (FALSE);
return (ISC_FALSE);
task->magic = TASK_MAGIC;
task->manager = manager;
if (!os_mutex_init(&task->lock)) {
mem_put(manager->mctx, task, sizeof *task);
return (FALSE);
return (ISC_FALSE);
}
task->state = task_state_idle;
task->references = 1;
INIT_LIST(task->events);
task->quantum = quantum;
task->enqueue_allowed = TRUE;
task->enqueue_allowed = ISC_TRUE;
task->shutdown_event = event_allocate(manager->mctx,
NULL,
TASK_EVENT_SHUTDOWN,
......@@ -200,7 +200,7 @@ task_create(task_manager_t manager, task_action_t shutdown_action,
if (task->shutdown_event == NULL) {
(void)os_mutex_destroy(&task->lock);
mem_put(manager->mctx, task, sizeof *task);
return (FALSE);
return (ISC_FALSE);
}
INIT_LINK(task, link);
INIT_LINK(task, ready_link);
......@@ -213,7 +213,7 @@ task_create(task_manager_t manager, task_action_t shutdown_action,
*taskp = task;
return (TRUE);
return (ISC_TRUE);
}
void
......@@ -231,7 +231,7 @@ task_attach(task_t task, task_t *taskp) {
void
task_detach(task_t *taskp) {
boolean_t free_task = FALSE;
isc_boolean_t free_task = ISC_FALSE;
task_t task;
XTRACE("task_detach");
......@@ -244,7 +244,7 @@ task_detach(task_t *taskp) {
REQUIRE(task->references > 0);
task->references--;
if (task->state == task_state_shutdown && task->references == 0)
free_task = TRUE;
free_task = ISC_TRUE;
UNLOCK(&task->lock);
if (free_task)
......@@ -253,10 +253,10 @@ task_detach(task_t *taskp) {
*taskp = NULL;
}
boolean_t
isc_boolean_t
task_send_event(task_t task, task_event_t *eventp) {
boolean_t was_idle = FALSE;
boolean_t discard = FALSE;
isc_boolean_t was_idle = ISC_FALSE;
isc_boolean_t discard = ISC_FALSE;
task_event_t event;
REQUIRE(VALID_TASK(task));
......@@ -275,7 +275,7 @@ task_send_event(task_t task, task_event_t *eventp) {
LOCK(&task->lock);
if (task->enqueue_allowed) {
if (task->state == task_state_idle) {
was_idle = TRUE;
was_idle = ISC_TRUE;
INSIST(EMPTY(task->events));
task->state = task_state_ready;
}
......@@ -283,17 +283,17 @@ task_send_event(task_t task, task_event_t *eventp) {
task->state == task_state_running);
ENQUEUE(task->events, event, link);
} else
discard = TRUE;
discard = ISC_TRUE;
UNLOCK(&task->lock);
if (discard) {
task_event_free(&event);
*eventp = NULL;
return (TRUE);
return (ISC_TRUE);
}
if (was_idle) {
boolean_t need_wakeup = FALSE;
isc_boolean_t need_wakeup = ISC_FALSE;
task_manager_t manager;
/*
......@@ -319,7 +319,7 @@ task_send_event(task_t task, task_event_t *eventp) {
INSIST(VALID_MANAGER(manager));
LOCK(&manager->lock);
if (EMPTY(manager->ready_tasks))
need_wakeup = TRUE;
need_wakeup = ISC_TRUE;
ENQUEUE(manager->ready_tasks, task, ready_link);
UNLOCK(&manager->lock);
......@@ -335,7 +335,7 @@ task_send_event(task_t task, task_event_t *eventp) {
*eventp = NULL;
XTRACE("sent");
return (TRUE);
return (ISC_TRUE);
}
void
......@@ -377,8 +377,8 @@ task_purge_events(task_t task, void *sender, task_eventtype_t type) {
void
task_shutdown(task_t task) {
boolean_t was_idle = FALSE;
boolean_t discard = FALSE;
isc_boolean_t was_idle = ISC_FALSE;
isc_boolean_t discard = ISC_FALSE;
REQUIRE(VALID_TASK(task));
......@@ -389,7 +389,7 @@ task_shutdown(task_t task) {
LOCK(&task->lock);
if (task->enqueue_allowed) {
if (task->state == task_state_idle) {
was_idle = TRUE;
was_idle = ISC_TRUE;
INSIST(EMPTY(task->events));
task->state = task_state_ready;
}
......@@ -398,23 +398,23 @@ task_shutdown(task_t task) {
INSIST(task->shutdown_event != NULL);
ENQUEUE(task->events, task->shutdown_event, link);
task->shutdown_event = NULL;
task->enqueue_allowed = FALSE;
task->enqueue_allowed = ISC_FALSE;
} else
discard = TRUE;
discard = ISC_TRUE;
UNLOCK(&task->lock);
if (discard)
return;
if (was_idle) {
boolean_t need_wakeup = FALSE;
isc_boolean_t need_wakeup = ISC_FALSE;
task_manager_t manager;
manager = task->manager;
INSIST(VALID_MANAGER(manager));
LOCK(&manager->lock);
if (EMPTY(manager->ready_tasks))
need_wakeup = TRUE;
need_wakeup = ISC_TRUE;
ENQUEUE(manager->ready_tasks, task, ready_link);
UNLOCK(&manager->lock);
......@@ -442,7 +442,7 @@ static
void *task_manager_run(void *uap) {
task_manager_t manager = uap;
task_t task;
boolean_t no_workers = FALSE;
isc_boolean_t no_workers = ISC_FALSE;
XTRACE("start");
......@@ -517,14 +517,14 @@ void *task_manager_run(void *uap) {
task = HEAD(manager->ready_tasks);
if (task != NULL) {
unsigned int dispatch_count = 0;
boolean_t done = FALSE;