Commit 7d60763b authored by William Ahern's avatar William Ahern

fix MAX bug and debug format string allocation

parent 2c55edda
...@@ -26,12 +26,11 @@ ...@@ -26,12 +26,11 @@
#include <limits.h> /* CHAR_BIT */ #include <limits.h> /* CHAR_BIT */
#include <stddef.h> /* NULL */ #include <stddef.h> /* NULL */
#include <stdint.h> /* UINT64_C uint64_t */ #include <inttypes.h> /* UINT64_C uint64_t */
#include <string.h> #include <string.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/param.h>
#include "timer.h" #include "timer.h"
...@@ -94,7 +93,7 @@ static inline char *fmt_(char *buf, uint64_t ts, int wheel_bit, int wheel_num) { ...@@ -94,7 +93,7 @@ static inline char *fmt_(char *buf, uint64_t ts, int wheel_bit, int wheel_num) {
return buf; return buf;
} /* fmt_() */ } /* fmt_() */
#define fmt(ts) fmt_(((char[(1 << WHEEL_BIT) + WHEEL_NUM + 1]){ 0 }), (ts), WHEEL_BIT, WHEEL_NUM) #define fmt(ts) fmt_(((char[((1 << WHEEL_BIT) * WHEEL_NUM) + WHEEL_NUM + 1]){ 0 }), (ts), WHEEL_BIT, WHEEL_NUM)
static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) { static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) {
...@@ -110,7 +109,7 @@ static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) { ...@@ -110,7 +109,7 @@ static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) {
return buf; return buf;
} /* bin64_() */ } /* bin64_() */
#define bin64(ts) bin64_(((char[(1 << WHEEL_BIT) + 1]){ 0 }), (ts), WHEEL_BIT) #define bin64(ts) bin64_(((char[((1 << WHEEL_BIT) * WHEEL_NUM) + 1]){ 0 }), (ts), WHEEL_BIT)
/* /*
...@@ -125,6 +124,10 @@ static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) { ...@@ -125,6 +124,10 @@ static inline char *bin64_(char *buf, uint64_t n, int wheel_bit) {
#define MIN(a, b) (((a) < (b))? (a) : (b)) #define MIN(a, b) (((a) < (b))? (a) : (b))
#endif #endif
#if !defined MAX
#define MAX(a, b) (((a) > (b))? (a) : (b))
#endif
#define CIRCLEQ_CONCAT(head1, head2, field) do { \ #define CIRCLEQ_CONCAT(head1, head2, field) do { \
if (!CIRCLEQ_EMPTY(head2)) { \ if (!CIRCLEQ_EMPTY(head2)) { \
if (!CIRCLEQ_EMPTY(head1)) { \ if (!CIRCLEQ_EMPTY(head1)) { \
...@@ -369,10 +372,10 @@ void timer_step(struct timer *T, timer_t curtime) { ...@@ -369,10 +372,10 @@ void timer_step(struct timer *T, timer_t curtime) {
CIRCLEQ_INIT(&todo); CIRCLEQ_INIT(&todo);
SAY("\n"); SAYit(2, "\n");
SAY("== step ========================================="); SAYit(2, "== step =========================================");
SAY("%" TIMER_PRIu " -> %" TIMER_PRIu, T->curtime, curtime); SAYit(2, "%" TIMER_PRIu " -> %" TIMER_PRIu, T->curtime, curtime);
SAY("%s -> %s", fmt(T->curtime), fmt(curtime)); SAYit(2, "%s -> %s", fmt(T->curtime), fmt(curtime));
for (wheel = 0; wheel < WHEEL_NUM; wheel++) { for (wheel = 0; wheel < WHEEL_NUM; wheel++) {
wheel_t pending; wheel_t pending;
...@@ -487,7 +490,7 @@ static timer_t timer_min(struct timer *T) { ...@@ -487,7 +490,7 @@ static timer_t timer_min(struct timer *T) {
for (i = 0; i < countof(T->wheel); i++) { for (i = 0; i < countof(T->wheel); i++) {
for (j = 0; j < countof(T->wheel[i]); j++) { for (j = 0; j < countof(T->wheel[i]); j++) {
CIRCLEQ_FOREACH(to, &T->wheel[i][j], cqe) { CIRCLEQ_FOREACH(to, &T->wheel[i][j], cqe) {
if (!min || min->expires > to->expires) if (!min || to->expires < min->expires)
min = to; min = to;
} }
} }
...@@ -548,10 +551,8 @@ int main(int argc, char **argv) { ...@@ -548,10 +551,8 @@ int main(int argc, char **argv) {
while (count > 0 && time <= stop - 1) { while (count > 0 && time <= stop - 1) {
time += step; time += step;
//printf("step: %llu\n", time);
SAY("timeout -> %" TIMEOUT_PRIu " (actual:%" TIMEOUT_PRIu " curtime:%" TIMER_PRIu ")", timer_timeout(&T), slow_timeout(&T), T.curtime); SAY("timeout -> %" TIMEOUT_PRIu " (actual:%" TIMEOUT_PRIu " curtime:%" TIMER_PRIu ")", timer_timeout(&T), slow_timeout(&T), T.curtime);
timer_step(&T, time); timer_step(&T, time);
//SAY("timeout <- %" TIMEOUT_PRIu " (curtime:%" TIMER_PRIu ")", timer_timeout(&T), T.curtime);
while ((expired = timer_get(&T))) { while ((expired = timer_get(&T))) {
timer_del(&T, expired); timer_del(&T, expired);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment