41 #include <ldns/ldns.h>
43 static const char* schedule_str =
"scheduler";
55 ods_log_error(
"[%s] unable to create: no allocator available",
64 ods_log_error(
"[%s] unable to create: allocator failed", schedule_str);
86 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
90 if (!schedule || !schedule->
tasks) {
96 node = ldns_rbtree_first(schedule->
tasks);
97 while (node && node != LDNS_RBTREE_NULL) {
102 task->
what =
override;
104 node = ldns_rbtree_next(node);
114 static ldns_rbnode_t*
117 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
131 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
134 if (!schedule || !task) {
141 node = ldns_rbtree_search(schedule->
tasks, task);
142 if (node && node != LDNS_RBTREE_NULL) {
156 ldns_rbnode_t* new_node = NULL;
157 ldns_rbnode_t* ins_node = NULL;
160 ods_log_error(
"[%s] unable to schedule task: no task", schedule_str);
172 ods_log_debug(
"[%s] schedule task %s for zone %s", schedule_str,
175 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
180 new_node = task2node(task);
181 ins_node = ldns_rbtree_insert(schedule->
tasks, new_node);
183 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
186 free((
void*)new_node);
206 ldns_rbnode_t* del_node = LDNS_RBTREE_NULL;
224 del_node = ldns_rbtree_delete(schedule->
tasks, (
const void*) task);
227 free((
void*)del_node);
234 if (del_task->
flush) {
260 del_task->
what = what;
261 del_task->
when = when;
273 ldns_rbnode_t* first_node = LDNS_RBTREE_NULL;
274 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
283 first_node = ldns_rbtree_first(schedule->
tasks);
291 while (node && node != LDNS_RBTREE_NULL) {
296 node = ldns_rbtree_next(node);
300 "find flush-task, while there should be %i flush-tasks left",
302 ods_log_info(
"[%s] reset flush count to 0", schedule_str);
322 ods_log_error(
"[%s] unable to pop task: no schedule", schedule_str);
330 if (pop && (pop->
flush || pop->
when <= now)) {
333 pop->
who?pop->
who:
"(null)");
336 pop->
who?pop->
who:
"(null)");
340 ods_log_debug(
"[%s] not popping task for zone %s: not ready (when %u "
341 "< now %u, flush=%u)", schedule_str, pop->
who?pop->
who:
"(null)",
344 ods_log_debug(
"[%s] not popping task: no task", schedule_str);
357 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
360 if (!out || !schedule || !schedule->
tasks) {
367 node = ldns_rbtree_first(schedule->
tasks);
368 while (node && node != LDNS_RBTREE_NULL) {
371 node = ldns_rbtree_next(node);
383 task_delfunc(ldns_rbnode_t* elem)
387 if (elem && elem != LDNS_RBTREE_NULL) {
389 task_delfunc(elem->left);
390 task_delfunc(elem->right);
412 if (schedule->
tasks) {
413 task_delfunc(schedule->
tasks->root);
414 ldns_rbtree_free(schedule->
tasks);
415 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,...)
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)
const char * task_what2str(int what)
allocator_type * allocator
const char * task_who2str(const char *who)
#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,...)