input: add lock to mouse wheel packet
authormunkyu.im <munkyu.im@samsung.com>
Tue, 4 Dec 2012 07:51:18 +0000 (16:51 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Tue, 4 Dec 2012 07:51:18 +0000 (16:51 +0900)
to guarantee safe serialization of input event

Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
hw/ps2.c

index 93db328ff2367c31f661b0078e39b2a66e668d1e..4c7abdd7590a68c8d9cdeac9e2e04fc2c7832f42 100644 (file)
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -25,6 +25,7 @@
 #include "ps2.h"
 #include "console.h"
 #include "sysemu.h"
+#include "qemu-thread.h"
 
 /* debug PC keyboard */
 //#define DEBUG_KBD
@@ -132,6 +133,8 @@ static const unsigned char ps2_raw_keycode_set3[128] = {
  19,  25,  57,  81,  83,  92,  95,  98,  99, 100, 101, 103, 104, 106, 109, 110
 };
 
+static QemuMutex mutex;
+
 void ps2_queue(void *opaque, int b)
 {
     PS2State *s = (PS2State *)opaque;
@@ -379,7 +382,9 @@ static void ps2_mouse_event(void *opaque,
         for(;;) {
             /* if not remote, send event. Multiple events are sent if
                too big deltas */
+            qemu_mutex_lock(&mutex);
             ps2_mouse_send_packet(s);
+            qemu_mutex_unlock(&mutex);
             if (s->mouse_dx == 0 && s->mouse_dy == 0 && s->mouse_dz == 0)
                 break;
         }
@@ -676,5 +681,7 @@ void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg)
     vmstate_register(NULL, 0, &vmstate_ps2_mouse, s);
     qemu_add_mouse_event_handler(ps2_mouse_event, s, 0, "QEMU PS/2 Mouse");
     qemu_register_reset(ps2_mouse_reset, s);
+    qemu_mutex_init(&mutex);
+
     return s;
 }