ALSA: sound, core, pcm_lib: fix xrun_log
[linux-2.6.git] / sound / core / hrtimer.c
index 34c7d48..b8b31c4 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/hrtimer.h>
@@ -37,14 +38,23 @@ static unsigned int resolution;
 struct snd_hrtimer {
        struct snd_timer *timer;
        struct hrtimer hrt;
+       atomic_t running;
 };
 
 static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
 {
        struct snd_hrtimer *stime = container_of(hrt, struct snd_hrtimer, hrt);
        struct snd_timer *t = stime->timer;
-       hrtimer_forward_now(hrt, ns_to_ktime(t->sticks * resolution));
-       snd_timer_interrupt(stime->timer, t->sticks);
+       unsigned long oruns;
+
+       if (!atomic_read(&stime->running))
+               return HRTIMER_NORESTART;
+
+       oruns = hrtimer_forward_now(hrt, ns_to_ktime(t->sticks * resolution));
+       snd_timer_interrupt(stime->timer, t->sticks * oruns);
+
+       if (!atomic_read(&stime->running))
+               return HRTIMER_NORESTART;
        return HRTIMER_RESTART;
 }
 
@@ -58,6 +68,7 @@ static int snd_hrtimer_open(struct snd_timer *t)
        hrtimer_init(&stime->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        stime->timer = t;
        stime->hrt.function = snd_hrtimer_callback;
+       atomic_set(&stime->running, 0);
        t->private_data = stime;
        return 0;
 }
@@ -78,21 +89,23 @@ static int snd_hrtimer_start(struct snd_timer *t)
 {
        struct snd_hrtimer *stime = t->private_data;
 
+       atomic_set(&stime->running, 0);
+       hrtimer_cancel(&stime->hrt);
        hrtimer_start(&stime->hrt, ns_to_ktime(t->sticks * resolution),
                      HRTIMER_MODE_REL);
+       atomic_set(&stime->running, 1);
        return 0;
 }
 
 static int snd_hrtimer_stop(struct snd_timer *t)
 {
        struct snd_hrtimer *stime = t->private_data;
-
-       hrtimer_cancel(&stime->hrt);
+       atomic_set(&stime->running, 0);
        return 0;
 }
 
 static struct snd_timer_hardware hrtimer_hw = {
-       .flags =        SNDRV_TIMER_HW_AUTO,
+       .flags =        SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_TASKLET,
        .open =         snd_hrtimer_open,
        .close =        snd_hrtimer_close,
        .start =        snd_hrtimer_start,