From 470989bd708d9a425dbbf2d83b8fcbd0a8d0f488 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 14 Mar 2014 23:15:16 +0100 Subject: events: Rework event subsystem (add_event, send_event) to be more versatile. add_event_ex is added that takes an extra user_data pointer. This pointer is passed to the callback (add_event and add_event_ex have slightly different callbacks types). All callbacks also get the event id passed. Events added with add_event_ex must be removed with remove_event_ex because the user_data pointer must match in addition to the callback pointer. On the other add_event is simplified to omit the oneshort parameter which was almost always false (still there with add_event_ex). As a side effect the ata_idle_notify callbacks are changed as well, they do not take a data parameter anymore which was always NULL anyway. This commit also adds some documentation to events.h Change-Id: I13e29a0f88ef908f175b376d83550f9e0231f772 --- firmware/ata_idle_notify.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'firmware/ata_idle_notify.c') diff --git a/firmware/ata_idle_notify.c b/firmware/ata_idle_notify.c index 35d192bee0..ee9f3c035f 100644 --- a/firmware/ata_idle_notify.c +++ b/firmware/ata_idle_notify.c @@ -25,12 +25,20 @@ #include "kernel.h" #include "string.h" -void register_storage_idle_func(void (*function)(void *data)) +static void wrapper(unsigned short id, void *ev_data, void *user_data) +{ + (void)id; + (void)ev_data; + void (*func)(void) = user_data; + func(); +} + +void register_storage_idle_func(void (*function)(void)) { #if USING_STORAGE_CALLBACK - add_event(DISK_EVENT_SPINUP, true, function); + add_event_ex(DISK_EVENT_SPINUP, true, wrapper, function); #else - function(NULL); /* just call the function now */ + function(); /* just call the function now */ /* this _may_ cause problems later if the calling function sets a variable expecting the callback to unset it, because the callback will be run before this function exits, so before the var is set */ @@ -38,12 +46,12 @@ void register_storage_idle_func(void (*function)(void *data)) } #if USING_STORAGE_CALLBACK -void unregister_storage_idle_func(void (*func)(void *data), bool run) +void unregister_storage_idle_func(void (*func)(void), bool run) { - remove_event(DISK_EVENT_SPINUP, func); + remove_event_ex(DISK_EVENT_SPINUP, wrapper, func); if (run) - func(NULL); + func(); } bool call_storage_idle_notifys(bool force) -- cgit v1.2.3