Reformatted the source somewhat and removed preproccessor #include statements to the respective header files since those are only needed externally
This commit is contained in:
parent
86d75c8bed
commit
f23333a597
@ -34,19 +34,18 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <generic_types.h>
|
#include <generic_types.h>
|
||||||
#include <heap.h>
|
|
||||||
|
|
||||||
#define Minimum_Heap_Size 10
|
#define Minimum_Heap_Size 10
|
||||||
|
|
||||||
struct Heap {
|
struct Heap {
|
||||||
u_long array_size;
|
u_long array_size;
|
||||||
u_long num_elements;
|
u_long num_elements;
|
||||||
heap_compare compare;
|
_Bool (*compare)(Any_Type, Any_Type);
|
||||||
Any_Type storage[]; /* c99 Flexible Array Member */
|
Any_Type storage[]; /* c99 Flexible Array Member */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Heap *
|
struct Heap *
|
||||||
create_heap(u_long size, heap_compare compare_callback)
|
create_heap(u_long size, _Bool (*compare_callback) (Any_Type, Any_Type))
|
||||||
{
|
{
|
||||||
struct Heap *h;
|
struct Heap *h;
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ poll_min(struct Heap * h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
heap_for_each(struct Heap *h, heap_for_each_action action)
|
heap_for_each(struct Heap *h, void (*action) (Any_Type))
|
||||||
{
|
{
|
||||||
for(u_long i = 1; i <= h->num_elements; i++)
|
for(u_long i = 1; i <= h->num_elements; i++)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#define WHEEL_SIZE 4096
|
#define WHEEL_SIZE 4096
|
||||||
|
|
||||||
#define TIMER_INTERVAL (1.0/1000) /* timer granularity in seconds */
|
#define TIMER_INTERVAL (1.0/1000) /* timer granularity in seconds */
|
||||||
typedef void (*Timer_Callback) (struct Timer * t, Any_Type arg);
|
|
||||||
|
|
||||||
static Time now;
|
static Time now;
|
||||||
static Time next_tick;
|
static Time next_tick;
|
||||||
@ -57,7 +56,7 @@ struct Timer {
|
|||||||
/*
|
/*
|
||||||
* Callback function called when timer expires (timeout)
|
* Callback function called when timer expires (timeout)
|
||||||
*/
|
*/
|
||||||
Timer_Callback timeout_callback;
|
void (*timeout_callback) (struct Timer * t, Any_Type arg);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Typically used as a void pointer to the data object being timed
|
* Typically used as a void pointer to the data object being timed
|
||||||
@ -145,7 +144,7 @@ timer_init(void)
|
|||||||
goto init_failure;
|
goto init_failure;
|
||||||
|
|
||||||
while (!is_queue_full(passive_timers)) {
|
while (!is_queue_full(passive_timers)) {
|
||||||
Any_Type a;
|
Any_Type a;
|
||||||
a.vp = malloc(sizeof(struct Timer));
|
a.vp = malloc(sizeof(struct Timer));
|
||||||
|
|
||||||
if (a.vp == NULL)
|
if (a.vp == NULL)
|
||||||
@ -248,7 +247,8 @@ timer_tick(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Timer *
|
struct Timer *
|
||||||
timer_schedule(Timer_Callback timeout, Any_Type subject, Time delay)
|
timer_schedule(void (*timeout) (struct Timer * t, Any_Type arg),
|
||||||
|
Any_Type subject, Time delay)
|
||||||
{
|
{
|
||||||
struct Timer *t;
|
struct Timer *t;
|
||||||
u_long ticks;
|
u_long ticks;
|
||||||
@ -284,8 +284,9 @@ timer_schedule(Timer_Callback timeout, Any_Type subject, Time delay)
|
|||||||
insert((Any_Type) (void *) t, active_timers);
|
insert((Any_Type) (void *) t, active_timers);
|
||||||
|
|
||||||
if (DBG > 2)
|
if (DBG > 2)
|
||||||
fprintf(stderr, "timer_schedule: t=%p, delay=%gs, subject=%lx\n",
|
fprintf(stderr,
|
||||||
t, delay, subject.l);
|
"timer_schedule: t=%p, delay=%gs, subject=%lx\n", t,
|
||||||
|
delay, subject.l);
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user