diff options
author | Anton Staaf <robotboy@chromium.org> | 2016-03-23 12:45:28 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-04-18 17:32:40 -0700 |
commit | 068cd0850684ee28a5a514e5a270edce2edb3979 (patch) | |
tree | e84f2316e37baa72f1c9611e665749d91a3ce8fd /include/hooks.h | |
parent | 1e7c280491232110e1006d545f9a61ca05d469d5 (diff) | |
download | chrome-ec-068cd0850684ee28a5a514e5a270edce2edb3979.tar.gz |
Deferred: Use deferred_data instead of function pointer
Previously calls to hook_call_deferred were passed the function to call,
which was then looked up in the .rodata.deferred section with a linear
search. This linear search can be replaced with a subtract by passing
the pointer to the deferred_data object created when DECLARE_DEFERRED
was invoked.
Signed-off-by: Anton Staaf <robotboy@chromium.org>
BRANCH=None
BUG=None
CQ-DEPEND=CL:*255812
TEST=make buildall -j
Change-Id: I951dd1541302875b102dd086154cf05591694440
Reviewed-on: https://chromium-review.googlesource.com/334315
Commit-Ready: Bill Richardson <wfrichar@chromium.org>
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'include/hooks.h')
-rw-r--r-- | include/hooks.h | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/include/hooks.h b/include/hooks.h index 3a7af06f3c..142926e6a9 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -190,22 +190,26 @@ struct hook_data { */ void hook_notify(enum hook_type type); +struct deferred_data { + /* Deferred function pointer */ + void (*routine)(void); +}; + /** * Start a timer to call a deferred routine. * * The routine will be called after at least the specified delay, in the * context of the hook task. * - * @param routine Routine to call; must have been declared with - * DECLARE_DEFERRED(). - * @param us Delay in microseconds until routine will be called. - * If the routine is already pending, subsequent calls - * will change the delay. Pass us=0 to call as soon as - * possible, or -1 to cancel the deferred call. + * @param data The deferred_data struct created by invoking DECLARE_DEFERRED(). + * @param us Delay in microseconds until routine will be called. If the + * routine is already pending, subsequent calls will change the + * delay. Pass us=0 to call as soon as possible, or -1 to cancel + * the deferred call. * * @return non-zero if error. */ -int hook_call_deferred(void (*routine)(void), int us); +int hook_call_deferred(const struct deferred_data *data, int us); #ifdef CONFIG_COMMON_RUNTIME /** @@ -239,18 +243,20 @@ int hook_call_deferred(void (*routine)(void), int us); __attribute__((section(".rodata." STRINGIFY(hooktype)))) \ = {routine, priority} - -struct deferred_data { - /* Deferred function pointer */ - void (*routine)(void); -}; - /** * Register a deferred function call. * * Note that if you declare a bunch of these, you may need to override * DEFERRABLE_MAX_COUNT in your board.h. * + * DECLARE_DEFERRED creates a new deferred_data struct with a name constructed + * by concatenating _data to the name of the routine passed. + * + * To call a deferred routine defined as: + * DECLARE_DEFERRED(foo) + * You would call + * hook_call_deferred(&foo_data, delay_in_microseconds); + * * NOTE: Deferred function call routines must be careful not to leave resources * locked which may be needed by other hook routines or deferred function * calls. This can cause a deadlock, because most hooks and all deferred @@ -260,7 +266,7 @@ struct deferred_data { * @param routine Function pointer, with prototype void routine(void) */ #define DECLARE_DEFERRED(routine) \ - const struct deferred_data __keep CONCAT2(__deferred_, routine) \ + const struct deferred_data __keep CONCAT2(routine, _data) \ __attribute__((section(".rodata.deferred"))) \ = {routine} |