diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-12 22:02:37 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-12 22:02:37 +0200 |
commit | 44692b7e7a7134f64d6c0a70b5075b466471a152 (patch) | |
tree | 3f804571d5d6f2313a8361e9bb90e22ee3e89e1c | |
parent | 9146a7916188097c765b90c170da6400b0717bd4 (diff) | |
download | librb-44692b7e7a7134f64d6c0a70b5075b466471a152.tar.gz librb-44692b7e7a7134f64d6c0a70b5075b466471a152.tar.bz2 librb-44692b7e7a7134f64d6c0a70b5075b466471a152.zip |
fix: compiler warning from -ansi flag
-rw-r--r-- | rb.c | 237 |
1 files changed, 121 insertions, 116 deletions
@@ -21,10 +21,16 @@ # include <syscall.h> # include <unistd.h> -# define trace(x, ...) fprintf(stderr, "[%s:%d:%s():%ld] " x "\n", \ - __FILE__, __LINE__, __func__, syscall(SYS_gettid), ##__VA_ARGS__) +# define trace(x) do \ + { \ + printf("[%s:%d:%s():%ld]" , __FILE__, __LINE__, __func__, \ + syscall(SYS_gettid)); \ + printf x ; \ + printf("\n"); \ + } \ + while (0) #else -# define trace(x, ...) +# define trace(x) #endif #if HAVE_CONFIG_H @@ -244,6 +250,7 @@ static int rb_is_power_of_two static void rb_sigaction(int signum) { + (void)signum; return; } @@ -311,7 +318,7 @@ static int rb_add_blocked_thread memset(rb->blocked_threads + rb->max_blocked / 2, 0x00, rb->max_blocked / 2 * sizeof(struct blocked_threads)); - trace("i/increase blocked size; new size is %d", rb->max_blocked); + trace(("i/increase blocked size; new size is %d", rb->max_blocked)); } /* @@ -340,7 +347,7 @@ static int rb_add_blocked_thread rb->blocked_threads[i].thread = pthread_self(); rb->blocked_threads[i].valid = 1; rb->curr_blocked++; - trace("i/slots used: %d, max %d", rb->curr_blocked, rb->max_blocked); + trace(("i/slots used: %d, max %d", rb->curr_blocked, rb->max_blocked)); return 0; } @@ -395,7 +402,7 @@ static int rb_del_blocked_thread rb->blocked_threads[i].valid = 0; rb->curr_blocked--; - trace("i/slots used %d max %d", rb->curr_blocked, rb->max_blocked); + trace(("i/used %d max %d", rb->curr_blocked, rb->max_blocked)); return 0; } } @@ -563,7 +570,7 @@ static long rb_recvs long w; /* number of bytes wrote with write() */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - trace("i/fd: %d, count: %zu, flags: %lu", fd, count, flags); + trace(("i/fd: %d, count: %zu, flags: %lu", fd, count, flags)); if (count > (rbcount = rb_count_ns(rb))) { @@ -576,7 +583,7 @@ static long rb_recvs if (count == 0) { - trace("e/eagain"); + trace(("e/eagain")); errno = EAGAIN; return -1; } @@ -614,7 +621,7 @@ static long rb_recvs rb->tail &= rb->count - 1; } - trace("i/ret %zu", count); + trace(("i/ret %zu", count)); return count; #if ENABLE_POSIX_CALLS @@ -638,7 +645,7 @@ static long rb_recvs w = rb_nb_write(fd, rb->buffer + rb->tail * objsize, objsize * cnte); if (w == -1) { - trace("e/write() %s", strerror(errno)); + trace(("e/write() %s", strerror(errno))); return -1; } @@ -650,7 +657,7 @@ static long rb_recvs tw = w / objsize; - if (tw != cnte) + if ((size_t)tw != cnte) { /* * write() returned less bytes than we wanted, looks like fd @@ -660,20 +667,20 @@ static long rb_recvs rb->tail += flags & MSG_PEEK ? 0 : tw; rb->tail &= rb->count - 1; - trace("i/ret %lu", tw); + trace(("i/ret %lu", tw)); return tw; } w = rb_nb_write(fd, rb->buffer, (count - cnte) * objsize); if (w == -1) { - trace("e/write() %s", strerror(errno)); + trace(("e/write() %s", strerror(errno))); return -1; } tw += w / objsize; rb->tail = flags & MSG_PEEK ? rb->tail : w / objsize; - trace("i/ret %lu", tw); + trace(("i/ret %lu", tw)); return tw; } @@ -684,13 +691,13 @@ static long rb_recvs w = rb_nb_write(fd, rb->buffer + rb->tail * objsize, count * objsize); if (w == -1) { - trace("e/write() %s", strerror(errno)); + trace(("e/write() %s", strerror(errno))); return -1; } rb->tail += flags & MSG_PEEK ? 0 : w / objsize; rb->tail &= rb->count - 1; - trace("i/ret %zu", w / objsize); + trace(("i/ret %zu", w / objsize)); return w / objsize; #endif /* ENABLE_POSIX_CALLS */ @@ -740,9 +747,9 @@ static long rb_recvt * bad when reading full packets */ - trace("i/read lock"); + trace(("i/read lock")); pthread_mutex_lock(&rb->rlock); - trace("i/fd: %d, count: %zu, flags: %lu", fd, count, flags); + trace(("i/fd: %d, count: %zu, flags: %lu", fd, count, flags)); while (count) { size_t count_to_end; @@ -751,7 +758,7 @@ static long rb_recvt /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); while (rb_count_ns(rb) == 0 && rb->force_exit == 0) @@ -768,9 +775,9 @@ static long rb_recvt if (rb->flags & O_NONBLOCK || flags & MSG_DONTWAIT) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); + trace(("read unlock")); if (r == 0) { @@ -779,7 +786,7 @@ static long rb_recvt * this is how standard posix read/send works */ - trace("e/eagain"); + trace(("e/eagain")); errno = EAGAIN; return -1; } @@ -814,10 +821,10 @@ static long rb_recvt */ pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); - trace("i/force exit"); + trace(("read unlock")); + trace(("i/force exit")); return -1; } @@ -865,7 +872,7 @@ static long rb_recvt } pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); tv.tv_sec = 0; tv.tv_usec = 0; @@ -882,36 +889,36 @@ static long rb_recvt sact = select(fd + 1, NULL, &fds, NULL, NULL); } - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); rb_del_blocked_thread(rb); if (sact == -1) { - trace("e/select() %s", strerror(errno)); + trace(("e/select() %s", strerror(errno))); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); return -1; } if (sact == 0) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (rb->flags & O_NONBLOCK || flags & MSG_DONTWAIT) { pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); + trace(("read unlock")); if (r == 0) { - trace("w/select() timeout, eagain"); + trace(("w/select() timeout, eagain")); errno = EAGAIN; return -1; } - trace("i/select() timeout, ret %zu", r); + trace(("i/select() timeout, ret %zu", r)); return r; } @@ -923,9 +930,9 @@ static long rb_recvt if (w == -1) { - trace("e/write() %s", strerror(errno)); + trace(("e/write() %s", strerror(errno))); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (errno == EAGAIN) { @@ -939,8 +946,8 @@ static long rb_recvt */ pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); - trace("i/ret %zu", r ? r : -1); + trace(("read unlock")); + trace(("i/ret %zu", r ? r : -1)); return r ? r : -1; } @@ -961,8 +968,8 @@ static long rb_recvt */ pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); - trace("i/ret %zu", r ? r : -1); + trace(("read unlock")); + trace(("i/ret %zu", r ? r : -1)); return r ? r : -1; } @@ -992,12 +999,12 @@ static long rb_recvt pthread_cond_signal(&rb->wait_room); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } pthread_mutex_unlock(&rb->rlock); - trace("read unlock"); - trace("i/ret %zu", r); + trace(("read unlock")); + trace(("i/ret %zu", r)); return r; } @@ -1033,7 +1040,7 @@ static long rb_sends /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ (void)flags; - trace("i/fd: %d, count: %zu, flags: %lu", fd, count, flags); + trace(("i/fd: %d, count: %zu, flags: %lu", fd, count, flags)); if (count > (rbspace = rb_space_ns(rb))) { @@ -1046,7 +1053,7 @@ static long rb_sends if (count == 0) { - trace("e/eagain"); + trace(("e/eagain")); errno = EAGAIN; return -1; } @@ -1083,7 +1090,7 @@ static long rb_sends rb->head &= rb->count - 1; } - trace("i/ret %zu", count); + trace(("i/ret %zu", count)); return count; #if ENABLE_POSIX_CALLS @@ -1104,7 +1111,7 @@ static long rb_sends if (r == -1) { - trace("e/read() %s", strerror(errno)); + trace(("e/read() %s", strerror(errno))); return -1; } @@ -1116,7 +1123,7 @@ static long rb_sends tr = r / objsize; - if (tr != spce) + if ((size_t)tr != spce) { /* * read() returned less bytes than we wanted, fd is empty, no @@ -1125,7 +1132,7 @@ static long rb_sends rb->head += tr; rb->head &= rb->count -1; - trace("i/ret %ld", tr); + trace(("i/ret %ld", tr)); return tr; } @@ -1133,7 +1140,7 @@ static long rb_sends if (r == -1) { - trace("e/read() %s", strerror(errno)); + trace(("e/read() %s", strerror(errno))); return -1; } @@ -1149,7 +1156,7 @@ static long rb_sends * and we return number of elements totaly read from read() */ - trace("i/ret %ld", tr); + trace(("i/ret %ld", tr)); return tr; } @@ -1162,13 +1169,13 @@ static long rb_sends if (r == -1) { - trace("e/read() %s", strerror(errno)); + trace(("e/read() %s", strerror(errno))); return -1; } rb->head += r / objsize; rb->head &= rb->count -1; - trace("i/ret %zu", r / objsize); + trace(("i/ret %zu", r / objsize)); return r / objsize; #endif /* ENABLE_POSIX_CALLS */ @@ -1208,8 +1215,8 @@ long rb_sendt w = 0; buf = buffer; - trace("i/fd: %d, count: %zu, flags: %lu", fd, count, flags); - trace("i/write lock"); + trace(("i/fd: %d, count: %zu, flags: %lu", fd, count, flags)); + trace(("i/write lock")); pthread_mutex_lock(&rb->wlock); while (count) @@ -1220,7 +1227,7 @@ long rb_sendt /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); while (rb_space_ns(rb) == 0 && rb->force_exit == 0) @@ -1237,9 +1244,9 @@ long rb_sendt if (rb->flags & O_NONBLOCK || flags & MSG_DONTWAIT) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); + trace(("i/write unlock")); if (w == 0) { @@ -1252,7 +1259,7 @@ long rb_sendt return -1; } - trace("i/ret %zu", w); + trace(("i/ret %zu", w)); return w; } @@ -1284,10 +1291,10 @@ long rb_sendt */ pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); - trace("i/force exit"); + trace(("i/write unlock")); + trace(("i/force exit")); return -1; } @@ -1348,7 +1355,7 @@ long rb_sendt */ pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); tv.tv_sec = 0; tv.tv_usec = 0; @@ -1373,17 +1380,17 @@ long rb_sendt sact = select(fd + 1, &fds, NULL, NULL, NULL); } - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); rb_del_blocked_thread(rb); if (sact == -1) { - trace("e/select() %s", strerror(errno)); + trace(("e/select() %s", strerror(errno))); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); + trace(("i/write unlock")); return -1; } @@ -1394,12 +1401,12 @@ long rb_sendt */ pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (rb->flags & O_NONBLOCK || flags & MSG_DONTWAIT) { pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); + trace(("i/write unlock")); /* * in non blocking mode, we return what has been already @@ -1409,11 +1416,11 @@ long rb_sendt if (w == 0) { errno = EAGAIN; - trace("w/select() timeout, eagain"); + trace(("w/select() timeout, eagain")); return -1; } - trace("i/select() timeout, return %zu", w); + trace(("i/select() timeout, return %zu", w)); return w; } @@ -1460,7 +1467,7 @@ long rb_sendt if (r == -1) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (errno == EAGAIN) { @@ -1474,8 +1481,8 @@ long rb_sendt */ pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); - trace("w/read() eagain, ret: %zu", w ? w : -1); + trace(("i/write unlock")); + trace(("w/read() eagain, ret: %zu", w ? w : -1)); return w ? w : -1; } @@ -1496,8 +1503,8 @@ long rb_sendt */ pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); - trace("e/read() %s, ret: %zu", strerror(errno), w ? w : -1); + trace(("i/write unlock")); + trace(("e/read() %s, ret: %zu", strerror(errno), w ? w : -1)); return w ? w : -1; } @@ -1527,12 +1534,12 @@ long rb_sendt pthread_cond_signal(&rb->wait_data); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } pthread_mutex_unlock(&rb->wlock); - trace("i/write unlock"); - trace("i/ret %zu", w); + trace(("i/write unlock")); + trace(("i/ret %zu", w)); return w; } @@ -1565,13 +1572,13 @@ static void *rb_stop_thread rb = arg; stopped = 0; - trace("starting"); + trace(("starting")); - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); rb->force_exit = 1; pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); # if ENABLE_POSIX_CALLS @@ -1600,7 +1607,7 @@ static void *rb_stop_thread * save his sorry ass by installing default sigaction. */ - trace("e/sigaction() %s", strerror(errno)); + trace(("e/sigaction() %s", strerror(errno))); sigaction(SIGUSR1, &sa, &osa); } @@ -1614,7 +1621,7 @@ static void *rb_stop_thread while (stopped != 1) { - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); pthread_cond_signal(&rb->wait_data); pthread_cond_signal(&rb->wait_room); @@ -1632,7 +1639,7 @@ static void *rb_stop_thread if (now != prev) { prev = now; - trace("i/sending kill"); + trace(("i/sending kill")); for (i = 0; i != rb->max_blocked; ++i) { if (rb->curr_blocked == 0) @@ -1660,7 +1667,7 @@ static void *rb_stop_thread # endif /* ENABLE_POSIX_CALLS */ pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } # if ENABLE_POSIX_CALLS @@ -1681,7 +1688,7 @@ static void *rb_stop_thread # endif /* ENABLE_POSIX_CALLS */ - trace("return NULL"); + trace(("return NULL")); return NULL; } @@ -1707,7 +1714,7 @@ static int rb_init_p #endif VALID(EINVAL, rb_is_power_of_two(count) == 1); - trace("init rb %p", rb); + trace(("count: %zu, objsize: %zu, flags: %lu", count, object_size, flags)); rb->head = 0; rb->tail = 0; @@ -1805,7 +1812,7 @@ static int rb_cleanup_p * caller made sure all threads are stopped before calling destroy. */ - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); # if ENABLE_POSIX_CALLS @@ -1818,13 +1825,13 @@ static int rb_cleanup_p { rb->stopped_all = 1; pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); pthread_join(rb->stop_thread, NULL); } else { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } pthread_cond_destroy(&rb->wait_data); @@ -1974,17 +1981,17 @@ long rb_recv return rb_recvs(rb, buffer, -1, count, flags); } - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); if (rb->force_exit) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); errno = ECANCELED; return -1; } pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (flags & MSG_PEEK) { @@ -1994,11 +2001,11 @@ long rb_recv * deadlock */ - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); count = rb_recvs(rb, buffer, -1, count, flags); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); return count; } @@ -2052,18 +2059,17 @@ long rb_fd_recv return rb_recvs(rb, NULL, fd, count, flags); } - //VALID(EINVAL, rb->object_size == 1); - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); if (rb->force_exit) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); errno = ECANCELED; return -1; } pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); if (flags & MSG_PEEK) { @@ -2073,11 +2079,11 @@ long rb_fd_recv * deadlock */ - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); count = rb_recvs(rb, NULL, fd, count, flags); pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); return count; } @@ -2152,17 +2158,17 @@ long rb_send return rb_sends(rb, buffer, -1, count, flags); } - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); if (rb->force_exit) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); errno = ECANCELED; return -1; } pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); return rb_sendt(rb, buffer, -1, count, flags); #else @@ -2214,18 +2220,17 @@ long rb_fd_send return rb_sends(rb, NULL, fd, count, flags); } - //VALID(EINVAL, rb->object_size == 1); - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); if (rb->force_exit) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); errno = ECANCELED; return -1; } pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); return rb_sendt(rb, NULL, fd, count, flags); @@ -2265,7 +2270,7 @@ int rb_clear #if ENABLE_THREADS if ((rb->flags & O_NONBLOCK) == 0) { - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); } #endif @@ -2282,7 +2287,7 @@ int rb_clear if ((rb->flags & O_NONBLOCK) == 0) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } #endif @@ -2408,7 +2413,7 @@ long rb_discard #if ENABLE_THREADS if ((rb->flags & O_NONBLOCK) == 0) { - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); } #endif @@ -2435,7 +2440,7 @@ long rb_discard if ((rb->flags & O_NONBLOCK) == 0) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } #endif @@ -2491,7 +2496,7 @@ long rb_count #if ENABLE_THREADS if ((rb->flags & O_NONBLOCK) == 0) { - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); } #endif @@ -2502,7 +2507,7 @@ long rb_count if ((rb->flags & O_NONBLOCK) == 0) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } #endif @@ -2530,7 +2535,7 @@ long rb_space #if ENABLE_THREADS if ((rb->flags & O_NONBLOCK) == 0) { - trace("i/rb lock"); + trace(("i/rb lock")); pthread_mutex_lock(&rb->lock); } #endif @@ -2541,7 +2546,7 @@ long rb_space if ((rb->flags & O_NONBLOCK) == 0) { pthread_mutex_unlock(&rb->lock); - trace("i/rb unlock"); + trace(("i/rb unlock")); } #endif |