Coding style change

This commit is contained in:
Nils O. Selåsdal
2012-12-05 18:53:58 +01:00
parent d9c8b2b48a
commit 16e1ac52ec
32 changed files with 236 additions and 234 deletions
+21 -21
View File
@@ -29,10 +29,10 @@ static inline uint32_t mux_2_epoll_events(unsigned int events)
{
uint32_t epoll_events = 0;
if(events & MUX_EV_READ)
if (events & MUX_EV_READ)
epoll_events |= EPOLLIN;
if(events & MUX_EV_WRITE)
if (events & MUX_EV_WRITE)
epoll_events |= EPOLLOUT;
return epoll_events;
@@ -44,10 +44,10 @@ static inline unsigned int epoll_2_mux_events(uint32_t events)
//epoll always waits for EPOLLHUP and EPOLLERR , we map
//those to read events which will hopefully do the right thing
if(events & (EPOLLIN | EPOLLHUP | EPOLLERR))
if (events & (EPOLLIN | EPOLLHUP | EPOLLERR))
mux_events |= MUX_EV_READ;
if(events & EPOLLOUT)
if (events & EPOLLOUT)
mux_events |= MUX_EV_WRITE;
return mux_events;
@@ -65,7 +65,7 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
//in order to try to "pause" reading can lead to missing or false
//read events.
assert(fd->what != 0);
if(fd->what == 0)
if (fd->what == 0)
return EINVAL;
@@ -74,7 +74,7 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_MOD, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0)
if (rc != 0)
return errno;
return 0;
@@ -86,7 +86,7 @@ static int iomux_epoll_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
struct epoll_event e_event = {0, {0}};
int rc;
if(fd->what == 0 || fd->callback == NULL)
if (fd->what == 0 || fd->callback == NULL)
return EINVAL;
e_event.events = mux_2_epoll_events(fd->what);
@@ -94,7 +94,7 @@ static int iomux_epoll_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_ADD, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0) {
if (rc != 0) {
return errno;
}
@@ -111,18 +111,18 @@ static int iomux_epoll_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_DEL, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0)
if (rc != 0)
return errno;
//if the fd is pending, remove it from pending_events
//This ensures that it's safe to unregister a descriptor
//that is currently pending a callback
for(i = 0; i < mux->pending; i++) {
for (i = 0; i < mux->pending; i++) {
struct IOMuxFD *fdi = mux->pending_events[i].data.ptr;
if(fdi == NULL)
if (fdi == NULL)
continue;
if(fd == fdi) {
if (fd == fdi) {
mux->pending_events[i].data.ptr = NULL;
break;
}
@@ -149,17 +149,17 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
int timeout_ms;
int event_cnt;
if(mux->num_descriptors == 0 && timeout == NULL)
if (mux->num_descriptors == 0 && timeout == NULL)
return 0;
//epoll takes the timeout in miliseconds
if(timeout)
if (timeout)
timeout_ms = timeval_to_ms(timeout);
else
timeout_ms = -1;
again:
rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms);
if(rc == -1 && errno == EINTR)
if (rc == -1 && errno == EINTR)
goto again;
assert(rc >= 0);
@@ -170,12 +170,12 @@ again:
event_cnt = iomux_timers_run(mux_); //process timers
if(rc == 0) //Just the timeout
if (rc == 0) //Just the timeout
return event_cnt;
for(i = 0; i < rc; i++) {
for (i = 0; i < rc; i++) {
struct IOMuxFD *fd = mux->pending_events[i].data.ptr;
if(fd != NULL) { //calling _unregister from a callback could have removed it
if (fd != NULL) { //calling _unregister from a callback could have removed it
unsigned int events;
events = epoll_2_mux_events(mux->pending_events[i].events);
@@ -195,7 +195,7 @@ again:
static void iomux_epoll_delete(struct IOMux *mux)
{
assert(mux != NULL && mux->instance != NULL);
if(mux != NULL && mux->instance != NULL) {
if (mux != NULL && mux->instance != NULL) {
struct IOMuxEpoll *mux_epoll = mux->instance;
close(mux_epoll->epoll_fd);
free(mux_epoll);
@@ -206,11 +206,11 @@ static void iomux_epoll_delete(struct IOMux *mux)
int iomux_epoll_init(struct IOMux *mux)
{
struct IOMuxEpoll *mux_epoll = calloc(1, sizeof *mux_epoll);
if(mux_epoll == NULL)
if (mux_epoll == NULL)
return ENOMEM;
mux_epoll->epoll_fd = epoll_create(128);
if(mux_epoll->epoll_fd == -1) {
if (mux_epoll->epoll_fd == -1) {
free(mux_epoll);
return errno;
}
+8 -8
View File
@@ -13,7 +13,7 @@ struct IOMux *iomux_create(enum IOMUX_TYPE type)
int rc = -1;
switch(type) {
switch (type) {
case IOMUX_TYPE_DEFAULT:
case IOMUX_TYPE_EPOLL:
rc = iomux_epoll_init(mux);
@@ -23,12 +23,12 @@ struct IOMux *iomux_create(enum IOMUX_TYPE type)
break;
}
if(rc != 0) {
if (rc != 0) {
//try fallback to select
rc = iomux_select_init(mux);
}
if(rc == 0) {
if (rc == 0) {
rc = gettimeofday(&mux->now, NULL);
assert(rc == 0);
uc_timers_init(&mux->timers);
@@ -50,7 +50,7 @@ void iomux_delete(struct IOMux *mux)
//convert the difference between future and now
static inline void future_to_interval(struct timeval *future, const struct timeval *now, struct timeval *result)
{
if(timercmp(future, now, >)) {
if (timercmp(future, now, >)) {
timersub(future, now, result);
} else {
result->tv_sec = 0;
@@ -60,7 +60,7 @@ static inline void future_to_interval(struct timeval *future, const struct timev
int iomux_run(struct IOMux *mux)
{
for(;;) {
for (;;) {
int rc;
struct timeval first_timer;
struct timeval timeout;
@@ -71,7 +71,7 @@ int iomux_run(struct IOMux *mux)
rc = gettimeofday(&mux->now, NULL);
assert(rc == 0);
if(uc_timers_first(&mux->timers, &first_timer) == 0) {
if (uc_timers_first(&mux->timers, &first_timer) == 0) {
future_to_interval(&first_timer, &mux->now, &timeout);
timeoutp = &timeout;
/* fprintf(stdout, "now %d %d future %d %d interval %d %d\n", mux->now.tv_sec, mux->now.tv_usec,
@@ -88,10 +88,10 @@ int iomux_run(struct IOMux *mux)
timeoutp = NULL; //no timeout
}
rc = mux->run_impl(mux, timeoutp);
if(rc < 0)
if (rc < 0)
return rc;
if(rc == 0 && !has_timers) //no more events, ever
if (rc == 0 && !has_timers) //no more events, ever
return 0;
}
+23 -23
View File
@@ -28,7 +28,7 @@ static int iomux_select_grow(struct IOMuxSelect *mux)
{
void *tmp = realloc(mux->descriptors, (mux->num_descriptors + IOMUX_GROW_CHUNK) * sizeof *mux->descriptors);
assert(tmp != NULL);
if(tmp == NULL)
if (tmp == NULL)
return ENOMEM;
mux->alloc_descriptors += IOMUX_GROW_CHUNK;
@@ -39,7 +39,7 @@ static int iomux_select_grow(struct IOMuxSelect *mux)
static void iomux_select_remove(struct IOMuxSelect *mux, size_t idx)
{
if(mux->num_descriptors > 1) {
if (mux->num_descriptors > 1) {
//move last element into the empty slot
size_t last_idx = mux->num_descriptors - 1;
mux->descriptors[idx] = mux->descriptors[last_idx];
@@ -54,8 +54,8 @@ static void iomux_select_rebuild(struct IOMuxSelect *mux)
size_t i;
mux->max_fd = -1;
for(i = 0; i < mux->num_descriptors; ) {
if(mux->descriptors[i] == NULL) {
for (i = 0; i < mux->num_descriptors; ) {
if (mux->descriptors[i] == NULL) {
iomux_select_remove(mux, i);
//a deleted fd slot needs to be rechecked, no i++ here
} else {
@@ -70,12 +70,12 @@ static int iomux_select_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
{
struct IOMuxSelect *mux = mux_->instance;
if(fd->what & MUX_EV_READ)
if (fd->what & MUX_EV_READ)
FD_SET(fd->fd, &mux->master_read_set);
else
FD_CLR(fd->fd, &mux->master_read_set);
if(fd->what & MUX_EV_WRITE)
if (fd->what & MUX_EV_WRITE)
FD_SET(fd->fd, &mux->master_write_set);
else
FD_CLR(fd->fd, &mux->master_write_set);
@@ -86,11 +86,11 @@ static int iomux_select_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
static int iomux_select_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
{
struct IOMuxSelect *mux = mux_->instance;
if(fd->what == 0 || fd->callback == NULL)
if (fd->what == 0 || fd->callback == NULL)
return EINVAL;
if(mux->num_descriptors == mux->alloc_descriptors) {
if(iomux_select_grow(mux) != 0)
if (mux->num_descriptors == mux->alloc_descriptors) {
if (iomux_select_grow(mux) != 0)
return ENOMEM;
}
@@ -110,8 +110,8 @@ static int iomux_select_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd)
int rc = ENOENT;
size_t i;
for(i = 0; i < mux->num_descriptors; i++) {
if(fd == mux->descriptors[i]) {
for (i = 0; i < mux->num_descriptors; i++) {
if (fd == mux->descriptors[i]) {
unsigned int what = fd->what; //make sure we don't alter 'what' as seen from the user
fd->what &= ~MUX_EV_MASK;
iomux_select_update_events(mux_, fd);
@@ -136,46 +136,46 @@ static int iomux_select_run(struct IOMux *mux_, struct timeval *timeout)
fd_set read_set;
fd_set write_set;
if(mux->deleted_cnt) {
if (mux->deleted_cnt) {
iomux_select_rebuild(mux);
mux->deleted_cnt = 0;
}
if(mux->max_fd == -1 && timeout == NULL)
if (mux->max_fd == -1 && timeout == NULL)
return 0;
again:
read_set = mux->master_read_set;
write_set = mux->master_write_set;
rc = select(mux->max_fd + 1, &read_set, &write_set, NULL, timeout); //we can use timeout directly
if(rc == -1 && errno == EINTR)
if (rc == -1 && errno == EINTR)
goto again;
assert(rc >= 0);
if(rc < 0)
if (rc < 0)
return -1;
event_cnt = iomux_timers_run(mux_); //fire the timers
if(rc == 0) //Just the timeout
if (rc == 0) //Just the timeout
return event_cnt;
for(i = 0; rc >= 0 && i < mux->num_descriptors; i++) {
for (i = 0; rc >= 0 && i < mux->num_descriptors; i++) {
unsigned int events = 0;
if(mux->descriptors[i] == NULL) { //callback might have deleted it
if (mux->descriptors[i] == NULL) { //callback might have deleted it
continue;
}
if(FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
if (FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
events |= MUX_EV_READ;
}
if(FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
if (FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
events |= MUX_EV_WRITE;
}
if(events) {
if (events) {
assert(mux->descriptors[i]->callback != NULL);
mux->descriptors[i]->callback(mux_, mux->descriptors[i], events);
rc--;
@@ -188,7 +188,7 @@ again:
static void iomux_select_delete(struct IOMux *mux)
{
if(mux != NULL && mux->instance != NULL) {
if (mux != NULL && mux->instance != NULL) {
struct IOMuxSelect *mux_select = mux->instance;
free(mux_select->descriptors);
mux_select->descriptors = NULL;
@@ -200,7 +200,7 @@ static void iomux_select_delete(struct IOMux *mux)
int iomux_select_init(struct IOMux *mux)
{
struct IOMuxSelect *mux_select = calloc(1, sizeof *mux_select);
if(mux_select == NULL)
if (mux_select == NULL)
return ENOMEM;
mux_select->max_fd = -1;
+1 -1
View File
@@ -10,7 +10,7 @@ void uc_backtrace_fd(int fd)
int ptrs;
ptrs = backtrace(buffer, MAX_BACKTRACE_SYMBOLS);
if(ptrs > 0) { //dont print out this function
if (ptrs > 0) { //dont print out this function
ptrs--;
syms = &buffer[1];
} else {
+5 -5
View File
@@ -11,14 +11,14 @@ uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler)
*bcdp = 0;
for(; *ascii; ascii++) {
if(*ascii < '0' || *ascii > '9') {
for (; *ascii; ascii++) {
if (*ascii < '0' || *ascii > '9') {
continue;
}
*bcdp |= (*ascii - '0') << shift;
if(shift) {
if (shift) {
bcdp++;
*bcdp = 0;
}
@@ -26,7 +26,7 @@ uc_ascii2bcd(const char *ascii, unsigned char *bcdout, unsigned char filler)
shift = 4 - shift;
}
if(shift) {
if (shift) {
*bcdp |= (filler & 0xf) << 4;
bcdp++;
}
@@ -41,7 +41,7 @@ uc_bcd2ascii(const unsigned char *bcd, size_t bcdlen, char *asciiout)
size_t i;
size_t idx = 0;
for(i = 0; i < bcdlen; i++) {
for (i = 0; i < bcdlen; i++) {
asciiout[idx] = hex[bcd[i] & 0xf];
idx++;
asciiout[idx] = hex[(bcd[i] & 0xf0) >> 4];
+9 -9
View File
@@ -26,11 +26,11 @@ struct bitvec *bitvec_new(size_t nbits)
{
struct bitvec *v = malloc(sizeof *v);
if(v == NULL)
if (v == NULL)
return NULL;
v->vec_len = BITVEC_VEC_LEN(nbits);
v->vec = malloc(v->vec_len * sizeof(unsigned long));
if(v->vec == NULL) {
if (v->vec == NULL) {
free(v);
return NULL;
}
@@ -42,7 +42,7 @@ struct bitvec *bitvec_new(size_t nbits)
void bitvec_free(struct bitvec *v)
{
if(v) {
if (v) {
free(v->vec);
free(v);
}
@@ -70,7 +70,7 @@ void set_bit_s(struct bitvec *v,int b)
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if(likely(idx < v->vec_len))
if (likely(idx < v->vec_len))
v->vec[idx] |= 1UL << (bit_offset(b));
}
@@ -81,7 +81,7 @@ void clear_bit_s(struct bitvec *v,int b)
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if(likely(idx < v->vec_len))
if (likely(idx < v->vec_len))
v->vec[idx] &= ~(1UL << (bit_offset(b)));
}
@@ -92,7 +92,7 @@ int get_bit_s(const struct bitvec *v,int b)
assert(b >= 0);
assert(v->vec_len > (size_t)idx);
if(likely(idx < v->vec_len))
if (likely(idx < v->vec_len))
return !!(v->vec[idx] & (1UL << bit_offset(b)));
else
return 0;
@@ -102,12 +102,12 @@ void set_bits_from_array(struct bitvec *v,char *array,size_t array_len)
{
size_t i;
for(i = 0; i < array_len; i++) {
for (i = 0; i < array_len; i++) {
size_t idx = (size_t)bit_index(array_len);
if(unlikely(idx >= v->vec_len))
if (unlikely(idx >= v->vec_len))
break;
if(array[i])
if (array[i])
set_bit(v,i);
else
clear_bit(v,i);
+9 -9
View File
@@ -9,7 +9,7 @@ uc_new_gbuf(size_t initsz)
{
GBuf *p;
p = malloc(sizeof *p);
if(p == NULL)
if (p == NULL)
return NULL;
p->used = 0;
@@ -17,7 +17,7 @@ uc_new_gbuf(size_t initsz)
p->buf = NULL;
p->ref_cnt = 1;
if(initsz != 0 && (p->buf = malloc(initsz)) == NULL) {
if (initsz != 0 && (p->buf = malloc(initsz)) == NULL) {
free(p);
return NULL;
}
@@ -36,7 +36,7 @@ uc_gbuf_unref(GBuf *buf)
{
buf->ref_cnt--;
if(buf->ref_cnt == 0) {
if (buf->ref_cnt == 0) {
free(buf->buf);
free(buf);
}
@@ -47,8 +47,8 @@ uc_gbuf_append(GBuf *buf,const void *data,size_t len)
{
unsigned char *gbuf;
if(buf->len - buf->used < len)
if(uc_gbuf_grow(buf, len + len/2))
if (buf->len - buf->used < len)
if (uc_gbuf_grow(buf, len + len/2))
return -1;
gbuf = buf->buf;
@@ -74,8 +74,8 @@ int uc_gbuf_printf(GBuf *buf, const char *fmt, ...)
char *gbuf;
remaining = uc_gbuf_remaining(buf);
if(rc >= remaining) {
if(uc_gbuf_grow(buf, buf->len + (rc - remaining) + 1)) {
if (rc >= remaining) {
if (uc_gbuf_grow(buf, buf->len + (rc - remaining) + 1)) {
rc = -1;
va_end(apc);
break;
@@ -88,7 +88,7 @@ int uc_gbuf_printf(GBuf *buf, const char *fmt, ...)
rc = vsnprintf(gbuf + buf->used, remaining, fmt, apc);
va_end(apc);
} while(rc >= remaining);
} while (rc >= remaining);
if(rc > 0) {
buf->used += rc;
@@ -108,7 +108,7 @@ uc_gbuf_grow(GBuf *buf, size_t addlen)
newsz = buf->len + addlen;
tmp = realloc(buf->buf,newsz);
if(tmp == NULL)
if (tmp == NULL)
return -1;
buf->buf = tmp;
+1 -1
View File
@@ -3,7 +3,7 @@
uint32_t
uc_gcd_32(uint32_t a, uint32_t b)
{
while(b != 0) {
while (b != 0) {
uint32_t t = b;
b = a%b;
a = t;
+1 -1
View File
@@ -3,7 +3,7 @@
uint64_t
uc_gcd_64(uint64_t a, uint64_t b)
{
while(b != 0) {
while (b != 0) {
uint64_t t = b;
b = a%b;
a = t;
+8 -8
View File
@@ -7,28 +7,28 @@ getfields(char *str, char **args, int max, int mflag, const char *set)
char r;
int intok, narg;
if(max <= 0)
if (max <= 0)
return 0;
narg = 0;
args[narg] = str;
if(!mflag)
if (!mflag)
narg++;
intok = 0;
for(;; str++) {
for (;; str++) {
r = *str;
if(r == 0)
if (r == 0)
break;
if(strchr(set, r)) {
if(narg >= max)
if (strchr(set, r)) {
if (narg >= max)
break;
*str = 0;
intok = 0;
args[narg] = str + 1;
if(!mflag)
if (!mflag)
narg++;
} else {
if(!intok && mflag)
if (!intok && mflag)
narg++;
intok = 1;
}
+5 -5
View File
@@ -34,7 +34,7 @@ uc_hex_encode_delim(const uint8_t *in, size_t inlen, char *out, int outlen, char
for (i = 0; i < inlen && outlen > 0; i++) {
int rc = snprintf(outp, outlen, "%02X%s", in[i], delim);
if(rc <= 0)
if (rc <= 0)
break;
outp += rc;
outlen -= rc;
@@ -46,11 +46,11 @@ uc_hex_encode_delim(const uint8_t *in, size_t inlen, char *out, int outlen, char
/* ASCII only */
static inline int char_to_bin(char c)
{
if(c >='0' && c <='9')
if (c >='0' && c <='9')
return c - '0';
else if(c >= 'A' && c <= 'F')
else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
else if(c >= 'a' && c <= 'f')
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
return -1;
@@ -66,7 +66,7 @@ uc_hex_decode(const char *in, size_t maxlen,uint8_t *out)
int hn, ln;
hn = char_to_bin(in[i]);
ln = char_to_bin(in[i + 1]);
if(hn == -1 || ln == -1)
if (hn == -1 || ln == -1)
return NULL;
out[t] = (hn << 4 ) | ln;
+1 -1
View File
@@ -5,7 +5,7 @@
char *
uc_human_bytesz(uint64_t bytes, char *result, size_t result_len)
{
if(bytes < 1000) {
if (bytes < 1000) {
snprintf(result, result_len, "%" PRIu64 " b", bytes);
} else if (bytes < 1000000) {
snprintf(result, result_len, "%.2f kB", bytes/1000.0);
+30 -30
View File
@@ -114,12 +114,12 @@ struct uc_log_destination *uc_log_new_syslog(const char *ident, int facility, in
struct uc_log_destination *dest = calloc(1, sizeof *dest);
char *id;
if(dest == NULL)
if (dest == NULL)
return NULL;
//copy the ident - though it's unused inside the struct for now
id = strdup(ident);
if(id == NULL) {
if (id == NULL) {
free(dest);
return NULL;
}
@@ -141,17 +141,17 @@ struct uc_log_destination *uc_log_new_file(const char *filename, int log_level,
FILE *f;
char *name;
if(dest == NULL)
if (dest == NULL)
return NULL;
name = strdup(filename);
if(name == NULL) {
if (name == NULL) {
free(dest);
return NULL;
}
f = fopen(filename, "a");
if(f == NULL) {
if (f == NULL) {
free(name);
free(dest);
return NULL;
@@ -170,19 +170,19 @@ void uc_log_add_destination(struct uc_log_destination *dest)
{
struct uc_log_destination *it;
if(dest == NULL)
if (dest == NULL)
return;
pthread_mutex_lock(&log_lock);
//make sure the destination isn't added twice.
SLIST_FOREACH(it, &destinations, entry) {
if(dest == it)
if (dest == it)
break;
}
//add if it isn't already in the list
if(it == NULL) {
if (it == NULL) {
SLIST_INSERT_HEAD(&destinations, dest, entry);
}
@@ -196,18 +196,18 @@ static inline void uc_log_remove_dest_unlocked(struct uc_log_destination *dest)
//check that it's not already removed
SLIST_FOREACH(it, &destinations, entry) {
if(it == dest)
if (it == dest)
break;
}
if(it != NULL) {
if (it != NULL) {
SLIST_REMOVE(&destinations, dest, uc_log_destination, entry);
}
}
void uc_log_remove_destination(struct uc_log_destination *dest)
{
if(dest == NULL)
if (dest == NULL)
return;
pthread_mutex_lock(&log_lock);
@@ -219,7 +219,7 @@ void uc_log_remove_destination(struct uc_log_destination *dest)
void uc_log_delete_destination(struct uc_log_destination *dest)
{
if(dest == NULL)
if (dest == NULL)
return;
pthread_mutex_lock(&log_lock);
@@ -228,7 +228,7 @@ void uc_log_delete_destination(struct uc_log_destination *dest)
uc_log_remove_dest_unlocked(dest);
//clean up, according to the type
switch(dest->dest_type) {
switch (dest->dest_type) {
case UC_LDEST_SYSLOG:
free(dest->type.syslog.ident);
closelog();
@@ -259,17 +259,17 @@ int uc_log_reopen_files(void)
SLIST_FOREACH(dest, &destinations, entry) {
if(dest->dest_type == UC_LDEST_FILE) {
if (dest->dest_type == UC_LDEST_FILE) {
if(dest->type.file.file != NULL) {
if (dest->type.file.file != NULL) {
fclose(dest->type.file.file);
dest->type.file.file = NULL;
}
if(dest->type.file.file_name != NULL) {
if (dest->type.file.file_name != NULL) {
dest->type.file.file = fopen(dest->type.file.file_name, "a");
if(dest->type.file.file == NULL)
if (dest->type.file.file == NULL)
rc = errno;
}
}
@@ -292,8 +292,8 @@ int uc_log_module_set_loglevel(int module, enum UC_LOG_LEVEL level)
pthread_mutex_lock(&log_lock);
for(i = 0; i < modules.cnt; i++) {
if(modules.mods[i].id == module) {
for (i = 0; i < modules.cnt; i++) {
if (modules.mods[i].id == module) {
modules.mods[i].log_level = level;
rc = 0;
break;
@@ -312,12 +312,12 @@ static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt,
time_t now;
struct tm t;
if(dest->type.file.file == NULL)
if (dest->type.file.file == NULL)
return;
now = time(NULL);
localtime_r(&now, &t);
if(!args->raw) {
if (!args->raw) {
snprintf(time_buf, sizeof time_buf, "%04d-%02d-%02d %02d:%02d:%02d",
t.tm_year + 1900,
t.tm_mon + 1,
@@ -329,7 +329,7 @@ static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt,
time_buf[sizeof time_buf -1] = 0;
if(dest->log_location) {
if (dest->log_location) {
fprintf(dest->type.file.file, "[%s] %s %s:%d [%s] : ",
uc_ll_2_str(args->log_level), time_buf, args->file,
args->line, args->module->short_name);
@@ -353,23 +353,23 @@ static inline void uc_vlog_syslog(const struct uc_log_args *args, const char *fm
int pri = uc_ll_2_syslog(args->log_level);
if(!args->raw) {
if (!args->raw) {
//go via a buffer as we must do just 1 syslog call
char buf[4096];
int offset = 0;
int rc;
buf[0] = 0;
if(dest->log_location) {
if (dest->log_location) {
rc = snprintf(buf, sizeof buf, "%s:%d ", args->file, args->line);
if(rc < 0)
if (rc < 0)
goto log;
offset += rc;
}
rc = snprintf(&buf[offset], sizeof buf - (size_t)offset, "[%s] ",
args->module->short_name);
if(rc < 0)
if (rc < 0)
goto log;
offset +=rc;
@@ -398,20 +398,20 @@ void uc_logf(int log_level, int module, int raw,
//Find the module doign the logging, or use the unknown module -
//the latter would indicate a bug somewhere in the application as it should
//always specify a known module
if(module >= 0 && module < modules.cnt)
if (module >= 0 && module < modules.cnt)
log_module = &modules.mods[module];
else
log_module = &unknown_module;
//Check if the module should not be logged
if(log_level < log_module->log_level)
if (log_level < log_module->log_level)
goto out;
//do logging for each destination
SLIST_FOREACH(dest, &destinations, entry) {
va_list apc;
if(log_level >= dest->log_level) {
if (log_level >= dest->log_level) {
const struct uc_log_args args = {
.dest = dest,
.module = log_module,
@@ -425,7 +425,7 @@ void uc_logf(int log_level, int module, int raw,
//so make a copy
va_copy(apc, ap);
switch(dest->dest_type) {
switch (dest->dest_type) {
case UC_LDEST_SYSLOG:
uc_vlog_syslog(&args, fmt, apc);
break;
+3 -3
View File
@@ -25,7 +25,7 @@ enum {
void mtsrand(int seed, MTRand *r)
{
int j;
for(j = 0 ; j < N ; j++) {
for (j = 0 ; j < N ; j++) {
r->x[j] = seed * ((j+1)<< 3)|0x1;
}
r->i = 0;
@@ -63,10 +63,10 @@ int main(int argc,char *argv[])
{
MTRand r;
mtsrand(time(NULL),&r);
for(;;){
for (;;){
unsigned int _y = mtrand(&r);
if(_y < 100)
if (_y < 100)
printf("%u \n",_y);
}
+2 -2
View File
@@ -18,7 +18,7 @@ uc_murmurmash2(const void *key, int len, uint32_t seed )
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
while (len >= 4)
{
uint32_t k = *(const uint32_t *)data;
@@ -35,7 +35,7 @@ uc_murmurmash2(const void *key, int len, uint32_t seed )
// Handle the last few bytes of the input array
switch(len)
switch (len)
{
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
+7 -7
View File
@@ -294,10 +294,10 @@ uc_rb_insert(RBTree *root, RBNode *child)
RBNode *uc_rb_first(const RBTree *root)
{
RBNode *n = root->node;
if(n == NULL)
if (n == NULL)
return NULL;
while(n->left)
while (n->left)
n = n->left;
return n;
@@ -305,15 +305,15 @@ RBNode *uc_rb_first(const RBTree *root)
RBNode *uc_rb_next(RBNode *node)
{
if(node->right) { //down and left of the right branch
if (node->right) { //down and left of the right branch
node = node->right;
while(node->left)
while (node->left)
node = node->left;
} else { //up until we are not the right node
while(node->parent && node == node->parent->right)
while (node->parent && node == node->parent->right)
node = node->parent;
node = node->parent;
@@ -326,10 +326,10 @@ RBNode *uc_rb_last(const RBTree *root)
{
RBNode *n = root->node;
if(n == NULL)
if (n == NULL)
return NULL;
while(n->right)
while (n->right)
n = n->right;
return n;
+6 -6
View File
@@ -27,7 +27,7 @@ uc_read_file(const char *f, size_t *length, size_t max)
}
if ((statb.st_mode & S_IFMT) == S_IFREG) {
if((size_t)statb.st_size > max) {
if ((size_t)statb.st_size > max) {
errno = EMSGSIZE;
goto out_close;
}
@@ -44,21 +44,21 @@ uc_read_file(const char *f, size_t *length, size_t max)
p = s;
for(;;) {
for (;;) {
ssize_t rc = read(fd, p, alloc_sz - (p - s));
if(rc == 0) {
if (rc == 0) {
*p = 0; // nul terminate. all malloc calls adds room for this byte
goto out_close;
} else if (rc == -1) {
goto out_err_free;
} else if(*length + rc > max) {
} else if (*length + rc > max) {
errno = EMSGSIZE;
goto out_err_free;
}
if(p + rc == s + alloc_sz) { //reached end of allocated memory, grow it.
if (p + rc == s + alloc_sz) { //reached end of allocated memory, grow it.
char *tmp = realloc(s, alloc_sz + CHUNK_SZ + 1);
if(tmp == NULL) {
if (tmp == NULL) {
goto out_err_free;
}
+11 -11
View File
@@ -30,10 +30,10 @@ add_chunk(SAlloc *p)
Chunk *newchunk;
newchunk = malloc(sizeof *newchunk + p->chunksz - (sizeof *newchunk - offsetof(Chunk, data.data)));
if(newchunk == NULL)
if (newchunk == NULL)
return NULL;
if(p->current != NULL)
if (p->current != NULL)
p->current->next = newchunk;
newchunk->next = NULL;
@@ -47,13 +47,13 @@ next_chunk(SAlloc *p)
{
Chunk *newchunk;
if(p->current->next) {
if (p->current->next) {
newchunk = p->current->next;
newchunk->firstfree = 0;
} else
newchunk = add_chunk(p);
if(newchunk)
if (newchunk)
p->current = newchunk;
return newchunk;
@@ -65,13 +65,13 @@ uc_new_salloc(size_t chunksz)
SAlloc *p;
Chunk *first;
p = malloc(sizeof *p);
if(p == NULL)
if (p == NULL)
return NULL;
p->chunksz = chunksz;
p->current = NULL;
if((first = add_chunk(p)) == NULL) {
if ((first = add_chunk(p)) == NULL) {
free(p);
return NULL;
}
@@ -99,12 +99,12 @@ uc_s_alloc(SAlloc *p,size_t sz)
void *newmem;
chunk = p->current;
if(chunk->firstfree + sz > p->chunksz) {
if(sz > p->chunksz)
if (chunk->firstfree + sz > p->chunksz) {
if (sz > p->chunksz)
return NULL;
chunk = next_chunk(p);
if(chunk == NULL)
if (chunk == NULL)
return NULL;
}
@@ -119,7 +119,7 @@ uc_s_allocz(SAlloc *p,size_t sz)
{
void *newmem = uc_s_alloc(p, sz);
if(newmem != NULL)
if (newmem != NULL)
memset(newmem, 0, sz);
return newmem;
@@ -130,7 +130,7 @@ free_chunks(Chunk *chunk)
{
Chunk *next;
for(next = NULL; chunk != NULL; chunk = next) {
for (next = NULL; chunk != NULL; chunk = next) {
next = chunk->next;
free(chunk);
}
+9 -9
View File
@@ -53,23 +53,23 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg)
//insert the new element
msg->next = NULL;
if(msg->msgtype >= 0) { //add at the tail
if (msg->msgtype >= 0) { //add at the tail
*(queue->last) = msg;
queue->last = &msg->next;
} else { //add at the head ("priority message")
msg->next = queue->first;
if(queue->first == NULL) {
if (queue->first == NULL) {
queue->last = &msg->next;
}
queue->first = msg;
}
//signal blocked readers
if(queue->num_read_waiters == 1) {
if (queue->num_read_waiters == 1) {
//if there's just one thread waiting to pop elements
//use _cond_signal. _cond_broadcast can be more expensive (os dependent)
pthread_cond_signal(&queue->read_cond);
} else if(queue->num_read_waiters > 1) {
} else if (queue->num_read_waiters > 1) {
//signall all threads that there's items available.
pthread_cond_broadcast(&queue->read_cond);
}
@@ -127,18 +127,18 @@ int uc_thread_queue_get(struct uc_threadqueue *queue, const struct timespec *tim
//remove the first element
first_msg = queue->first;
queue->first = first_msg->next;
if(queue->first == NULL)
if (queue->first == NULL)
queue->last = &queue->first;
first_msg->next = NULL;
queue->num_elements--;
//signal blocked writers
if(queue->num_write_waiters == 1) {
if (queue->num_write_waiters == 1) {
//if there's just one thread waiting to push elements
//use _cond_signal. _cond_broadcast can be more expensive (os dependent)
pthread_cond_signal(&queue->write_cond);
} else if(queue->num_write_waiters > 1) {
} else if (queue->num_write_waiters > 1) {
//signall all threads that there's items available.
pthread_cond_broadcast(&queue->write_cond);
}
@@ -192,12 +192,12 @@ int uc_thread_queue_destroy(struct uc_threadqueue *queue, uc_thread_queue_walk_f
* But if we *know* there are some threads still using the queue,
* we can't destroy it.
*/
if(queue->num_read_waiters != 0 || queue->num_write_waiters != 0) {
if (queue->num_read_waiters != 0 || queue->num_write_waiters != 0) {
pthread_mutex_unlock(&queue->mutex);
return EBUSY;
}
if(free_func) {
if (free_func) {
uc_thread_queue_walk_unlocked(queue, free_func);
}
+11 -11
View File
@@ -7,14 +7,14 @@ static int timers_cmp(const void *a_, const void *b_)
const struct UCTimer *a = a_;
const struct UCTimer *b = b_;
if(timercmp(&a->timeout, &b->timeout, <)) {
if (timercmp(&a->timeout, &b->timeout, <)) {
return -1;
} else if (timercmp(&a->timeout, &b->timeout, >)) {
return 1;
} else { //check sequence number
if(a->seq < b->seq) {
if (a->seq < b->seq) {
return -1;
} else if(a->seq > b->seq) {
} else if (a->seq > b->seq) {
return 1;
} else { //should never happen
//assert(0);
@@ -48,7 +48,7 @@ void uc_timer_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int u
struct timeval tmp;
assert(timer->callback != NULL);
if(timer->callback == NULL) //must be set.
if (timer->callback == NULL) //must be set.
return;
tmp.tv_sec = sec;
@@ -61,7 +61,7 @@ void uc_timer_add(struct UCTimers *timers, struct UCTimer *timer, int sec, int u
void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer)
{
if(timer->state == UC_TIMER_INACTIVE) { //already removed , or never added.
if (timer->state == UC_TIMER_INACTIVE) { //already removed , or never added.
//debugging bandaid
timer->ready_entry.tqe_next = (struct UCTimer *)104;
timer->ready_entry.tqe_prev = (struct UCTimer **)105;
@@ -70,7 +70,7 @@ void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer)
uc_rb_remove(&timers->timers, &timer->rb_node); //remove it, safe for the
//callback to re_add it
if(timer->state == UC_TIMER_PENDING) {
if (timer->state == UC_TIMER_PENDING) {
//timer is pending for callback, remove it from the list
//so code in uc_timers_run does not touch it.
TAILQ_REMOVE(&timers->ready_list, timer, ready_entry);
@@ -81,7 +81,7 @@ void uc_timer_remove(struct UCTimers *timers, struct UCTimer *timer)
int uc_timers_first(const struct UCTimers *timers, struct timeval *first)
{
const RBNode *n = uc_rb_first(&timers->timers);
if(n) {
if (n) {
struct UCTimer *timer = n->data;
*first = timer->timeout;
return 0;
@@ -95,7 +95,7 @@ size_t uc_timer_count(const struct UCTimers *timers)
struct RBNode *n;
size_t count = 0;
for(n = uc_rb_first(&timers->timers); n ; n = uc_rb_next(n)) {
for (n = uc_rb_first(&timers->timers); n ; n = uc_rb_next(n)) {
count++;
}
@@ -119,10 +119,10 @@ int uc_timers_run(struct UCTimers *timers, const struct timeval *now)
*/
assert(TAILQ_EMPTY(&timers->ready_list)); //somethings serious wrong if it isn't already empty
TAILQ_INIT(&timers->ready_list);
for(node = uc_rb_first(&timers->timers); node ; node = uc_rb_next(node)) {
for (node = uc_rb_first(&timers->timers); node ; node = uc_rb_next(node)) {
struct UCTimer *t = node->data;
//Note, timercmp does not work for >=
if(!timercmp(now, &t->timeout, <)) {
if (!timercmp(now, &t->timeout, <)) {
TAILQ_INSERT_TAIL(&timers->ready_list, t, ready_entry);
t->state = UC_TIMER_PENDING; //so uc_timer_remove knows
//it have to remove it from the ready_list
@@ -139,7 +139,7 @@ int uc_timers_run(struct UCTimers *timers, const struct timeval *now)
* we had in the list.
* uc_timer_remove will unlink the timer from this list.
*/
while(!TAILQ_EMPTY(&timers->ready_list)) {
while (!TAILQ_EMPTY(&timers->ready_list)) {
struct UCTimer *t = TAILQ_FIRST(&timers->ready_list);
uc_timer_remove(timers, t);
+2 -2
View File
@@ -27,9 +27,9 @@ uc_tvsub(struct timeval *dst, const struct timeval *a, const struct timeval *b)
int
uc_tvcmp(const struct timeval *a, const struct timeval *b)
{
if(a->tv_sec < b->tv_sec)
if (a->tv_sec < b->tv_sec)
return -1;
else if(a->tv_sec > b->tv_sec)
else if (a->tv_sec > b->tv_sec)
return 1;
if (a->tv_usec < b->tv_usec)
+1 -1
View File
@@ -10,7 +10,7 @@ void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
ssize_t len = read(fd->fd, buf, sizeof buf);
printf("Read %d bytes\n", len);
iomux_unregister_fd(mux, fd);
if(len > 0) {
if (len > 0) {
s_fd.what = MUX_EV_READ;
iomux_register_fd(mux, &s_fd);
}
+4 -4
View File
@@ -10,7 +10,7 @@ void stdin_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
{
char buf[4096];
ssize_t len = read(fd->fd, buf, sizeof buf);
if(len <= 0) {
if (len <= 0) {
perror("read");
fprintf(stderr,"Unregister stdin fd %d\n", fd->fd);
iomux_unregister_fd(mux, fd);
@@ -25,7 +25,7 @@ void pipe_read_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
{
char buf[4095];
ssize_t len = read(fd->fd, buf, sizeof buf);
if(len <= 0) {
if (len <= 0) {
perror("pipe read");
printf("Unregister pipe fd %d [stdout]\n", fd->fd);
fprintf(stderr,"Unregister pipe fd %d[stderr]\n", fd->fd);
@@ -72,10 +72,10 @@ int main(int argc, char *argv[])
rc = iomux_register_fd(mux1, &fd1);
if(rc != 0)
if (rc != 0)
printf("Cannot register fd1: %s\n", strerror(rc));
rc = iomux_register_fd(mux2, &fd2);
if(rc != 0)
if (rc != 0)
printf("Cannot register fdw: %s\n", strerror(rc));
pthread_create(&tid,NULL,writer,mux2);
iomux_run(mux1);
+11 -11
View File
@@ -26,15 +26,15 @@ void in_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
size_t left = BUFLEN - copy_ctx->w_idx;
ssize_t rc;
left /= 2;
if(left == 0)
if (left == 0)
left++;
rc = read(fd->fd, &copy_ctx->buffer[copy_ctx->w_idx], left);
if(rc <= 0) {
if(rc == -1 && errno == EAGAIN) {
if (rc <= 0) {
if (rc == -1 && errno == EAGAIN) {
return;
} else if(rc == -1) {
} else if (rc == -1) {
perror("read");
}
iomux_unregister_fd(mux, fd);
@@ -43,13 +43,13 @@ void in_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
copy_ctx->w_idx += rc;
if(!copy_ctx->out_running) {
if (!copy_ctx->out_running) {
copy_ctx->out.what = MUX_EV_WRITE;
iomux_register_fd(mux, &copy_ctx->out);
copy_ctx->out_running = 1;
}
if(copy_ctx->w_idx == BUFLEN) {
if (copy_ctx->w_idx == BUFLEN) {
iomux_unregister_fd(mux, fd);
}
}
@@ -61,8 +61,8 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
size_t len = copy_ctx->w_idx - copy_ctx->r_idx;
rc = write(1, &copy_ctx->buffer[copy_ctx->r_idx], len);
if(rc <= 0) {
if(rc == -1 && errno == EAGAIN) {
if (rc <= 0) {
if (rc == -1 && errno == EAGAIN) {
return;
} else {
perror("write");
@@ -72,10 +72,10 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
copy_ctx->out_running = 0;
} else {
copy_ctx->r_idx += rc;
if(copy_ctx->r_idx == copy_ctx->w_idx) {
if (copy_ctx->r_idx == copy_ctx->w_idx) {
iomux_unregister_fd(mux, fd);
copy_ctx->out_running = 0;
if(copy_ctx->w_idx == BUFLEN) {
if (copy_ctx->w_idx == BUFLEN) {
copy_ctx->w_idx = 0;
copy_ctx->r_idx = 0;
iomux_register_fd(mux, &copy_ctx->in);
@@ -88,7 +88,7 @@ void out_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int event)
int set_nonblocking(int fd)
{
int flags = fcntl(fd,F_GETFL,NULL);
if(flags < 0 ) {
if (flags < 0 ) {
return flags;
}
return fcntl(fd,F_SETFL,flags | O_NONBLOCK);
+2 -2
View File
@@ -8,7 +8,7 @@ int main(int argc, char *argv)
{
size_t i;
SAlloc *s = uc_new_salloc(36 * 100);
for(i = 0; i < 100; i++) {
for (i = 0; i < 100; i++) {
void *p = uc_s_alloc(s, 36);
memset(p,7,36);
}
@@ -16,7 +16,7 @@ int main(int argc, char *argv)
uc_free_salloc(s);
s = uc_new_salloc(85 * 100);
for(i = 0; i < 100 * 3; i++) {
for (i = 0; i < 100 * 3; i++) {
void *p = uc_s_alloc(s, 85);
memset(p,7,85);
}
+8 -8
View File
@@ -7,7 +7,7 @@ START_TEST (test_bitvec_1)
struct bitvec v = BITVEC_STATIC_INIT(s);
size_t i;
for(i = 0; i < sizeof s * 8; i++)
for (i = 0; i < sizeof s * 8; i++)
fail_if(get_bit(&v, i), "bit %zu is not 0", i);
END_TEST
@@ -16,10 +16,10 @@ START_TEST (test_bitvec_2)
struct bitvec v = BITVEC_STATIC_INIT(s);
size_t i;
for(i = 0; i < sizeof s * 8; i++)
for (i = 0; i < sizeof s * 8; i++)
set_bit(&v, i);
for(i = 0; i < sizeof s * 8; i++)
for (i = 0; i < sizeof s * 8; i++)
fail_if(get_bit(&v, i) != 1 , "bit %zu is not 1", i);
END_TEST
@@ -28,13 +28,13 @@ START_TEST (test_bitvec_clearbit)
struct bitvec v = BITVEC_STATIC_INIT(s);
size_t i;
for(i = 0; i < sizeof(unsigned long) * 8; i++)
for (i = 0; i < sizeof(unsigned long) * 8; i++)
fail_if(get_bit(&v, i) != 1 , "bit %zu is not 1", i);
for(i = 0; i < sizeof(unsigned long) * 8; i++)
for (i = 0; i < sizeof(unsigned long) * 8; i++)
clear_bit(&v, i);
for(i = 0; i < sizeof(unsigned long) * 8; i++)
for (i = 0; i < sizeof(unsigned long) * 8; i++)
fail_if(get_bit(&v, i) != 0 , "bit %zu is not 0", i);
END_TEST
@@ -58,12 +58,12 @@ START_TEST (test_bitvec_setall_clearall)
set_all(v);
for(i = 0; i < 511; i++)
for (i = 0; i < 511; i++)
fail_if(get_bit(v, i) != 1 , "bit %zu is not 1", i);
clear_all(v);
for(i = 0; i < sizeof(unsigned long) * 8; i++)
for (i = 0; i < sizeof(unsigned long) * 8; i++)
fail_if(get_bit(v, i) != 0 , "bit %zu is not 0", i);
END_TEST
+4 -2
View File
@@ -263,7 +263,7 @@ START_TEST (test_logfile_full_filesystem)
fail_if(dest == NULL, "Cannot open /dev/full");
uc_log_add_destination(dest);
for(i = 0; i < 1024; i++) {
for (i = 0; i < 1024; i++) {
UC_LOGF(UC_LL_DEBUG, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_WARNING, 0, "Lorum ipson %d\n", 1);
UC_LOGF(UC_LL_INFO, 0, "Lorum ipson %d\n", 1);
@@ -374,11 +374,13 @@ Suite *logging_suite(void)
tcase_add_test(tc1, test_logfile_loglevel_surpressed_module);
tcase_add_test(tc1, test_logfile_reopen_files);
tcase_add_test(tc1, test_logfile_remove_dest);
if(access("/dev/full", R_OK) == 0) {
if (access("/dev/full", R_OK) == 0) {
tcase_add_test(tc1, test_logfile_full_filesystem);
} else {
puts("Cannot access /dev/full. Not testing test_logfile_full_filesystem");
}
tcase_add_test(tc1, test_logfile_invalid_file);
tcase_add_test(tc2, test_logfile_invalid_file_after_reopen);
tcase_add_test(tc1, test_logfile_raw);
+2 -2
View File
@@ -21,7 +21,7 @@ main (int argc, char *argv[])
int number_failed = 0;
SRunner *sr = srunner_create (NULL);
if(xml_output)
if (xml_output)
srunner_set_xml(sr, "result.xml");
srunner_add_suite(sr, bitvec_suite());
@@ -39,7 +39,7 @@ main (int argc, char *argv[])
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
if(number_failed)
if (number_failed)
printf("ERROR: %d tests failed\n", number_failed);
return (number_failed != 0) ;
+10 -10
View File
@@ -17,7 +17,7 @@ START_TEST (test_thread_queue_length)
int i;
fail_if(uc_thread_queue_init(&queue, 100) != 0);
for(i = 0; i < 51; i++) {
for (i = 0; i < 51; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->msg.msgtype = 1;
@@ -34,7 +34,7 @@ START_TEST (test_thread_queue_one_thread)
int i;
fail_if(uc_thread_queue_init(&queue, 100) != 0);
for(i = 0; i < 51; i++) {
for (i = 0; i < 51; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->msg.msgtype = 0;
@@ -42,7 +42,7 @@ START_TEST (test_thread_queue_one_thread)
fail_if(uc_thread_queue_add(&queue, &msg->msg) != 0);
}
for(i = 0; i < 51; i++) {
for (i = 0; i < 51; i++) {
struct uc_threadmsg *msg;
struct thr_msg *my_msg;
fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0);
@@ -70,7 +70,7 @@ START_TEST (test_thread_queue_walk)
int i;
fail_if(uc_thread_queue_init(&queue, 100) != 0);
for(i = 0; i < 51; i++) {
for (i = 0; i < 51; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->a = i;
@@ -91,7 +91,7 @@ static void *test_thread_queue_reader_writer_func(void *arg)
struct uc_threadqueue *queue = arg;
int i;
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
struct uc_threadmsg *msg;
struct thr_msg *my_msg;
fail_if(uc_thread_queue_get(queue, NULL, &msg) != 0);
@@ -113,7 +113,7 @@ START_TEST (test_thread_queue_reader_writer)
fail_if(pthread_create(&tid, NULL, test_thread_queue_reader_writer_func, &queue) != 0);
sched_yield();
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->a = i;
@@ -137,7 +137,7 @@ START_TEST (test_thread_queue_reader_writer_len_1)
fail_if(pthread_create(&tid, NULL, test_thread_queue_reader_writer_func, &queue) != 0);
sched_yield();
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->a = i;
@@ -162,7 +162,7 @@ void *test_thread_queue_multiple_writers_func(void *arg)
struct uc_threadqueue *queue = arg;
int i;
for(i = 0; i < READER_WRITER_NUM_MSG; i++) {
for (i = 0; i < READER_WRITER_NUM_MSG; i++) {
struct thr_msg *msg = malloc(sizeof *msg);
fail_if(msg == NULL);
msg->a = i;
@@ -185,13 +185,13 @@ START_TEST (test_thread_queue_multiple_writers)
fail_if(pthread_create(&tid2, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
fail_if(pthread_create(&tid3, NULL, test_thread_queue_multiple_writers_func, &queue) != 0);
for(i = 0; i < READER_WRITER_NUM_MSG * 3; i++) {
for (i = 0; i < READER_WRITER_NUM_MSG * 3; i++) {
struct uc_threadmsg *msg;
struct thr_msg *my_msg;
fail_if(uc_thread_queue_get(&queue, NULL, &msg) != 0);
my_msg = (struct thr_msg *)msg;
if(my_msg->a == READER_WRITER_NUM_MSG - 1)
if (my_msg->a == READER_WRITER_NUM_MSG - 1)
count_max++;
free(my_msg);
+7 -7
View File
@@ -15,10 +15,10 @@ void *reader(void *arg)
{
int i;
int last;
for(i = 0; i < CNT/2; i++) {
for (i = 0; i < CNT/2; i++) {
struct uc_threadmsg *msg;
struct my_msg *my;
if(uc_thread_queue_get(&queue, NULL, &msg) != 0) {
if (uc_thread_queue_get(&queue, NULL, &msg) != 0) {
printf("uc_threadqueue_get failed\n");
return NULL;
}
@@ -39,25 +39,25 @@ int main(int argc, char *argv[])
uc_thread_queue_init(&queue, 100);
if(pthread_create(&tid1, NULL, reader, NULL) != 0) {
if (pthread_create(&tid1, NULL, reader, NULL) != 0) {
perror("pthread_create");
return 1;
}
if(pthread_create(&tid2, NULL, reader, NULL) != 0) {
if (pthread_create(&tid2, NULL, reader, NULL) != 0) {
perror("pthread_create");
return 1;
}
for(i = 0; i < CNT; i++) {
for (i = 0; i < CNT; i++) {
struct my_msg *msg = malloc(sizeof *msg);
if(msg == NULL) {
if (msg == NULL) {
perror("malloc");
return 1;
}
msg->uc_msg.msgtype = 11;
msg->counter = i;
if(uc_thread_queue_add(&queue, &msg->uc_msg) != 0) {
if (uc_thread_queue_add(&queue, &msg->uc_msg) != 0) {
printf("uc_threadqueue_add failed\n");
return 2;
}
+4 -4
View File
@@ -17,9 +17,9 @@ struct descriptors entries;
int descriptor_cmp(struct descriptor *a, struct descriptor *b)
{
if(a->fd < b->fd)
if (a->fd < b->fd)
return -1;
if(a->fd > b->fd)
if (a->fd > b->fd)
return 1;
return 0;
@@ -41,7 +41,7 @@ void find(int fd)
des.fd = fd;
found = SPLAY_FIND(descriptors, &entries, &des);
if(found == NULL)
if (found == NULL)
printf("Not found fd %d\n", fd);
else
printf("Found fd %d (%d)\n", found->fd, fd);
@@ -80,7 +80,7 @@ void fd_min_max(void)
min_des = SPLAY_MIN(descriptors, &entries);
max_des = SPLAY_MAX(descriptors, &entries);
if(min_des && max_des)
if (min_des && max_des)
printf("min fd = %d max fd = %d\n", min_des->fd, max_des->fd);
}
+1 -1
View File
@@ -5,7 +5,7 @@
int main(int argc, char *argv[])
{
unsigned int a,N;
if(argc < 2) {
if (argc < 2) {
printf("Usage %s interger1\n",argv[0]);
return 1;
}