Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / util / notify.c
blobc6e158ffb3317f23f4d694771d5c47d5530dec82
1 /*
2 * Notifier lists
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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.
16 #include "qemu/osdep.h"
17 #include "qemu/notify.h"
19 void notifier_list_init(NotifierList *list)
21 QLIST_INIT(&list->notifiers);
24 void notifier_list_add(NotifierList *list, Notifier *notifier)
26 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
29 void notifier_remove(Notifier *notifier)
31 QLIST_REMOVE(notifier, node);
34 void notifier_list_notify(NotifierList *list, void *data)
36 Notifier *notifier, *next;
38 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
39 notifier->notify(notifier, data);
43 bool notifier_list_empty(NotifierList *list)
45 return QLIST_EMPTY(&list->notifiers);
48 void notifier_with_return_list_init(NotifierWithReturnList *list)
50 QLIST_INIT(&list->notifiers);
53 void notifier_with_return_list_add(NotifierWithReturnList *list,
54 NotifierWithReturn *notifier)
56 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
59 void notifier_with_return_remove(NotifierWithReturn *notifier)
61 QLIST_REMOVE(notifier, node);
64 int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data,
65 Error **errp)
67 NotifierWithReturn *notifier, *next;
68 int ret = 0;
70 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
71 ret = notifier->notify(notifier, data, errp);
72 if (ret != 0) {
73 break;
76 return ret;