diff mbox

[v10,4/7] hw/ptimer: Support "on the fly" timer mode switch

Message ID f515e61fa162411d0a75c3d0583780531fe8cc6e.1452359845.git.digetx@gmail.com
State New
Headers show

Commit Message

Dmitry Osipenko Jan. 9, 2016, 5:39 p.m. UTC
Allow to switch between periodic <-> oneshot modes while timer is running.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 hw/core/ptimer.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Peter Crosthwaite Jan. 10, 2016, 12:50 a.m. UTC | #1
On Sat, Jan 9, 2016 at 9:39 AM, Dmitry Osipenko <digetx@gmail.com> wrote:
> Allow to switch between periodic <-> oneshot modes while timer is running.
>

"Allow switching"

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  hw/core/ptimer.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
> index 0a54212..6960738 100644
> --- a/hw/core/ptimer.c
> +++ b/hw/core/ptimer.c
> @@ -167,16 +167,16 @@ void ptimer_set_count(ptimer_state *s, uint64_t count)
>
>  void ptimer_run(ptimer_state *s, int oneshot)
>  {
> -    if (s->enabled) {
> -        return;
> -    }
> -    if (s->period == 0) {
> +    int was_disabled = !s->enabled;

bool

blank line here.

Otherwise:

Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>

Regards,
Peter

> +    if (was_disabled && s->period == 0) {
>          fprintf(stderr, "Timer with period zero, disabling\n");
>          return;
>      }
>      s->enabled = oneshot ? 2 : 1;
> -    s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> -    ptimer_reload(s);
> +    if (was_disabled) {
> +        s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> +        ptimer_reload(s);
> +    }
>  }
>
>  /* Pause a timer.  Note that this may cause it to "lose" time, even if it
> --
> 2.6.4
>
diff mbox

Patch

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 0a54212..6960738 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -167,16 +167,16 @@  void ptimer_set_count(ptimer_state *s, uint64_t count)
 
 void ptimer_run(ptimer_state *s, int oneshot)
 {
-    if (s->enabled) {
-        return;
-    }
-    if (s->period == 0) {
+    int was_disabled = !s->enabled;
+    if (was_disabled && s->period == 0) {
         fprintf(stderr, "Timer with period zero, disabling\n");
         return;
     }
     s->enabled = oneshot ? 2 : 1;
-    s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
-    ptimer_reload(s);
+    if (was_disabled) {
+        s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+        ptimer_reload(s);
+    }
 }
 
 /* Pause a timer.  Note that this may cause it to "lose" time, even if it