40 #include <ldns/ldns.h>
42 static const char* schedule_str =
"scheduler";
59 ods_log_error(
"[%s] unable to create schedule: allocator_alloc() "
60 "failed", schedule_str);
67 if (!schedule->
tasks) {
68 ods_log_error(
"[%s] unable to create schedule: ldns_rbtree_create() "
69 "failed", schedule_str);
85 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
89 if (!schedule || !schedule->
tasks) {
92 node = ldns_rbtree_first(schedule->
tasks);
93 while (node && node != LDNS_RBTREE_NULL) {
98 task->
what =
override;
100 node = ldns_rbtree_next(node);
110 static ldns_rbnode_t*
113 ldns_rbnode_t* node = (ldns_rbnode_t*) malloc(
sizeof(ldns_rbnode_t));
129 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
131 if (!schedule || !task) {
135 node = ldns_rbtree_search(schedule->
tasks, task);
136 if (node && node != LDNS_RBTREE_NULL) {
150 ldns_rbnode_t* new_node = NULL;
151 ldns_rbnode_t* ins_node = NULL;
152 if (!task || !schedule || !schedule->
tasks) {
155 ods_log_debug(
"[%s] schedule task %s for zone %s", schedule_str,
158 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
163 new_node = task2node(task);
165 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
170 ins_node = ldns_rbtree_insert(schedule->
tasks, new_node);
172 ods_log_error(
"[%s] unable to schedule task %s for zone %s: "
175 free((
void*)new_node);
195 ldns_rbnode_t* del_node = LDNS_RBTREE_NULL;
197 if (!task || !schedule || !schedule->
tasks) {
202 del_node = ldns_rbtree_delete(schedule->
tasks, (
const void*) task);
205 free((
void*)del_node);
212 if (del_task->
flush) {
229 if (!task || !schedule || !schedule->
tasks) {
236 del_task->
what = what;
237 del_task->
when = when;
249 ldns_rbnode_t* first_node = LDNS_RBTREE_NULL;
250 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
252 if (!schedule || !schedule->
tasks) {
255 first_node = ldns_rbtree_first(schedule->
tasks);
262 while (node && node != LDNS_RBTREE_NULL) {
267 node = ldns_rbtree_next(node);
271 "find flush-task, while there should be %i flush-tasks left",
273 ods_log_info(
"[%s] reset flush count to 0", schedule_str);
291 if (!schedule || !schedule->
tasks) {
296 if (pop && (pop->
flush || pop->
when <= now)) {
317 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
320 if (!out || !schedule || !schedule->
tasks) {
323 node = ldns_rbtree_first(schedule->
tasks);
324 while (node && node != LDNS_RBTREE_NULL) {
327 node = ldns_rbtree_next(node);
339 task_delfunc(ldns_rbnode_t* elem)
343 if (elem && elem != LDNS_RBTREE_NULL) {
345 task_delfunc(elem->left);
346 task_delfunc(elem->right);
368 if (schedule->
tasks) {
369 task_delfunc(schedule->
tasks->root);
370 ldns_rbtree_free(schedule->
tasks);
371 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)