Prefix CONTAINER_OF with UC_
This commit is contained in:
@@ -46,14 +46,14 @@
|
|||||||
//a 'zap' member inside a struct foo.
|
//a 'zap' member inside a struct foo.
|
||||||
//give us the struct foo*:
|
//give us the struct foo*:
|
||||||
//struct foo *f = CONTAINER_OF(p, struct foo, zap);
|
//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); \
|
typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
(type *)((void *)(unsigned char *)__mptr - offsetof(type, member) ); })
|
(type *)((void *)(unsigned char *)__mptr - offsetof(type, member) ); })
|
||||||
|
|
||||||
//the void* cast is to suppress alignment warnings
|
//the void* cast is to suppress alignment warnings
|
||||||
|
|
||||||
//Same as CONTAINER_OF, but for a const pointer to avoid gcc warnings..
|
//Same as UC_CONTAINER_OF, but for a const pointer to avoid gcc warnings..
|
||||||
#define CONST_CONTAINER_OF(ptr, type, member) ({ \
|
#define UC_CONST_CONTAINER_OF(ptr, type, member) ({ \
|
||||||
const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
||||||
(const type *)((const void *)(const unsigned char *)__mptr - offsetof(const type, member) ); })
|
(const type *)((const void *)(const unsigned char *)__mptr - offsetof(const type, member) ); })
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -32,7 +32,7 @@ static void uc_cached_clock_now(struct UCoreClock *uclock,
|
|||||||
struct timeval *tv)
|
struct timeval *tv)
|
||||||
{
|
{
|
||||||
struct UCoreCachedClock *cached_clock;
|
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;
|
*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)
|
static void uc_settable_clock_now(struct UCoreClock *uclock, struct timeval *tv)
|
||||||
{
|
{
|
||||||
struct UCoreSettableClock *cached_clock;
|
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;
|
*tv = cached_clock->now;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-7
@@ -57,7 +57,9 @@ int uc_thread_queue_init(struct uc_threadqueue *queue, long max_elements)
|
|||||||
return rc;
|
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;
|
int rc = 0;
|
||||||
struct timespec abstimeout;
|
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) {
|
if(timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
|
||||||
rc = ETIMEDOUT;
|
rc = ETIMEDOUT;
|
||||||
} else {
|
} else {
|
||||||
rc = pthread_cond_timedwait(&queue->write_cond, &queue->mutex, &abstimeout);
|
rc = pthread_cond_timedwait(&queue->write_cond, &queue->mutex,
|
||||||
|
&abstimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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;
|
int rc = 0;
|
||||||
struct timespec abstimeout;
|
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) {
|
if(timeout->tv_sec == 0 && timeout->tv_nsec == 0) {
|
||||||
rc = ETIMEDOUT;
|
rc = ETIMEDOUT;
|
||||||
} else {
|
} else {
|
||||||
rc = pthread_cond_timedwait(&queue->read_cond, &queue->mutex, &abstimeout);
|
rc = pthread_cond_timedwait(&queue->read_cond, &queue->mutex,
|
||||||
|
&abstimeout);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pthread_cond_wait(&queue->read_cond, &queue->mutex);
|
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;
|
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 *p;
|
||||||
struct uc_threadmsg *next;
|
struct uc_threadmsg *next;
|
||||||
|
|
||||||
for(p = queue->first; p; p = next) {
|
for(p = queue->first; p; p = next) {
|
||||||
next = p->next;
|
next = p->next;
|
||||||
walk_func(p);
|
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) {
|
if (queue == NULL || !walk_func) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -217,7 +226,8 @@ int uc_thread_queue_walk(struct uc_threadqueue *queue, uc_thread_queue_walk_func
|
|||||||
return 0;
|
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;
|
int rc;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
static int timers_cmp(const RBNode *a_, const RBNode *b_)
|
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 *a = UC_CONST_CONTAINER_OF(a_, struct UCTimer, rb_node);
|
||||||
const struct UCTimer *b = CONST_CONTAINER_OF(b_, struct UCTimer, rb_node);
|
const struct UCTimer *b = UC_CONST_CONTAINER_OF(b_, struct UCTimer, rb_node);
|
||||||
|
|
||||||
if (timercmp(&a->timeout, &b->timeout, <)) {
|
if (timercmp(&a->timeout, &b->timeout, <)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ int diffts(const struct timespec *a, struct timespec *b)
|
|||||||
|
|
||||||
void timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
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;
|
int rc;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ START_TEST (test_container_of)
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Inner *innerp = &outer.inner;
|
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);
|
fail_if(outerp != &outer);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ void t2_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
|
|
||||||
void mystruct1_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);
|
TRACEF("MyStruct1 timer: %s\n", mystruct->str);
|
||||||
uc_timers_add(timers, timer, 1, 0);
|
uc_timers_add(timers, timer, 1, 0);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void peer_do_state(struct HBPeer *peer, enum PeerEvent event);
|
|||||||
|
|
||||||
void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
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;
|
struct HBContext *ctx = timer->cookie_ptr;
|
||||||
time_t now;
|
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)
|
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;
|
ssize_t rc;
|
||||||
struct sockaddr_in peer_addr;
|
struct sockaddr_in peer_addr;
|
||||||
socklen_t peer_len = sizeof peer_addr;
|
socklen_t peer_len = sizeof peer_addr;
|
||||||
|
|||||||
Reference in New Issue
Block a user