Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * event notifier support |
| 3 | * |
| 4 | * Copyright Red Hat, Inc. 2010 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Michael S. Tsirkin <mst@redhat.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
Peter Maydell | aafd758 | 2016-01-29 17:49:55 +0000 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 14 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 15 | #include "qemu/event_notifier.h" |
| 16 | #include "qemu/main-loop.h" |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 17 | |
| 18 | int event_notifier_init(EventNotifier *e, int active) |
| 19 | { |
Jan Kiszka | e9bff10 | 2012-11-22 20:56:11 +0100 | [diff] [blame] | 20 | e->event = CreateEvent(NULL, TRUE, FALSE, NULL); |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 21 | assert(e->event); |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | void event_notifier_cleanup(EventNotifier *e) |
| 26 | { |
| 27 | CloseHandle(e->event); |
Halil Pasic | aa26292 | 2017-03-02 19:13:08 +0100 | [diff] [blame] | 28 | e->event = NULL; |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | HANDLE event_notifier_get_handle(EventNotifier *e) |
| 32 | { |
| 33 | return e->event; |
| 34 | } |
| 35 | |
Paolo Bonzini | fc97a65 | 2010-05-24 17:26:13 +0200 | [diff] [blame] | 36 | int event_notifier_set(EventNotifier *e) |
| 37 | { |
| 38 | SetEvent(e->event); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | int event_notifier_test_and_clear(EventNotifier *e) |
| 43 | { |
| 44 | int ret = WaitForSingleObject(e->event, 0); |
| 45 | if (ret == WAIT_OBJECT_0) { |
| 46 | ResetEvent(e->event); |
| 47 | return true; |
| 48 | } |
| 49 | return false; |
| 50 | } |