Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Notifier lists |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2010 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 12 | * Contributions after 2012-01-13 are licensed under the terms of the |
| 13 | * GNU GPL, version 2 or (at your option) any later version. |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 14 | */ |
| 15 | |
Peter Maydell | aafd758 | 2016-01-29 17:49:55 +0000 | [diff] [blame] | 16 | #include "qemu/osdep.h" |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 17 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 18 | #include "qemu/notify.h" |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 19 | |
| 20 | void notifier_list_init(NotifierList *list) |
| 21 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 22 | QLIST_INIT(&list->notifiers); |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | void notifier_list_add(NotifierList *list, Notifier *notifier) |
| 26 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 27 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 28 | } |
| 29 | |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 30 | void notifier_remove(Notifier *notifier) |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 31 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 32 | QLIST_REMOVE(notifier, node); |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 33 | } |
| 34 | |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 35 | void notifier_list_notify(NotifierList *list, void *data) |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 36 | { |
| 37 | Notifier *notifier, *next; |
| 38 | |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 39 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 40 | notifier->notify(notifier, data); |
Anthony Liguori | d1e70c5 | 2010-03-09 13:16:14 -0600 | [diff] [blame] | 41 | } |
| 42 | } |
Stefan Hajnoczi | 5dae8e5 | 2013-06-24 17:13:09 +0200 | [diff] [blame] | 43 | |
| 44 | void notifier_with_return_list_init(NotifierWithReturnList *list) |
| 45 | { |
| 46 | QLIST_INIT(&list->notifiers); |
| 47 | } |
| 48 | |
| 49 | void notifier_with_return_list_add(NotifierWithReturnList *list, |
| 50 | NotifierWithReturn *notifier) |
| 51 | { |
| 52 | QLIST_INSERT_HEAD(&list->notifiers, notifier, node); |
| 53 | } |
| 54 | |
| 55 | void notifier_with_return_remove(NotifierWithReturn *notifier) |
| 56 | { |
| 57 | QLIST_REMOVE(notifier, node); |
| 58 | } |
| 59 | |
| 60 | int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data) |
| 61 | { |
| 62 | NotifierWithReturn *notifier, *next; |
| 63 | int ret = 0; |
| 64 | |
| 65 | QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { |
| 66 | ret = notifier->notify(notifier, data); |
| 67 | if (ret != 0) { |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | return ret; |
| 72 | } |