From dd517a5d85600bc62bdcf98efa9d64dbe495bb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sat, 28 Sep 2013 23:45:51 +0200 Subject: [PATCH] Prefix CONTAINER_OF with UC_ --- include/ucore/utils.h | 6 +++--- src/clock.c | 4 ++-- src/threadqueue.c | 24 +++++++++++++++++------- src/timers.c | 4 ++-- test/ortp-send-simple.c | 2 +- test/test_containerof.c | 2 +- test/timers.c | 2 +- test/udp_heartbeat.c | 4 ++-- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/ucore/utils.h b/include/ucore/utils.h index aad8379..26d706e 100644 --- a/include/ucore/utils.h +++ b/include/ucore/utils.h @@ -46,14 +46,14 @@ //a 'zap' member inside a struct foo. //give us the struct foo*: //struct foo *f = CONTAINER_OF(p, struct foo, zap); -#define CONTAINER_OF(ptr, type, member) ({ \ +#define UC_CONTAINER_OF(ptr, type, member) ({ \ typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)((void *)(unsigned char *)__mptr - offsetof(type, member) ); }) //the void* cast is to suppress alignment warnings -//Same as CONTAINER_OF, but for a const pointer to avoid gcc warnings.. -#define CONST_CONTAINER_OF(ptr, type, member) ({ \ +//Same as UC_CONTAINER_OF, but for a const pointer to avoid gcc warnings.. +#define UC_CONST_CONTAINER_OF(ptr, type, member) ({ \ const typeof( ((const type *)0)->member ) *__mptr = (ptr); \ (const type *)((const void *)(const unsigned char *)__mptr - offsetof(const type, member) ); }) diff --git a/src/clock.c b/src/clock.c index 3e3e309..aeb0538 100644 --- a/src/clock.c +++ b/src/clock.c @@ -32,7 +32,7 @@ static void uc_cached_clock_now(struct UCoreClock *uclock, struct timeval *tv) { struct UCoreCachedClock *cached_clock; - cached_clock = CONTAINER_OF(uclock, struct UCoreCachedClock, clock), + cached_clock = UC_CONTAINER_OF(uclock, struct UCoreCachedClock, clock), *tv = cached_clock->cache; } @@ -55,7 +55,7 @@ void uc_cached_clock_update(struct UCoreCachedClock *uclock) static void uc_settable_clock_now(struct UCoreClock *uclock, struct timeval *tv) { struct UCoreSettableClock *cached_clock; - cached_clock = CONTAINER_OF(uclock, struct UCoreSettableClock, clock), + cached_clock = UC_CONTAINER_OF(uclock, struct UCoreSettableClock, clock), *tv = cached_clock->now; } diff --git a/src/threadqueue.c b/src/threadqueue.c index 14d087d..47308df 100644 --- a/src/threadqueue.c +++ b/src/threadqueue.c @@ -57,7 +57,9 @@ int uc_thread_queue_init(struct uc_threadqueue *queue, long max_elements) return rc; } -int uc_thread_queue_tryadd(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg *msg) +int uc_thread_queue_tryadd(struct uc_threadqueue *queue, + const struct timespec *timeout, + struct uc_threadmsg *msg) { int rc = 0; struct timespec abstimeout; @@ -81,7 +83,8 @@ int uc_thread_queue_tryadd(struct uc_threadqueue *queue, const struct timespec * if(timeout->tv_sec == 0 && timeout->tv_nsec == 0) { rc = ETIMEDOUT; } else { - rc = pthread_cond_timedwait(&queue->write_cond, &queue->mutex, &abstimeout); + rc = pthread_cond_timedwait(&queue->write_cond, &queue->mutex, + &abstimeout); } } else { @@ -127,7 +130,9 @@ int uc_thread_queue_tryadd(struct uc_threadqueue *queue, const struct timespec * } -int uc_thread_queue_tryget(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg **msg) +int uc_thread_queue_tryget(struct uc_threadqueue *queue, + const struct timespec *timeout, + struct uc_threadmsg **msg) { int rc = 0; struct timespec abstimeout; @@ -153,7 +158,8 @@ int uc_thread_queue_tryget(struct uc_threadqueue *queue, const struct timespec * if(timeout->tv_sec == 0 && timeout->tv_nsec == 0) { rc = ETIMEDOUT; } else { - rc = pthread_cond_timedwait(&queue->read_cond, &queue->mutex, &abstimeout); + rc = pthread_cond_timedwait(&queue->read_cond, &queue->mutex, + &abstimeout); } } else { pthread_cond_wait(&queue->read_cond, &queue->mutex); @@ -192,17 +198,20 @@ int uc_thread_queue_tryget(struct uc_threadqueue *queue, const struct timespec * return 0; } -static void uc_thread_queue_walk_unlocked(struct uc_threadqueue *queue, uc_thread_queue_walk_func walk_func) +static void uc_thread_queue_walk_unlocked(struct uc_threadqueue *queue, + uc_thread_queue_walk_func walk_func) { struct uc_threadmsg *p; struct uc_threadmsg *next; + for(p = queue->first; p; p = next) { next = p->next; walk_func(p); } } -int uc_thread_queue_walk(struct uc_threadqueue *queue, uc_thread_queue_walk_func walk_func) +int uc_thread_queue_walk(struct uc_threadqueue *queue, + uc_thread_queue_walk_func walk_func) { if (queue == NULL || !walk_func) { return EINVAL; @@ -217,7 +226,8 @@ int uc_thread_queue_walk(struct uc_threadqueue *queue, uc_thread_queue_walk_func return 0; } -int uc_thread_queue_destroy(struct uc_threadqueue *queue, uc_thread_queue_walk_func free_func) +int uc_thread_queue_destroy(struct uc_threadqueue *queue, + uc_thread_queue_walk_func free_func) { int rc; diff --git a/src/timers.c b/src/timers.c index ed399dc..872a21b 100644 --- a/src/timers.c +++ b/src/timers.c @@ -6,8 +6,8 @@ static int timers_cmp(const RBNode *a_, const RBNode *b_) { - const struct UCTimer *a = CONST_CONTAINER_OF(a_, struct UCTimer, rb_node); - const struct UCTimer *b = CONST_CONTAINER_OF(b_, struct UCTimer, rb_node); + const struct UCTimer *a = UC_CONST_CONTAINER_OF(a_, struct UCTimer, rb_node); + const struct UCTimer *b = UC_CONST_CONTAINER_OF(b_, struct UCTimer, rb_node); if (timercmp(&a->timeout, &b->timeout, <)) { return -1; diff --git a/test/ortp-send-simple.c b/test/ortp-send-simple.c index 7f27b18..681a038 100644 --- a/test/ortp-send-simple.c +++ b/test/ortp-send-simple.c @@ -43,7 +43,7 @@ int diffts(const struct timespec *a, struct timespec *b) void timer_cb(struct UCTimers *timers, struct UCTimer *timer) { - struct RTPSender *s = CONTAINER_OF(timer, struct RTPSender, timer); + struct RTPSender *s = UC_CONTAINER_OF(timer, struct RTPSender, timer); int rc; ssize_t r; struct timespec ts; diff --git a/test/test_containerof.c b/test/test_containerof.c index f8db97b..b0cc868 100644 --- a/test/test_containerof.c +++ b/test/test_containerof.c @@ -25,7 +25,7 @@ START_TEST (test_container_of) }; struct Inner *innerp = &outer.inner; - struct Outer *outerp = CONTAINER_OF(innerp, struct Outer, inner); + struct Outer *outerp = UC_CONTAINER_OF(innerp, struct Outer, inner); fail_if(outerp != &outer); diff --git a/test/timers.c b/test/timers.c index a708b77..9ff5af9 100644 --- a/test/timers.c +++ b/test/timers.c @@ -22,7 +22,7 @@ void t2_cb(struct UCTimers *timers, struct UCTimer *timer) void mystruct1_cb(struct UCTimers *timers, struct UCTimer *timer) { - struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer); + struct MyStruct *mystruct = UC_CONTAINER_OF(timer, struct MyStruct, timer); TRACEF("MyStruct1 timer: %s\n", mystruct->str); uc_timers_add(timers, timer, 1, 0); diff --git a/test/udp_heartbeat.c b/test/udp_heartbeat.c index 5fc0ae3..4eb3847 100644 --- a/test/udp_heartbeat.c +++ b/test/udp_heartbeat.c @@ -70,7 +70,7 @@ void peer_do_state(struct HBPeer *peer, enum PeerEvent event); void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer) { - struct HBPeer *peer = CONTAINER_OF(timer, struct HBPeer, timer); + struct HBPeer *peer = UC_CONTAINER_OF(timer, struct HBPeer, timer); struct HBContext *ctx = timer->cookie_ptr; time_t now; @@ -181,7 +181,7 @@ void peer_received(struct HBPeer *peer) void hb_read(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event) { - struct HBContext *ctx = CONTAINER_OF(fd, struct HBContext, sock_fd); + struct HBContext *ctx = UC_CONTAINER_OF(fd, struct HBContext, sock_fd); ssize_t rc; struct sockaddr_in peer_addr; socklen_t peer_len = sizeof peer_addr;