[PATCH 7/9] poller: allow to restrict the poller frequency

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Tue Dec 23 10:21:56 PST 2014


so we do not slow down barebox on too much polling
specialy on USB drivers

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 common/poller.c  | 11 ++++++++++-
 include/poller.h |  3 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/common/poller.c b/common/poller.c
index 496636d..58b105d 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -24,6 +24,9 @@ int poller_register(struct poller_struct *poller)
 	list_add_tail(&poller->list, &poller_list);
 	poller->registered = 1;
 
+	if (poller->frequency)
+		poller->poll_next = get_time_ns();
+
 	return 0;
 }
 
@@ -96,8 +99,14 @@ void poller_call(void)
 
 	poller_active = 1;
 
-	list_for_each_entry_safe(poller, tmp, &poller_list, list)
+	list_for_each_entry_safe(poller, tmp, &poller_list, list) {
+
+		if (poller->frequency && get_time_ns() < poller->poll_next)
+			continue;
 		poller->func(poller);
+		if (poller->frequency)
+			poller->poll_next += poller->frequency;
+	}
 
 	poller_active = 0;
 }
diff --git a/include/poller.h b/include/poller.h
index cda5b57..3568a80 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -14,6 +14,9 @@ struct poller_struct {
 	void (*func)(struct poller_struct *poller);
 	int registered;
 	struct list_head list;
+
+	uint64_t frequency;
+	uint64_t poll_next;
 };
 
 int poller_register(struct poller_struct *poller);
-- 
2.1.3




More information about the barebox mailing list