diff options
Diffstat (limited to 'firmware/events.c')
-rw-r--r-- | firmware/events.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/firmware/events.c b/firmware/events.c index 8015442cc2..8124f92b20 100644 --- a/firmware/events.c +++ b/firmware/events.c | |||
@@ -43,30 +43,30 @@ static struct sysevent events[MAX_SYS_EVENTS]; | |||
43 | static bool do_add_event(unsigned short id, bool oneshot, bool user_data_valid, | 43 | static bool do_add_event(unsigned short id, bool oneshot, bool user_data_valid, |
44 | void *handler, void *user_data) | 44 | void *handler, void *user_data) |
45 | { | 45 | { |
46 | int i; | 46 | int free = -1; |
47 | 47 | /* Check if the event already exists. & lowest free slot available */ | |
48 | /* Check if the event already exists. */ | 48 | for (int i = MAX_SYS_EVENTS - 1; i >= 0; i--) |
49 | for (i = 0; i < MAX_SYS_EVENTS; i++) | ||
50 | { | 49 | { |
51 | if (events[i].handler.callback == handler && events[i].id == id | 50 | if (events[i].handler.callback == handler && events[i].id == id |
52 | && (!user_data_valid || (user_data == events[i].handler.user_data))) | 51 | && (!user_data_valid || (user_data == events[i].handler.user_data))) |
52 | { | ||
53 | return false; | 53 | return false; |
54 | } | ||
55 | else if (events[i].handler.callback == NULL) | ||
56 | free = i; | ||
54 | } | 57 | } |
55 | 58 | ||
56 | /* Try to find a free slot. */ | 59 | /* is there a free slot? */ |
57 | for (i = 0; i < MAX_SYS_EVENTS; i++) | 60 | if (free >= 0) |
58 | { | 61 | { |
59 | if (events[i].handler.callback == NULL) | 62 | events[free].id = id; |
60 | { | 63 | events[free].oneshot = oneshot; |
61 | events[i].id = id; | 64 | if ((events[free].has_user_data = user_data_valid)) |
62 | events[i].oneshot = oneshot; | 65 | events[free].handler.user_data = user_data; |
63 | if ((events[i].has_user_data = user_data_valid)) | 66 | events[free].handler.callback = handler; |
64 | events[i].handler.user_data = user_data; | 67 | return true; |
65 | events[i].handler.callback = handler; | ||
66 | return true; | ||
67 | } | ||
68 | } | 68 | } |
69 | 69 | ||
70 | panicf("event line full"); | 70 | panicf("event line full"); |
71 | return false; | 71 | return false; |
72 | } | 72 | } |