Use bool rather than int and _Bool
This commit is contained in:
부모
447ad7b739
커밋
bcaf1d0eec
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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 */
|
||||
|
불러오는 중...
Reference in New Issue
Block a user