38 #include <ldns/ldns.h>
40 static const char* schedule_str =
"scheduler";
57 ods_log_error(
"[%s] unable to create schedule: allocator_alloc() "
58 "failed", schedule_str);
65 if (!schedule->
tasks) {
66 ods_log_error(
"[%s] unable to create schedule: ldns_rbtree_create() "
67 "failed", schedule_str);
83 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
87 if (!schedule || !schedule->
tasks) {
90 node = ldns_rbtree_first(schedule->
tasks);
91 while (node && node != LDNS_RBTREE_NULL) {
96 task->
what =
override;
98 node = ldns_rbtree_next(node);
108 static ldns_rbnode_t*
111 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
127 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
129 if (!schedule || !task) {
133 node = ldns_rbtree_search(schedule->
tasks, task);
134 if (node && node != LDNS_RBTREE_NULL) {
148 ldns_rbnode_t* new_node = NULL;
149 ldns_rbnode_t* ins_node = NULL;
150 if (!task || !schedule || !schedule->
tasks) {
153 ods_log_debug(
"[%s] schedule task %s for zone %s", schedule_str,
156 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
161 new_node = task2node(task);
163 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
168 ins_node = ldns_rbtree_insert(schedule->
tasks, new_node);
170 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
173 free((
void*)new_node);
193 ldns_rbnode_t* del_node = LDNS_RBTREE_NULL;
195 if (!task || !schedule || !schedule->
tasks) {
200 del_node = ldns_rbtree_delete(schedule->
tasks, (
const void*) task);
203 free((
void*)del_node);
210 if (del_task->
flush) {
227 if (!task || !schedule || !schedule->
tasks) {
234 del_task->
what = what;
235 del_task->
when = when;
247 ldns_rbnode_t* first_node = LDNS_RBTREE_NULL;
248 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
250 if (!schedule || !schedule->
tasks) {
253 first_node = ldns_rbtree_first(schedule->
tasks);
260 while (node && node != LDNS_RBTREE_NULL) {
265 node = ldns_rbtree_next(node);
269 "find flush-task, while there should be %i flush-tasks left",
271 ods_log_info(
"[%s] reset flush count to 0", schedule_str);
289 if (!schedule || !schedule->
tasks) {
294 if (pop && (pop->
flush || pop->
when <= now)) {
315 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
318 if (!out || !schedule || !schedule->
tasks) {
321 node = ldns_rbtree_first(schedule->
tasks);
322 while (node && node != LDNS_RBTREE_NULL) {
325 node = ldns_rbtree_next(node);
337 task_delfunc(ldns_rbnode_t* elem)
341 if (elem && elem != LDNS_RBTREE_NULL) {
343 task_delfunc(elem->left);
344 task_delfunc(elem->right);
366 if (schedule->
tasks) {
367 task_delfunc(schedule->
tasks->root);
368 ldns_rbtree_free(schedule->
tasks);
369 schedule->
tasks = NULL;
ods_status reschedule_task(schedule_type *schedule, task_type *task, task_id what, time_t when)
task_type * schedule_get_first_task(schedule_type *schedule)
void ods_log_debug(const char *format,...)
#define lock_basic_destroy(lock)
void * allocator_alloc(allocator_type *allocator, size_t size)
void task_log(task_type *task)
ods_status schedule_task(schedule_type *schedule, task_type *task, int log)
void ods_log_info(const char *format,...)
const char * task_who2str(task_type *task)
enum ods_enum_status ods_status
void schedule_flush(schedule_type *schedule, task_id override)
void ods_log_error(const char *format,...)
task_type * schedule_lookup_task(schedule_type *schedule, task_type *task)
enum task_id_enum task_id
void schedule_print(FILE *out, schedule_type *schedule)
task_type * schedule_pop_task(schedule_type *schedule)
void task_cleanup(task_type *task)
task_type * unschedule_task(schedule_type *schedule, task_type *task)
allocator_type * allocator
#define lock_basic_init(lock)
void allocator_deallocate(allocator_type *allocator, void *data)
void schedule_cleanup(schedule_type *schedule)
int task_compare(const void *a, const void *b)
lock_basic_type schedule_lock
void task_print(FILE *out, task_type *task)
#define ods_log_assert(x)
schedule_type * schedule_create(allocator_type *allocator)
void ods_log_warning(const char *format,...)
const char * task_what2str(task_id what)