sender: Deplete ACLs on exit.
[paraslash.git] / sched.c
diff --git a/sched.c b/sched.c
index 13993b13be128e261e989cb3963cfc2e73a693b4..4fc65b4b368627c9175f26a193199adcbd787c55 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -1,13 +1,8 @@
-/*
- * Copyright (C) 2006-2014 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file sched.c Paraslash's scheduling functions. */
 
 #include <regex.h>
-#include <assert.h>
 
 #include "para.h"
 #include "ipc.h"
@@ -49,13 +44,7 @@ struct task {
 };
 
 static struct timeval now_struct;
-struct timeval *now = &now_struct;
-
-static inline bool timeout_is_zero(struct sched *s)
-{
-       struct timeval *tv = &s->select_timeout;
-       return tv->tv_sec == 0 && tv->tv_usec == 0;
-}
+const struct timeval *now = &now_struct;
 
 static void sched_preselect(struct sched *s)
 {
@@ -67,13 +56,16 @@ static void sched_preselect(struct sched *s)
                if (t->notification != 0)
                        sched_min_delay(s);
                if (t->info.pre_select)
-                       t->info.pre_select(s, t);
+                       t->info.pre_select(s, t->info.context);
        }
 }
 
 static void unlink_and_free_task(struct task *t)
 {
-       PARA_INFO_LOG("freeing task %s\n", t->name);
+       PARA_INFO_LOG("freeing task %s (%s)\n", t->name, t->status < 0?
+               para_strerror(-t->status) :
+               (t->status == TS_DEAD? "[dead]" : "[running]"));
+
        list_del(&t->node);
        free(t->name);
        free(t);
@@ -85,13 +77,13 @@ static inline void call_post_select(struct sched *s, struct task *t)
        int ret;
 
 #ifndef SCHED_DEBUG
-       ret = t->info.post_select(s, t);
+       ret = t->info.post_select(s, t->info.context);
 #else
        struct timeval t1, t2, diff;
        unsigned long pst;
 
        clock_get_realtime(&t1);
-       ret = t->info.post_select(s, t);
+       ret = t->info.post_select(s, t->info.context);
        clock_get_realtime(&t2);
        tv_diff(&t1, &t2, &diff);
        pst = tv2ms(&diff);
@@ -133,7 +125,7 @@ static unsigned sched_post_select(struct sched *s)
  * \return Zero if no more tasks are left in the task list, negative if the
  * select function returned an error.
  *
- * \sa \ref task, \ref now.
+ * \sa \ref now.
  */
 int schedule(struct sched *s)
 {
@@ -147,7 +139,7 @@ again:
        FD_ZERO(&s->wfds);
        s->select_timeout = s->default_timeout;
        s->max_fileno = -1;
-       clock_get_realtime(now);
+       clock_get_realtime(&now_struct);
        sched_preselect(s);
        ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds,
                &s->select_timeout);
@@ -163,7 +155,7 @@ again:
                FD_ZERO(&s->rfds);
                FD_ZERO(&s->wfds);
        }
-       clock_get_realtime(now);
+       clock_get_realtime(&now_struct);
        num_running_tasks = sched_post_select(s);
        if (num_running_tasks == 0)
                return 0;
@@ -262,19 +254,6 @@ struct task *task_register(struct task_info *info, struct sched *s)
        return t;
 }
 
-/**
- * Obtain the context pointer of a task.
- *
- * \param t Return this task's context pointer.
- *
- * \return A pointer to the memory location specified previously as \a
- * task_info->context when the task was registered with \ref task_register().
- */
-void *task_context(struct task *t)
-{
-       return t->info.context;
-}
-
 /**
  * Get the list of all registered tasks.
  *
@@ -404,7 +383,7 @@ void sched_min_delay(struct sched *s)
  * function does nothing. Otherwise the timeout for the next select() call is
  * set to the given value.
  *
- * \sa sched_request_timeout_ms().
+ * \sa \ref sched_request_timeout_ms().
  */
 void sched_request_timeout(struct timeval *to, struct sched *s)
 {
@@ -437,7 +416,7 @@ void sched_request_timeout_ms(long unsigned ms, struct sched *s)
  * \return If \a barrier is in the past, this function does nothing and returns
  * zero. Otherwise it returns one.
  *
- * \sa sched_request_barrier_or_min_delay().
+ * \sa \ref sched_request_barrier_or_min_delay().
  */
 int sched_request_barrier(struct timeval *barrier, struct sched *s)
 {
@@ -458,7 +437,7 @@ int sched_request_barrier(struct timeval *barrier, struct sched *s)
  * \return If \a barrier is in the past, this function requests a minimal
  * timeout and returns zero. Otherwise it returns one.
  *
- * \sa sched_min_delay(), sched_request_barrier().
+ * \sa \ref sched_min_delay(), \ref sched_request_barrier().
  */
 int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s)
 {