From patchwork Fri Mar 13 12:33:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Heyne X-Patchwork-Id: 11436845 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEFF692A for ; Fri, 13 Mar 2020 12:35:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B68420724 for ; Fri, 13 Mar 2020 12:35:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="WHTWrSgy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B68420724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCjW6-0006VO-H6; Fri, 13 Mar 2020 12:34:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jCjVR-0006Sr-Vr for xen-devel@lists.xenproject.org; Fri, 13 Mar 2020 12:33:38 +0000 X-Inumbo-ID: d454c49a-6526-11ea-bec1-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d454c49a-6526-11ea-bec1-bc764e2007e4; Fri, 13 Mar 2020 12:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1584102804; x=1615638804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=/fya+BUW395U9TLzGT2hJK0Q5V3PVgjLhCkueg8SXWM=; b=WHTWrSgysw5+kYDMapmP42uaipgRSLnbnVHnqTMjyES0WydlO9VB38bm xaOU842avfogBWPWcJIw+A9mQbv1AGyUiD7ExM3sxLik6RAtDApPDW5UD poAcxF+Eny0pR9yDpNFuuaDJKvgawZl91izXGfSVSpkwYFcHVF6K9kGr8 Y=; IronPort-SDR: mY8lsV8TYLGhb+H/4UKwIj4NuZ6iv/RVBbrk7enU2Y8oUzT8CkdBubgawTIAy331gCfPgDj2O2 UiOF40BwnDIg== X-IronPort-AV: E=Sophos;i="5.70,548,1574121600"; d="scan'208";a="32421122" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 13 Mar 2020 12:33:21 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-2c665b5d.us-east-1.amazon.com (Postfix) with ESMTPS id 0B978A2C4E; Fri, 13 Mar 2020 12:33:20 +0000 (UTC) Received: from EX13D08EUC004.ant.amazon.com (10.43.164.176) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Fri, 13 Mar 2020 12:33:20 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D08EUC004.ant.amazon.com (10.43.164.176) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 12:33:19 +0000 Received: from dev-dsk-mheyne-60001.pdx1.corp.amazon.com (10.184.85.242) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 13 Mar 2020 12:33:17 +0000 Received: by dev-dsk-mheyne-60001.pdx1.corp.amazon.com (Postfix, from userid 5466572) id 87DE1222D7; Fri, 13 Mar 2020 12:33:16 +0000 (UTC) From: Maximilian Heyne To: Date: Fri, 13 Mar 2020 12:33:14 +0000 Message-ID: <20200313123316.122003-2-mheyne@amazon.de> X-Mailer: git-send-email 2.16.6 In-Reply-To: <20200313123316.122003-1-mheyne@amazon.de> References: <20200313123316.122003-1-mheyne@amazon.de> MIME-Version: 1.0 Precedence: Bulk X-Mailman-Approved-At: Fri, 13 Mar 2020 12:34:17 +0000 Subject: [Xen-devel] [PATCH 1/3] Add support for generic notifier lists X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Paul Durrant Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Anthony Liguori 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 Reviewed-by: Paul Durrant --- 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 --- 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 + * + * 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 + * + * 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. */