From bcaf1d0eec491a9b01f52eb6c3a88a6463499e67 Mon Sep 17 00:00:00 2001 From: tedbullock Date: Fri, 16 Nov 2007 01:05:55 +0000 Subject: [PATCH] Use bool rather than int and _Bool --- httperf/src/httperf.c | 6 +++++- httperf/src/lib/list.c | 9 +++++---- httperf/src/lib/list.h | 4 ++-- httperf/src/timer.c | 21 ++++++++------------- httperf/src/timer.h | 16 ++++++++-------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/httperf/src/httperf.c b/httperf/src/httperf.c index 1038b19..ddb3003 100755 --- a/httperf/src/httperf.c +++ b/httperf/src/httperf.c @@ -1023,7 +1023,11 @@ main (int argc, char **argv) } printf ("\n"); - timer_init (); + if(timer_init() == false) + { + fprintf(stderr, "%s: timer_init(): failed initialization (%d)\n", prog_name, __LINE__); + exit(1); + } core_init (); signal (SIGINT, (void (*)()) core_exit); diff --git a/httperf/src/lib/list.c b/httperf/src/lib/list.c index a3082c4..706c5d0 100644 --- a/httperf/src/lib/list.c +++ b/httperf/src/lib/list.c @@ -43,7 +43,7 @@ struct List { struct Node *dummy_head; }; -int +bool is_list_empty(struct List *l) { @@ -80,7 +80,7 @@ list_free(struct List *l) free(l); } -int +bool list_push(struct List *l, Any_Type data) { 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 */ if ((n = malloc(sizeof(struct Node))) == NULL) { - return 0; + return false; } n->data = data; n->next = l->dummy_head->next; l->dummy_head->next = n; - return 1; + return true; } Any_Type @@ -151,3 +151,4 @@ list_for_each(struct List *l, int (*action) (Any_Type)) n = n->next; } } + diff --git a/httperf/src/lib/list.h b/httperf/src/lib/list.h index 676c3a7..4ac8a71 100644 --- a/httperf/src/lib/list.h +++ b/httperf/src/lib/list.h @@ -37,8 +37,8 @@ struct List; struct List *list_create(); void list_free(struct List *); -void list_push(struct List *, Any_Type); -int is_list_empty(struct List *); +bool list_push(struct List *, Any_Type); +bool is_list_empty(struct List *); Any_Type list_top(struct List *); Any_Type list_pop(struct List *); void list_remove_if_true(struct List *, list_action); diff --git a/httperf/src/timer.c b/httperf/src/timer.c index a485c74..96e5f15 100755 --- a/httperf/src/timer.c +++ b/httperf/src/timer.c @@ -106,7 +106,7 @@ timer_now(void) * This is a very expensive function. Call before beginning measurements. * Returns 0 upon a memory allocation error */ -_Bool +bool timer_init(void) { passive_timers = list_create(); @@ -128,7 +128,8 @@ timer_init(void) if (a.vp == NULL) goto init_failure; - list_push(passive_timers, a); + if (list_push(passive_timers, a) == false) + goto init_failure; } now = timer_now_forced(); @@ -138,7 +139,6 @@ timer_init(void) init_failure: fprintf(stderr, "%s.%s: %s\n", __FILE__, __func__, strerror(errno)); return false; - } /* @@ -147,12 +147,9 @@ timer_init(void) void timer_free_all(void) { - int count = 0; - while (!is_list_empty(passive_timers)) { Any_Type a = list_pop(passive_timers); free(a.vp); - count++; } list_free(passive_timers); passive_timers = NULL; @@ -160,7 +157,6 @@ timer_free_all(void) while (!is_list_empty(active_timers)) { Any_Type a = list_pop(active_timers); free(a.vp); - count++; } list_free(active_timers); active_timers = NULL; @@ -168,13 +164,9 @@ timer_free_all(void) while (!is_list_empty(persistent_timers)) { Any_Type a = list_pop(persistent_timers); free(a.vp); - count++; } list_free(persistent_timers); persistent_timers = NULL; - - if (DBG > 2) - fprintf(stderr, "Experiment used a total of %d counters\n", count); } static int @@ -200,6 +192,7 @@ timer_deactivate(Any_Type a) { struct Timer *t = a.vp; + /* TODO: Error check list_push */ if (t->has_expired == true) list_push(passive_timers, a); @@ -239,9 +232,11 @@ timer_schedule(void (*timeout) (struct Timer * t, Any_Type arg), t->timeout_delay = delay; if (delay > 0) - list_push(active_timers, (Any_Type) (void *) t); + if (list_push(active_timers, (Any_Type) (void *) t) == false) + return false; else - list_push(persistent_timers, (Any_Type) (void *) t); + if (list_push(persistent_timers, (Any_Type) (void *) t) == false) + return false; if (DBG > 2) fprintf(stderr, diff --git a/httperf/src/timer.h b/httperf/src/timer.h index 0c2b916..9f297df 100755 --- a/httperf/src/timer.h +++ b/httperf/src/timer.h @@ -35,19 +35,19 @@ struct Timer; typedef void (*Timer_Callback) (struct Timer * t, Any_Type arg); -extern Time timer_now_forced(void); -extern Time timer_now(void); +Time timer_now_forced(void); +Time timer_now(void); -extern _Bool timer_init(void); -extern void timer_reset_all(void); -extern void timer_free_all(void); +bool timer_init(void); +void timer_reset_all(void); +void timer_free_all(void); /* * 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); -extern void timer_cancel(struct Timer * t); +void timer_cancel(struct Timer * t); #endif /* timer_h */