mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 01/15] poller: Fix async poller
Date: Wed, 13 Jan 2016 16:37:22 +0100	[thread overview]
Message-ID: <1452699456-1025-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1452699456-1025-1-git-send-email-s.hauer@pengutronix.de>

The async poller does not work as expected since it can happen that
the async poller is removed from the list of pollers while we are
iterating over the list. Even list_for_each_entry_safe does not help
here since we may remove the next list element, but
list_for_each_entry_safe only allows to remove the current list element.

Rework the async poller so that it is registered with the poller
framework on registration and then is only marked as active with
poller_call_async(). This way we do not have to do list manipulations
while running the pollers.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/poller.c  | 26 ++++++++++++++++++++++----
 include/poller.h |  4 ++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/common/poller.c b/common/poller.c
index 496636d..32795b6 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -32,6 +32,7 @@ int poller_unregister(struct poller_struct *poller)
 	if (!poller->registered)
 		return -ENODEV;
 
+
 	list_del(&poller->list);
 	poller->registered = 0;
 
@@ -42,12 +43,14 @@ static void poller_async_callback(struct poller_struct *poller)
 {
 	struct poller_async *pa = container_of(poller, struct poller_async, poller);
 
+	if (!pa->active)
+		return;
+
 	if (get_time_ns() < pa->end)
 		return;
 
+	pa->active = 0;
 	pa->fn(pa->ctx);
-	pa->fn = NULL;
-	poller_unregister(&pa->poller);
 }
 
 /*
@@ -62,7 +65,9 @@ static void poller_async_callback(struct poller_struct *poller)
  */
 int poller_async_cancel(struct poller_async *pa)
 {
-	return poller_unregister(&pa->poller);
+	pa->active = 0;
+
+	return 0;
 }
 
 /*
@@ -80,13 +85,26 @@ int poller_call_async(struct poller_async *pa, uint64_t delay_ns,
 		void (*fn)(void *), void *ctx)
 {
 	pa->ctx = ctx;
-	pa->poller.func = poller_async_callback;
 	pa->end = get_time_ns() + delay_ns;
 	pa->fn = fn;
+	pa->active = 1;
+
+	return 0;
+}
+
+int poller_async_register(struct poller_async *pa)
+{
+	pa->poller.func = poller_async_callback;
+	pa->active = 0;
 
 	return poller_register(&pa->poller);
 }
 
+int poller_async_unregister(struct poller_async *pa)
+{
+	return poller_unregister(&pa->poller);
+}
+
 void poller_call(void)
 {
 	struct poller_struct *poller, *tmp;
diff --git a/include/poller.h b/include/poller.h
index cda5b57..35a2271 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -26,8 +26,12 @@ struct poller_async {
 	void (*fn)(void *);
 	void *ctx;
 	uint64_t end;
+	int active;
 };
 
+int poller_async_register(struct poller_async *pa);
+int poller_async_unregister(struct poller_async *pa);
+
 int poller_call_async(struct poller_async *pa, uint64_t delay_ns,
 		void (*fn)(void *), void *ctx);
 int poller_async_cancel(struct poller_async *pa);
-- 
2.6.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-01-13 15:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 15:37 [PATCH] input core Sascha Hauer
2016-01-13 15:37 ` Sascha Hauer [this message]
2016-01-13 15:37 ` [PATCH 02/15] keymap: Fix braces Sascha Hauer
2016-01-13 15:37 ` [PATCH 03/15] keymap: remove exotic and nonprintable keys Sascha Hauer
2016-01-13 15:37 ` [PATCH 04/15] keymap: Add keypad keys Sascha Hauer
2016-01-13 15:37 ` [PATCH 05/15] keymap: Add apostrophe, backslash and home Sascha Hauer
2016-01-13 15:37 ` [PATCH 06/15] keymap: Add keymap for keys with shift pressed Sascha Hauer
2016-01-13 15:37 ` [PATCH 07/15] input: Add input core Sascha Hauer
2017-05-05 10:05   ` Antony Pavlov
2017-05-05 11:10     ` Sascha Hauer
2016-01-13 15:37 ` [PATCH 08/15] input: usb keyboard: convert to input framework Sascha Hauer
2016-01-13 15:37 ` [PATCH 09/15] input: imx-keypad: Use dev_* functions Sascha Hauer
2016-01-13 15:37 ` [PATCH 10/15] input: move matrix_keypad_build_keymap() to C file Sascha Hauer
2016-01-13 15:37 ` [PATCH 11/15] input: imx-keypad: convert to input framework Sascha Hauer
2016-01-13 15:37 ` [PATCH 12/15] input: Add device tree parsing support for matrix keymap Sascha Hauer
2016-01-13 15:37 ` [PATCH 13/15] input: imx-keypad: Add device tree support Sascha Hauer
2016-01-13 15:37 ` [PATCH 14/15] input: gpio-keys: Use KEY_* keycodes Sascha Hauer
2016-01-13 15:37 ` [PATCH 15/15] input: gpio-keys: convert to input framework Sascha Hauer

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=1452699456-1025-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox