Author: tjansen Date: Tue Oct 13 14:30:17 2009 New Revision: 1106 Log: Pisacd now tests the scheduler with a dummy maintenance function. Fixes include: * minor API change: pisa_sched_add takes a pointer to struct timeval now, rather than a struct timeval * wrapper function for scheduling an action for immediate execution * a memleak fix: pthread_cancel stops execution, but does not free memory, we still need pthread_join * deadlock caused by not completely moving the task execution to the runlist in commit 1105 Modified: trunk/include/scheduler.h trunk/libpisa/scheduler.c trunk/pisacd/cdmain.c Modified: trunk/include/scheduler.h ============================================================================== --- trunk/include/scheduler.h Tue Oct 13 13:42:39 2009 (r1105) +++ trunk/include/scheduler.h Tue Oct 13 14:30:17 2009 (r1106) @@ -29,7 +29,14 @@ void pisa_sched_cleanup(void); void pisa_sched_run(void); -pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval delay, void *data); +pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval *delay, void *data); void pisa_sched_remove(pisa_sched_task *task); +static inline pisa_sched_task *pisa_sched_add_now(pisa_sched_func func, void *data) +{ + struct timeval delay; + timerclear(&delay); + return pisa_sched_add(func, &delay, data); +} + #endif /* PISA_SCHEDULER_H */ Modified: trunk/libpisa/scheduler.c ============================================================================== --- trunk/libpisa/scheduler.c Tue Oct 13 13:42:39 2009 (r1105) +++ trunk/libpisa/scheduler.c Tue Oct 13 14:30:17 2009 (r1106) @@ -118,6 +118,7 @@ void pisa_sched_cleanup(void) { pthread_cancel(thread); + pthread_join(thread, NULL); close(pipefd[0]); close(pipefd[1]); @@ -172,14 +173,13 @@ gettimeofday(&now, NULL); while (head && pisa_time_before(&head->due, &now)) { - head->func(head->data); - pisa_sched_remove_internal(head); if (run_tail == NULL) run = run_tail = head; else { run_tail->next = head; run_tail = head; } + pisa_sched_remove_internal(head); } pthread_mutex_unlock(&mutex_list); @@ -204,7 +204,7 @@ * @param delay delay until the function is run * @param data opaque payload */ -pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval delay, void *data) +pisa_sched_task *pisa_sched_add(pisa_sched_func func, struct timeval *delay, void *data) { pisa_sched_task *cur = head, *task = malloc(sizeof(pisa_sched_task)); struct timeval now; @@ -215,7 +215,7 @@ task->func = func; task->data = data; - timeradd(&now, &delay, &task->due); + timeradd(&now, delay, &task->due); if (head == NULL || pisa_time_before(&task->due, &head->due)) { task->next = head; Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Tue Oct 13 13:42:39 2009 (r1105) +++ trunk/pisacd/cdmain.c Tue Oct 13 14:30:17 2009 (r1106) @@ -141,6 +141,13 @@ pisa_pending_remove_by_entry(entry); } +static void pisa_maintenance_test(void *data) +{ + struct timeval delay = {3, 0}; + PISA_DEBUG(PL_GENERIC, "maintenance, next in 3 seconds.\n"); + pisa_sched_add(pisa_maintenance_test, &delay, NULL); +} + /** * Initialize the basic settings before starting the main loop. */ @@ -255,6 +262,7 @@ pisa_tunnel_configure_main(cd_ctx.ifname_tunnel, &cd_cfg.local_ipv4, &cd_cfg.local_netmask, MTU_TUN); pisa_sched_init(&cd_ctx.scheduler); + pisa_sched_add_now(pisa_maintenance_test, NULL); } static void cd_deinit(void)