Use bool rather than int and _Bool

This commit is contained in:
tedbullock 2007-11-16 01:05:55 +00:00
förälder 447ad7b739
incheckning bcaf1d0eec
5 ändrade filer med 28 tillägg och 28 borttagningar

Visa fil

@ -1023,7 +1023,11 @@ main (int argc, char **argv)
} }
printf ("\n"); printf ("\n");
timer_init (); if(timer_init() == false)
{
fprintf(stderr, "%s: timer_init(): failed initialization (%d)\n", prog_name, __LINE__);
exit(1);
}
core_init (); core_init ();
signal (SIGINT, (void (*)()) core_exit); signal (SIGINT, (void (*)()) core_exit);

Visa fil

@ -43,7 +43,7 @@ struct List {
struct Node *dummy_head; struct Node *dummy_head;
}; };
int bool
is_list_empty(struct List *l) is_list_empty(struct List *l)
{ {
@ -80,7 +80,7 @@ list_free(struct List *l)
free(l); free(l);
} }
int bool
list_push(struct List *l, Any_Type data) list_push(struct List *l, Any_Type data)
{ {
struct Node *n; struct Node *n;
@ -90,14 +90,14 @@ list_push(struct List *l, Any_Type data)
* malloc every time we push a new node onto the list * malloc every time we push a new node onto the list
*/ */
if ((n = malloc(sizeof(struct Node))) == NULL) { if ((n = malloc(sizeof(struct Node))) == NULL) {
return 0; return false;
} }
n->data = data; n->data = data;
n->next = l->dummy_head->next; n->next = l->dummy_head->next;
l->dummy_head->next = n; l->dummy_head->next = n;
return 1; return true;
} }
Any_Type Any_Type
@ -151,3 +151,4 @@ list_for_each(struct List *l, int (*action) (Any_Type))
n = n->next; n = n->next;
} }
} }

Visa fil

@ -37,8 +37,8 @@ struct List;
struct List *list_create(); struct List *list_create();
void list_free(struct List *); void list_free(struct List *);
void list_push(struct List *, Any_Type); bool list_push(struct List *, Any_Type);
int is_list_empty(struct List *); bool is_list_empty(struct List *);
Any_Type list_top(struct List *); Any_Type list_top(struct List *);
Any_Type list_pop(struct List *); Any_Type list_pop(struct List *);
void list_remove_if_true(struct List *, list_action); void list_remove_if_true(struct List *, list_action);

Visa fil

@ -106,7 +106,7 @@ timer_now(void)
* This is a very expensive function. Call before beginning measurements. * This is a very expensive function. Call before beginning measurements.
* Returns 0 upon a memory allocation error * Returns 0 upon a memory allocation error
*/ */
_Bool bool
timer_init(void) timer_init(void)
{ {
passive_timers = list_create(); passive_timers = list_create();
@ -128,7 +128,8 @@ timer_init(void)
if (a.vp == NULL) if (a.vp == NULL)
goto init_failure; goto init_failure;
list_push(passive_timers, a); if (list_push(passive_timers, a) == false)
goto init_failure;
} }
now = timer_now_forced(); now = timer_now_forced();
@ -138,7 +139,6 @@ timer_init(void)
init_failure: init_failure:
fprintf(stderr, "%s.%s: %s\n", __FILE__, __func__, strerror(errno)); fprintf(stderr, "%s.%s: %s\n", __FILE__, __func__, strerror(errno));
return false; return false;
} }
/* /*
@ -147,12 +147,9 @@ timer_init(void)
void void
timer_free_all(void) timer_free_all(void)
{ {
int count = 0;
while (!is_list_empty(passive_timers)) { while (!is_list_empty(passive_timers)) {
Any_Type a = list_pop(passive_timers); Any_Type a = list_pop(passive_timers);
free(a.vp); free(a.vp);
count++;
} }
list_free(passive_timers); list_free(passive_timers);
passive_timers = NULL; passive_timers = NULL;
@ -160,7 +157,6 @@ timer_free_all(void)
while (!is_list_empty(active_timers)) { while (!is_list_empty(active_timers)) {
Any_Type a = list_pop(active_timers); Any_Type a = list_pop(active_timers);
free(a.vp); free(a.vp);
count++;
} }
list_free(active_timers); list_free(active_timers);
active_timers = NULL; active_timers = NULL;
@ -168,13 +164,9 @@ timer_free_all(void)
while (!is_list_empty(persistent_timers)) { while (!is_list_empty(persistent_timers)) {
Any_Type a = list_pop(persistent_timers); Any_Type a = list_pop(persistent_timers);
free(a.vp); free(a.vp);
count++;
} }
list_free(persistent_timers); list_free(persistent_timers);
persistent_timers = NULL; persistent_timers = NULL;
if (DBG > 2)
fprintf(stderr, "Experiment used a total of %d counters\n", count);
} }
static int static int
@ -200,6 +192,7 @@ timer_deactivate(Any_Type a)
{ {
struct Timer *t = a.vp; struct Timer *t = a.vp;
/* TODO: Error check list_push */
if (t->has_expired == true) if (t->has_expired == true)
list_push(passive_timers, a); list_push(passive_timers, a);
@ -239,9 +232,11 @@ timer_schedule(void (*timeout) (struct Timer * t, Any_Type arg),
t->timeout_delay = delay; t->timeout_delay = delay;
if (delay > 0) if (delay > 0)
list_push(active_timers, (Any_Type) (void *) t); if (list_push(active_timers, (Any_Type) (void *) t) == false)
return false;
else else
list_push(persistent_timers, (Any_Type) (void *) t); if (list_push(persistent_timers, (Any_Type) (void *) t) == false)
return false;
if (DBG > 2) if (DBG > 2)
fprintf(stderr, fprintf(stderr,

Visa fil

@ -35,19 +35,19 @@
struct Timer; struct Timer;
typedef void (*Timer_Callback) (struct Timer * t, Any_Type arg); typedef void (*Timer_Callback) (struct Timer * t, Any_Type arg);
extern Time timer_now_forced(void); Time timer_now_forced(void);
extern Time timer_now(void); Time timer_now(void);
extern _Bool timer_init(void); bool timer_init(void);
extern void timer_reset_all(void); void timer_reset_all(void);
extern void timer_free_all(void); void timer_free_all(void);
/* /*
* Needs to be called at least once every TIMER_INTERVAL: * Needs to be called at least once every TIMER_INTERVAL:
*/ */
extern void timer_tick(void); void timer_tick(void);
extern struct Timer *timer_schedule(Timer_Callback timeout, Any_Type arg, struct Timer *timer_schedule(Timer_Callback timeout, Any_Type arg,
Time delay); Time delay);
extern void timer_cancel(struct Timer * t); void timer_cancel(struct Timer * t);
#endif /* timer_h */ #endif /* timer_h */