Fixes preempt/indir tracing in lock_test
[akaros.git] / user / benchutil / alarm_dispatch.c
index ed70097..56e417c 100644 (file)
@@ -21,13 +21,16 @@ struct {
 } dispatch;
 
 /* Dispatch the alarm event to its proper handler */
-static void dispatch_alarm(struct event_msg *ev_msg, unsigned int ev_type)
+static void dispatch_alarm(struct event_msg *ev_msg, unsigned int ev_type,
+                           void *data)
 {
        assert(ev_type == EV_ALARM);
        if (ev_msg) {
                // There is a slight race here if you don't disable the alarm before
                // deregistering its handler.  Make sure you do this properly.
-               dispatch.handlers[ev_msg->ev_arg2](ev_msg, ev_type);
+               handle_event_t handler = dispatch.handlers[ev_msg->ev_arg2];
+               if (handler)
+                       handler(ev_msg, ev_type, data);
        }
 }
 
@@ -37,7 +40,7 @@ static void init_alarm_dispatch()
        spin_pdr_init(&dispatch.lock);
        dispatch.handlers = NULL;
        dispatch.length = 0;
-       ev_handlers[EV_ALARM] = dispatch_alarm;
+       register_ev_handler(EV_ALARM, dispatch_alarm, 0);
 }
 
 /* Grow the handler array if necessary.  The array lock must be held when
@@ -45,8 +48,9 @@ static void init_alarm_dispatch()
 static void __maybe_grow_handler_array(int index)
 {
        if (dispatch.length <= index) {
-               int new_size = dispatch.length + GROWTH_INC*(index/GROWTH_INC);
-               dispatch.handlers = realloc(dispatch.handlers, new_size);
+               int new_size = GROWTH_INC * (1 + index/GROWTH_INC);
+               dispatch.handlers = realloc(dispatch.handlers,
+                                           new_size * sizeof(handle_event_t));
                for (int i=dispatch.length; i<new_size; i++)
                        dispatch.handlers[i] = NULL;
                dispatch.length = new_size;