C: define many functions using predefine..

/* Defines COUNTER.  There must be exactly one such definition at file scope
 * within a program. */
#define COVERAGE_DEFINE(COUNTER)                                        \
        DEFINE_STATIC_PER_THREAD_DATA(unsigned int,                     \
                                      counter_##COUNTER, 0);            \
        static unsigned int COUNTER##_count(void)                       \
        {                                                               \
            unsigned int *countp = counter_##COUNTER##_get();           \
            unsigned int count = *countp;                               \
            *countp = 0;                                                \
            return count;                                               \
        }                                                               \
        static inline void COUNTER##_add(unsigned int n)                \
        {                                                               \
            *counter_##COUNTER##_get() += n;                            \
        }                                                               \
        extern struct coverage_counter counter_##COUNTER;               \
        struct coverage_counter counter_##COUNTER                       \
            = { #COUNTER, COUNTER##_count, 0, 0, {0}, {0} };            \
        OVS_CONSTRUCTOR(COUNTER##_init) {                               \
            coverage_counter_register(&counter_##COUNTER);              \
        }

 

posted on 2016-08-02 21:56  三叁  阅读(229)  评论(0)    收藏  举报

导航