Add a fps_meter_ prefix to macros master
authorAntonio Ospite <ospite@studenti.unina.it>
Tue, 17 Dec 2013 22:55:21 +0000 (23:55 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Tue, 17 Dec 2013 22:55:21 +0000 (23:55 +0100)
This plays more nicely when including files where other functions with the same names are defined.

fps-meter.c
fps-meter.h

index c1a245f..2d9ea6b 100644 (file)
@@ -27,7 +27,7 @@ int main(void)
        fps_meter_init(&stats);
        while (1) {
                /* simulate some workload of about 60fps */
        fps_meter_init(&stats);
        while (1) {
                /* simulate some workload of about 60fps */
-               dbg("Doing some work, which takes about %d ns", NSEC_PER_SEC / 60);
+               fps_meter_dbg("Doing some work, which takes about %d ns", NSEC_PER_SEC / 60);
                tmp.tv_sec = 0;
                tmp.tv_nsec = NSEC_PER_SEC / 60;
                clock_nanosleep(CLOCK_MONOTONIC, 0, &tmp, NULL);
                tmp.tv_sec = 0;
                tmp.tv_nsec = NSEC_PER_SEC / 60;
                clock_nanosleep(CLOCK_MONOTONIC, 0, &tmp, NULL);
index c756ab6..4b72180 100644 (file)
 #include <time.h>
 
 #ifdef DEBUG
 #include <time.h>
 
 #ifdef DEBUG
-#define dbg(...)                     \
+#define fps_meter_dbg(...)                     \
        do {                         \
                printf(__VA_ARGS__); \
                printf("\n");        \
                fflush(stdout);      \
        } while(0)
 #else
        do {                         \
                printf(__VA_ARGS__); \
                printf("\n");        \
                fflush(stdout);      \
        } while(0)
 #else
-#define dbg(...) do {} while(0)
+#define fps_meter_dbg(...) do {} while(0)
 #endif
 
 #define NSEC_PER_SEC 1000000000
 
 #endif
 
 #define NSEC_PER_SEC 1000000000
 
-#define timespecsub(a, b, result)                                \
+#define fps_meter_timespecsub(a, b, result)                                \
        do {                                                     \
                (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;    \
                (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
        do {                                                     \
                (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;    \
                (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
@@ -60,20 +60,20 @@ static void fps_meter_init(struct fps_meter_stats *stats)
        memset(stats, 0, sizeof(*stats));
 
        clock_gettime(CLOCK_MONOTONIC, &stats->time_start);
        memset(stats, 0, sizeof(*stats));
 
        clock_gettime(CLOCK_MONOTONIC, &stats->time_start);
-       dbg("Init time: s: %ld, ns: %ld", stats->time_start.tv_sec, stats->time_start.tv_nsec);
+       fps_meter_dbg("Init time: s: %ld, ns: %ld", stats->time_start.tv_sec, stats->time_start.tv_nsec);
 }
 
 static void fps_meter_update(struct fps_meter_stats *stats)
 {
        struct timespec elapsed;
 
 }
 
 static void fps_meter_update(struct fps_meter_stats *stats)
 {
        struct timespec elapsed;
 
-       dbg("Start time: s: %ld, ns: %ld", stats->time_start.tv_sec, stats->time_start.tv_nsec);
+       fps_meter_dbg("Start time: s: %ld, ns: %ld", stats->time_start.tv_sec, stats->time_start.tv_nsec);
 
        clock_gettime(CLOCK_MONOTONIC, &stats->time_end);
 
        clock_gettime(CLOCK_MONOTONIC, &stats->time_end);
-       dbg("End time: s: %ld, ns: %ld", stats->time_end.tv_sec, stats->time_end.tv_nsec);
+       fps_meter_dbg("End time: s: %ld, ns: %ld", stats->time_end.tv_sec, stats->time_end.tv_nsec);
 
 
-       timespecsub(&stats->time_end, &stats->time_start, &elapsed);
-       dbg("Elapsed s: %ld ns: %ld", elapsed.tv_sec, elapsed.tv_nsec);
+       fps_meter_timespecsub(&stats->time_end, &stats->time_start, &elapsed);
+       fps_meter_dbg("Elapsed s: %ld ns: %ld", elapsed.tv_sec, elapsed.tv_nsec);
 
        stats->frames++;
        stats->nsecs += (elapsed.tv_sec * NSEC_PER_SEC + elapsed.tv_nsec);
 
        stats->frames++;
        stats->nsecs += (elapsed.tv_sec * NSEC_PER_SEC + elapsed.tv_nsec);