From: Maximilian Heyne <mheyne@amazon.de>
To: <xen-devel@lists.xenproject.org>
Cc: Ian Jackson <ian.jackson@citrix.com>, Paul Durrant <paul@xen.org>
Subject: [Xen-devel] [PATCH 1/3] Add support for generic notifier lists
Date: Fri, 13 Mar 2020 12:33:14 +0000 [thread overview]
Message-ID: <20200313123316.122003-2-mheyne@amazon.de> (raw)
In-Reply-To: <20200313123316.122003-1-mheyne@amazon.de>
From: Anthony Liguori <aliguori@us.ibm.com>
Notifiers are data-less callbacks and a notifier list is a list of registered
notifiers that all are interested in a particular event.
We'll use this in a few patches to implement mouse change notification.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- Do not do memory allocations by placing list nodes in notifier
[cherry-picked from d1e70c5e6d1472856c52969301247fe8c3c8389d
conflicts: used the sys-qeue interface and added required
LIST_REMOVE_SAFE function to that]
Signed-off-by: Maximilian Heyne <mheyne@amazon.de>
---
Makefile | 1 +
notify.c | 39 +++++++++++++++++++++++++++++++++++++++
notify.h | 43 +++++++++++++++++++++++++++++++++++++++++++
sys-queue.h | 5 +++++
4 files changed, 88 insertions(+)
create mode 100644 notify.c
create mode 100644 notify.h
diff --git a/Makefile b/Makefile
index 0fbec990b..d921bcdf8 100644
--- a/Makefile
+++ b/Makefile
@@ -93,6 +93,7 @@ OBJS+=sd.o ssi-sd.o
OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
OBJS+=buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o
OBJS+=qemu-char.o aio.o net-checksum.o savevm.o cache-utils.o
+OBJS+=notify.o
ifdef CONFIG_BRLAPI
OBJS+= baum.o
diff --git a/notify.c b/notify.c
new file mode 100644
index 000000000..59e1e7c7d
--- /dev/null
+++ b/notify.c
@@ -0,0 +1,39 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "notify.h"
+
+void notifier_list_init(NotifierList *list)
+{
+ LIST_INIT(&list->notifiers);
+}
+
+void notifier_list_add(NotifierList *list, Notifier *notifier)
+{
+ LIST_INSERT_HEAD(&list->notifiers, notifier, node);
+}
+
+void notifier_list_remove(Notifier *notifier)
+{
+ LIST_REMOVE(notifier, node);
+}
+
+void notifier_list_notify(NotifierList *list)
+{
+ Notifier *notifier, *next;
+
+ LIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
+ notifier->notify(notifier);
+ }
+}
diff --git a/notify.h b/notify.h
new file mode 100644
index 000000000..093c63f19
--- /dev/null
+++ b/notify.h
@@ -0,0 +1,43 @@
+/*
+ * Notifier lists
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_NOTIFY_H
+#define QEMU_NOTIFY_H
+
+#include "sys-queue.h"
+
+typedef struct Notifier Notifier;
+
+struct Notifier
+{
+ void (*notify)(Notifier *notifier);
+ LIST_ENTRY(Notifier) node;
+};
+
+typedef struct NotifierList
+{
+ LIST_HEAD(, Notifier) notifiers;
+} NotifierList;
+
+#define NOTIFIER_LIST_INITIALIZER(head) \
+ { LIST_HEAD_INITIALIZER((head).notifiers) }
+
+void notifier_list_init(NotifierList *list);
+
+void notifier_list_add(NotifierList *list, Notifier *notifier);
+
+void notifier_list_remove(Notifier *notifier);
+
+void notifier_list_notify(NotifierList *list);
+
+#endif
diff --git a/sys-queue.h b/sys-queue.h
index 55c26fe7f..81ab044a8 100644
--- a/sys-queue.h
+++ b/sys-queue.h
@@ -132,6 +132,11 @@ struct { \
(var); \
(var) = ((var)->field.le_next))
+#define LIST_FOREACH_SAFE(var, head, field, next_var) \
+ for ((var) = ((head)->lh_first); \
+ (var) && ((next_var) = ((var)->field.le_next), 1); \
+ (var) = (next_var))
+
/*
* List access methods.
*/
--
2.16.6
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-03-13 12:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-13 12:33 [Xen-devel] [PATCH 0/3] Cleanup IOREQ server on exit Maximilian Heyne
2020-03-13 12:33 ` Maximilian Heyne [this message]
2020-04-08 14:58 ` [PATCH 1/3] Add support for generic notifier lists Paul Durrant
2020-03-13 12:33 ` [Xen-devel] [PATCH 2/3] Add exit notifiers Maximilian Heyne
2020-04-08 14:57 ` Paul Durrant
2020-03-13 12:33 ` [Xen-devel] [PATCH 3/3] xen: cleanup IOREQ server on exit Maximilian Heyne
2020-04-08 14:56 ` Paul Durrant
2020-04-07 9:16 ` [PATCH 0/3] Cleanup " Maximilian Heyne
2020-04-08 8:40 ` Paul Durrant
2020-04-21 16:35 ` Paul Durrant
2020-04-24 14:50 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200313123316.122003-2-mheyne@amazon.de \
--to=mheyne@amazon.de \
--cc=ian.jackson@citrix.com \
--cc=paul@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.