blob: 76bab212ae9c1096a7ee7939bc36edfac4231822 [file] [log] [blame]
Anthony Liguorid1e70c52010-03-09 13:16:14 -06001/*
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 Bonzini6b620ca2012-01-13 17:44:23 +010012 * 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 Liguorid1e70c52010-03-09 13:16:14 -060014 */
15
Peter Maydellaafd7582016-01-29 17:49:55 +000016#include "qemu/osdep.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010017#include "qemu/notify.h"
Anthony Liguorid1e70c52010-03-09 13:16:14 -060018
19void notifier_list_init(NotifierList *list)
20{
Paolo Bonzini31552522012-01-13 17:34:01 +010021 QLIST_INIT(&list->notifiers);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060022}
23
24void notifier_list_add(NotifierList *list, Notifier *notifier)
25{
Paolo Bonzini31552522012-01-13 17:34:01 +010026 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060027}
28
Paolo Bonzini31552522012-01-13 17:34:01 +010029void notifier_remove(Notifier *notifier)
Anthony Liguorid1e70c52010-03-09 13:16:14 -060030{
Paolo Bonzini31552522012-01-13 17:34:01 +010031 QLIST_REMOVE(notifier, node);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060032}
33
Jan Kiszka9e8dd452011-06-20 14:06:26 +020034void notifier_list_notify(NotifierList *list, void *data)
Anthony Liguorid1e70c52010-03-09 13:16:14 -060035{
36 Notifier *notifier, *next;
37
Paolo Bonzini31552522012-01-13 17:34:01 +010038 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
Jan Kiszka9e8dd452011-06-20 14:06:26 +020039 notifier->notify(notifier, data);
Anthony Liguorid1e70c52010-03-09 13:16:14 -060040 }
41}
Stefan Hajnoczi5dae8e52013-06-24 17:13:09 +020042
Paul Durrant374752a2019-09-13 09:21:56 +010043bool notifier_list_empty(NotifierList *list)
44{
45 return QLIST_EMPTY(&list->notifiers);
46}
47
Stefan Hajnoczi5dae8e52013-06-24 17:13:09 +020048void notifier_with_return_list_init(NotifierWithReturnList *list)
49{
50 QLIST_INIT(&list->notifiers);
51}
52
53void notifier_with_return_list_add(NotifierWithReturnList *list,
54 NotifierWithReturn *notifier)
55{
56 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
57}
58
59void notifier_with_return_remove(NotifierWithReturn *notifier)
60{
61 QLIST_REMOVE(notifier, node);
62}
63
64int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
65{
66 NotifierWithReturn *notifier, *next;
67 int ret = 0;
68
69 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
70 ret = notifier->notify(notifier, data);
71 if (ret != 0) {
72 break;
73 }
74 }
75 return ret;
76}