sched: Improve sched_request_barrier() and friends.
authorAndre Noll <maan@systemlinux.org>
Wed, 13 Jul 2011 19:13:32 +0000 (21:13 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 7 Aug 2011 11:40:25 +0000 (13:40 +0200)
Make these functions tell its caller whether the given barrier
was in the past. This is useful for vss because for certain
barriers, no other actions should be performed before the barrier
has passed.

alsa_write.c
sched.c
sched.h

index 6850221a83d861e04cfcd8254d3114f837013a2e..34a71f9bd34b503fafdbb192d5479c1815846b49 100644 (file)
@@ -150,10 +150,14 @@ static void alsa_write_pre_select(struct sched *s, struct task *t)
 
        if (ret == 0)
                return;
 
        if (ret == 0)
                return;
-       if (!pad)
-               return sched_min_delay(s);
-       if (ret < 0)
-               return sched_request_barrier_or_min_delay(&pad->drain_barrier, s);
+       if (!pad) {
+               sched_min_delay(s);
+               return;
+       }
+       if (ret < 0) {
+               sched_request_barrier_or_min_delay(&pad->drain_barrier, s);
+               return;
+       }
        /*
         * Data is available to be written to the alsa handle.  Compute number
         * of milliseconds until next buffer underrun would occur.
        /*
         * Data is available to be written to the alsa handle.  Compute number
         * of milliseconds until next buffer underrun would occur.
diff --git a/sched.c b/sched.c
index 8baed4962d9e5dfbf2cad170b1c38d2d42b123b3..65176bd91a875ab16ce07194299dbc9bde5a00a5 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -302,17 +302,19 @@ void sched_request_timeout_ms(long unsigned ms, struct sched *s)
  * \param barrier Absolute time before select() should return.
  * \param s Pointer to the scheduler struct.
  *
  * \param barrier Absolute time before select() should return.
  * \param s Pointer to the scheduler struct.
  *
- * If \a barrier is in the past, this function does nothing.
+ * \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 sched_request_barrier_or_min_delay().
  */
-void sched_request_barrier(struct timeval *barrier, struct sched *s)
+int sched_request_barrier(struct timeval *barrier, struct sched *s)
 {
        struct timeval diff;
 
        if (tv_diff(now, barrier, &diff) > 0)
 {
        struct timeval diff;
 
        if (tv_diff(now, barrier, &diff) > 0)
-               return;
+               return 0;
        sched_request_timeout(&diff, s);
        sched_request_timeout(&diff, s);
+       return 1;
 }
 
 /**
 }
 
 /**
@@ -321,15 +323,19 @@ void sched_request_barrier(struct timeval *barrier, struct sched *s)
  * \param barrier Absolute time before select() should return.
  * \param s Pointer to the scheduler struct.
  *
  * \param barrier Absolute time before select() should return.
  * \param s Pointer to the scheduler struct.
  *
- * If \a barrier is in the past, this function requests a minimal timeout.
+ * 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 sched_min_delay(), sched_request_barrier().
  */
-void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s)
+int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s)
 {
        struct timeval diff;
 
 {
        struct timeval diff;
 
-       if (tv_diff(now, barrier, &diff) > 0)
-               return sched_min_delay(s);
+       if (tv_diff(now, barrier, &diff) > 0) {
+               sched_min_delay(s);
+               return 0;
+       }
        sched_request_timeout(&diff, s);
        sched_request_timeout(&diff, s);
+       return 1;
 }
 }
diff --git a/sched.h b/sched.h
index e018c2fe9d0c35d2431b96967f97eb69f8ea0238..ea9578f7b05b3bae17e69e87543675e902d0c590 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -81,5 +81,5 @@ void sched_shutdown(void);
 void sched_min_delay(struct sched *s);
 void sched_request_timeout(struct timeval *to, struct sched *s);
 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
 void sched_min_delay(struct sched *s);
 void sched_request_timeout(struct timeval *to, struct sched *s);
 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
-void sched_request_barrier(struct timeval *barrier, struct sched *s);
-void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);
+int sched_request_barrier(struct timeval *barrier, struct sched *s);
+int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);