writers: Unify ->pre_select().
authorAndre Noll <maan@systemlinux.org>
Fri, 5 Nov 2010 07:45:20 +0000 (08:45 +0100)
committerAndre Noll <maan@systemlinux.org>
Tue, 23 Nov 2010 16:43:08 +0000 (17:43 +0100)
Always treat the easy cases "nothing to do", "error", and "not yet initialized"
first. For the alsa writer,  this change fixes two minor bugs:

First, if data is available but alsa has not yet been initialized, we return
from ->pre_select() without setting a delay. This is wrong, we should init
the alsa handle ASAP in this case.

Second,  on errors we wait 20ms which is both ugly and unnecessary.
Requesting a minimal delay is the right thing to do here as well.

alsa_write.c
file_write.c
oss_write.c
osx_write.c

index b685e4f..3428def 100644 (file)
@@ -154,15 +154,12 @@ static void alsa_write_pre_select(struct sched *s, struct task *t)
        struct private_alsa_write_data *pad = wn->private_data;
        struct timeval tv;
        snd_pcm_sframes_t avail, underrun;
        struct private_alsa_write_data *pad = wn->private_data;
        struct timeval tv;
        snd_pcm_sframes_t avail, underrun;
-       int ret;
+       int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
 
-       if (!pad->handle)
-               return;
-       ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
-       if (ret < 0)
-               sched_request_timeout_ms(20, s);
-       if (ret <= 0)
+       if (ret == 0)
                return;
                return;
+       if (ret < 0 || !pad->handle)
+               return sched_min_delay(s);
        /*
         * 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.
index 7bc1e43..e6a3229 100644 (file)
@@ -88,14 +88,13 @@ static void file_write_pre_select(struct sched *s, struct task *t)
 {
        struct writer_node *wn = container_of(t, struct writer_node, task);
        struct private_file_write_data *pfwd = wn->private_data;
 {
        struct writer_node *wn = container_of(t, struct writer_node, task);
        struct private_file_write_data *pfwd = wn->private_data;
-       int ret;
+       int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
 
-       t->error = 0;
-       ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
-       if (ret > 0 && pfwd->fd >= 0)
-               para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
-       else if (ret != 0) /* error or bos and fd not yet open */
-               sched_min_delay(s);
+       if (ret == 0)
+               return;
+       if (ret < 0 || pfwd->fd < 0)
+               return sched_min_delay(s);
+       para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
 }
 
 static void file_write_close(struct writer_node *wn)
 }
 
 static void file_write_close(struct writer_node *wn)
index 2d820d3..687275f 100644 (file)
@@ -52,11 +52,11 @@ static void oss_pre_select(struct sched *s, struct task *t)
        struct private_oss_write_data *powd = wn->private_data;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
        struct private_oss_write_data *powd = wn->private_data;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
-       t->error = 0;
-       if (ret < 0)
-               sched_min_delay(s);
-       else if (ret > 0)
-               para_fd_set(powd->fd, &s->wfds, &s->max_fileno);
+       if (ret == 0)
+               return;
+       if (ret < 0 || powd->fd < 0)
+               return sched_min_delay(s);
+       para_fd_set(powd->fd, &s->wfds, &s->max_fileno);
 }
 
 static void oss_close(struct writer_node *wn)
 }
 
 static void oss_close(struct writer_node *wn)
index c2b7b2f..551748a 100644 (file)
@@ -347,13 +347,15 @@ static void osx_write_pre_select(struct sched *s, struct task *t)
        struct private_osx_write_data *powd = wn->private_data;
        struct timeval tmp = {.tv_sec = 1, .tv_usec = 0}, delay = tmp;
        unsigned long divisor;
        struct private_osx_write_data *powd = wn->private_data;
        struct timeval tmp = {.tv_sec = 1, .tv_usec = 0}, delay = tmp;
        unsigned long divisor;
-       size_t numbytes = powd->to->remaining * sizeof(short);
+       size_t numbytes;
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
        int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
 
-       if (ret < 0)
-               sched_min_delay(s);
-       if (ret <= 0 || numbytes < wn->min_iqs)
+       if (ret == 0)
                return;
                return;
+       if (ret < 0 || !powd->audio_unit)
+               return sched_min_delay(s);
+       numbytes = powd->to->remaining * sizeof(short);
+       assert(numbytes > 0);
        divisor = powd->sample_rate * wn->min_iqs / numbytes;
        if (divisor)
                tv_divide(divisor, &tmp, &delay);
        divisor = powd->sample_rate * wn->min_iqs / numbytes;
        if (divisor)
                tv_divide(divisor, &tmp, &delay);