Skip to main content

Usability could be improved a bit. For example, alloc_timeralloc_timer() (note, name is deceptive as no actual allocation takes place) could be put inside of the set_timerset_timer() function. Let your framework worry about finding a free timer in the pool, or returning an error code. A separate function for allocating the timer would be more useful if you weren't using a pool and if it was important for a user to control when memory allocations occur.

I don't like how the callback method controls whether the timer is freed. I could see lots of potential timer 'leaks'. I think if you added a repeating timer type, most of the cases where you wouldn't want to free your timer could then be taken care of by your framework. If you really need a handle to a timer that you could guarantee would be available when you need it, I think extending or overloading alloc_timeralloc_timer() (and/or set_timerset_timer()) would be a better place. That way, the decision to take it off and put it back on the free_timersfree_timers list is in the same line of code.

In clock_tickclock_tick(), you're removing aan element off the active_timersactive_timers list while you iterate over it. In your case it looks like it'll work but that's usually an unsafe thing to do, I'd double check that.

Usability could be improved a bit. For example, alloc_timer (note, name is deceptive as no actual allocation takes place) could be put inside of the set_timer function. Let your framework worry about finding a free timer in the pool, or returning an error code. A separate function for allocating the timer would be more useful if you weren't using a pool and if it was important for a user to control when memory allocations occur.

I don't like how the callback method controls whether the timer is freed. I could see lots of potential timer 'leaks'. I think if you added a repeating timer type, most of the cases where you wouldn't want to free your timer could then be taken care of by your framework. If you really need a handle to a timer that you could guarantee would be available when you need it, I think extending or overloading alloc_timer (and/or set_timer) would be a better place. That way, the decision to take it off and put it back on the free_timers list is in the same line of code.

In clock_tick, you're removing a element off the active_timers list while you iterate over it. In your case it looks like it'll work but that's usually an unsafe thing to do, I'd double check that.

Usability could be improved a bit. For example, alloc_timer() (note, name is deceptive as no actual allocation takes place) could be put inside of the set_timer() function. Let your framework worry about finding a free timer in the pool, or returning an error code. A separate function for allocating the timer would be more useful if you weren't using a pool and if it was important for a user to control when memory allocations occur.

I don't like how the callback method controls whether the timer is freed. I could see lots of potential timer 'leaks'. I think if you added a repeating timer type, most of the cases where you wouldn't want to free your timer could then be taken care of by your framework. If you really need a handle to a timer that you could guarantee would be available when you need it, I think extending or overloading alloc_timer() (and/or set_timer()) would be a better place. That way, the decision to take it off and put it back on the free_timers list is in the same line of code.

In clock_tick(), you're removing an element off the active_timers list while you iterate over it. In your case it looks like it'll work but that's usually an unsafe thing to do, I'd double check that.

Source Link

Usability could be improved a bit. For example, alloc_timer (note, name is deceptive as no actual allocation takes place) could be put inside of the set_timer function. Let your framework worry about finding a free timer in the pool, or returning an error code. A separate function for allocating the timer would be more useful if you weren't using a pool and if it was important for a user to control when memory allocations occur.

I don't like how the callback method controls whether the timer is freed. I could see lots of potential timer 'leaks'. I think if you added a repeating timer type, most of the cases where you wouldn't want to free your timer could then be taken care of by your framework. If you really need a handle to a timer that you could guarantee would be available when you need it, I think extending or overloading alloc_timer (and/or set_timer) would be a better place. That way, the decision to take it off and put it back on the free_timers list is in the same line of code.

In clock_tick, you're removing a element off the active_timers list while you iterate over it. In your case it looks like it'll work but that's usually an unsafe thing to do, I'd double check that.