summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/bitmap.c62
-rw-r--r--src/lib/cdap.c5
-rw-r--r--src/lib/dev.c28
-rw-r--r--src/lib/irm.c4
-rw-r--r--src/lib/nsm.c10
-rw-r--r--src/lib/shm_flow_set.c45
-rw-r--r--src/lib/shm_rbuff.c28
-rw-r--r--src/lib/shm_rdrbuff.c85
-rw-r--r--src/lib/sockets.c1
-rw-r--r--src/lib/tests/bitmap_test.c3
10 files changed, 139 insertions, 132 deletions
diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c
index e84145b2..94f5654f 100644
--- a/src/lib/bitmap.c
+++ b/src/lib/bitmap.c
@@ -28,25 +28,25 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
-#define BITS_PER_BYTE 8
+#define BITS_PER_BYTE CHAR_BIT
-#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
+#define BITS_PER_LONG (sizeof(size_t) * BITS_PER_BYTE)
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define BITS_TO_LONGS(nr) \
- DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+ DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(size_t))
-static unsigned long find_next_zero_bit(const unsigned long * addr,
- unsigned long nbits)
+static size_t find_next_zero_bit(const size_t * addr, size_t nbits)
{
- unsigned long tmp;
- unsigned long start = 0;
- unsigned long pos = 0;
- unsigned long mask;
+ size_t tmp;
+ size_t start = 0;
+ size_t pos = 0;
+ size_t mask;
/* First find correct word */
tmp = ~addr[start];
@@ -68,36 +68,33 @@ static unsigned long find_next_zero_bit(const unsigned long * addr,
return (start * BITS_PER_LONG) + pos;
}
-static void bitmap_zero(unsigned long * dst,
- unsigned int nbits)
+static void bitmap_zero(size_t * dst, size_t nbits)
{
- unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+ size_t len = BITS_TO_LONGS(nbits) * sizeof(size_t);
memset(dst, 0, len);
}
-static void bitmap_clear(unsigned long * map,
- unsigned int start)
+static void bitmap_clear(size_t * map, size_t start)
{
- unsigned long * p = map + BIT_WORD(start);
- unsigned long mask = ~(1UL << (start % (BITS_PER_LONG)));
+ size_t * p = map + BIT_WORD(start);
+ size_t mask = ~(1UL << (start % (BITS_PER_LONG)));
*p &= mask;
}
-static void bitmap_set(unsigned long * map,
- unsigned int start)
+static void bitmap_set(size_t * map, size_t start)
{
- unsigned long * p = map + BIT_WORD(start);
- unsigned long mask = 1UL << (start % (BITS_PER_LONG));
+ size_t * p = map + BIT_WORD(start);
+ size_t mask = 1UL << (start % (BITS_PER_LONG));
*p |= mask;
}
struct bmp {
ssize_t offset;
- size_t size;
+ size_t size;
- unsigned long * bitmap;
+ size_t * bitmap;
};
struct bmp * bmp_create(size_t bits, ssize_t offset)
@@ -111,7 +108,7 @@ struct bmp * bmp_create(size_t bits, ssize_t offset)
if (tmp == NULL)
return NULL;
- tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(unsigned long));
+ tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(size_t));
if (tmp->bitmap == NULL) {
free(tmp);
return NULL;
@@ -150,14 +147,12 @@ static ssize_t bad_id(struct bmp * b)
ssize_t bmp_allocate(struct bmp * b)
{
- ssize_t id;
+ size_t id;
if (b == NULL)
return -1;
- id = (ssize_t) find_next_zero_bit(b->bitmap,
- b->size);
-
+ id = find_next_zero_bit(b->bitmap, b->size);
if (id >= b->size)
return bad_id(b);
@@ -166,19 +161,17 @@ ssize_t bmp_allocate(struct bmp * b)
return id + b->offset;
}
-static bool is_id_valid(struct bmp * b,
- ssize_t id)
+static bool is_id_valid(struct bmp * b, ssize_t id)
{
assert(b);
- if ((id < b->offset) || (id > (b->offset + b->size)))
+ if ((id < b->offset) || (id > (ssize_t) (b->offset + b->size)))
return false;
return true;
}
-bool bmp_is_id_valid(struct bmp * b,
- ssize_t id)
+bool bmp_is_id_valid(struct bmp * b, ssize_t id)
{
if (b == NULL)
return false;
@@ -186,10 +179,9 @@ bool bmp_is_id_valid(struct bmp * b,
return is_id_valid(b, id);
}
-int bmp_release(struct bmp * b,
- ssize_t id)
+int bmp_release(struct bmp * b, ssize_t id)
{
- ssize_t rid;
+ size_t rid;
if (b == NULL)
return -1;
diff --git a/src/lib/cdap.c b/src/lib/cdap.c
index 92a05221..4a6408f6 100644
--- a/src/lib/cdap.c
+++ b/src/lib/cdap.c
@@ -56,13 +56,14 @@ static int next_invoke_id(struct cdap * instance)
pthread_mutex_lock(&instance->ids_lock);
ret = bmp_allocate(instance->ids);
+ if (!bmp_is_id_valid(instance->ids, ret))
+ ret = -1; /* INVALID_INVOKE_ID */
pthread_mutex_unlock(&instance->ids_lock);
return ret;
}
-static int release_invoke_id(struct cdap * instance,
- int id)
+static int release_invoke_id(struct cdap * instance, int id)
{
int ret;
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 146070b7..86a5913e 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -285,7 +285,7 @@ void ap_fini()
for (i = 0; i < AP_MAX_FLOWS; ++i) {
if (ai.flows[i].tx_rb != NULL) {
- int idx;
+ ssize_t idx;
while ((idx = shm_rbuff_read(ai.flows[i].rx_rb)) >= 0)
shm_rdrbuff_remove(ai.rdrb, idx);
shm_rbuff_close(ai.flows[i].rx_rb);
@@ -467,6 +467,9 @@ int flow_alloc(char * dst_name, char * src_ae_name, struct qos_spec * qos)
irm_msg_t * recv_msg = NULL;
int fd = -1;
+ /* FIXME: add qos support */
+ (void) qos;
+
if (dst_name == NULL)
return -EINVAL;
@@ -755,8 +758,8 @@ ssize_t flow_write(int fd, void * buf, size_t count)
ssize_t flow_read(int fd, void * buf, size_t count)
{
- int idx = -1;
- int n;
+ ssize_t idx = -1;
+ ssize_t n;
uint8_t * sdu;
if (fd < 0 || fd >= AP_MAX_FLOWS)
@@ -794,7 +797,7 @@ ssize_t flow_read(int fd, void * buf, size_t count)
return -1;
}
- memcpy(buf, sdu, MIN(n, count));
+ memcpy(buf, sdu, MIN((size_t) n, count));
shm_rdrbuff_remove(ai.rdrb, idx);
@@ -949,7 +952,7 @@ int flow_event_wait(struct flow_set * set,
struct fqueue * fq,
const struct timespec * timeout)
{
- int ret;
+ ssize_t ret;
if (set == NULL)
return -EINVAL;
@@ -961,9 +964,6 @@ int flow_event_wait(struct flow_set * set,
if (ret == -ETIMEDOUT)
return -ETIMEDOUT;
- if (ret < 0)
- return ret;
-
fq->fqsize = ret;
fq->next = 0;
@@ -1214,7 +1214,7 @@ int ipcp_flow_alloc_reply(int fd, int response)
int ipcp_flow_read(int fd, struct shm_du_buff ** sdb)
{
- int idx = -1;
+ ssize_t idx = -1;
int port_id = -1;
pthread_rwlock_rdlock(&ai.data_lock);
@@ -1249,7 +1249,7 @@ int ipcp_flow_read(int fd, struct shm_du_buff ** sdb)
int ipcp_flow_write(int fd, struct shm_du_buff * sdb)
{
- ssize_t idx;
+ size_t idx;
if (sdb == NULL)
return -EINVAL;
@@ -1285,7 +1285,7 @@ ssize_t local_flow_read(int fd)
return shm_rbuff_read(ai.flows[fd].rx_rb);
}
-int local_flow_write(int fd, ssize_t idx)
+int local_flow_write(int fd, size_t idx)
{
if (fd < 0)
return -EINVAL;
@@ -1323,6 +1323,12 @@ int ipcp_read_shim(int fd, struct shm_du_buff ** sdb)
}
idx = shm_rbuff_read(ai.flows[fd].rx_rb);
+ if (idx < 0) {
+ pthread_rwlock_unlock(&ai.flows_lock);
+ pthread_rwlock_unlock(&ai.data_lock);
+ return -EAGAIN;
+ }
+
*sdb = shm_rdrbuff_get(ai.rdrb, idx);
pthread_rwlock_unlock(&ai.flows_lock);
diff --git a/src/lib/irm.c b/src/lib/irm.c
index c4c6395b..c68aa0f6 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -166,8 +166,8 @@ ssize_t irm_list_ipcps(char * name,
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
- ssize_t nr = -1;
- int i;
+ size_t nr = 0;
+ size_t i;
if (apis == NULL)
return -EINVAL;
diff --git a/src/lib/nsm.c b/src/lib/nsm.c
index 069db139..654b526b 100644
--- a/src/lib/nsm.c
+++ b/src/lib/nsm.c
@@ -26,6 +26,9 @@ int nsm_reg(char * name,
char ** dafs,
size_t dafs_size)
{
+ (void) name;
+ (void) dafs;
+ (void) dafs_size;
return -1;
}
@@ -34,6 +37,10 @@ int nsm_unreg(char * name,
char ** dafs,
size_t dafs_size)
{
+ (void) name;
+ (void) dafs;
+ (void) dafs_size;
+
return -1;
}
@@ -41,5 +48,8 @@ int nsm_unreg(char * name,
ssize_t nsm_resolve(char * name,
char ** dafs)
{
+ (void) name;
+ (void) dafs;
+
return -1;
}
diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index 04de9fc5..f68773aa 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -43,7 +43,7 @@
#define FN_MAX_CHARS 255
-#define FQUEUESIZE (SHM_BUFFER_SIZE * sizeof(int))
+#define FQUEUESIZE ((SHM_BUFFER_SIZE) * sizeof(int))
#define SHM_FLOW_SET_FILE_SIZE (IRMD_MAX_FLOWS * sizeof(ssize_t) \
+ AP_MAX_FQUEUES * sizeof(size_t) \
@@ -51,7 +51,7 @@
+ AP_MAX_FQUEUES * FQUEUESIZE \
+ sizeof(pthread_mutex_t))
-#define fqueue_ptr(fs, idx) (fs->fqueues + SHM_BUFFER_SIZE * idx)
+#define fqueue_ptr(fs, idx) (fs->fqueues + (SHM_BUFFER_SIZE) * idx)
struct shm_flow_set {
ssize_t * mtable;
@@ -123,7 +123,7 @@ struct shm_flow_set * shm_flow_set_create()
set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES);
set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES);
set->lock = (pthread_mutex_t *)
- (set->fqueues + AP_MAX_FQUEUES * SHM_BUFFER_SIZE);
+ (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE));
pthread_mutexattr_init(&mattr);
#ifndef __APPLE__
@@ -194,7 +194,7 @@ struct shm_flow_set * shm_flow_set_open(pid_t api)
set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES);
set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES);
set->lock = (pthread_mutex_t *)
- (set->fqueues + AP_MAX_FQUEUES * SHM_BUFFER_SIZE);
+ (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE));
set->api = api;
@@ -249,16 +249,16 @@ void shm_flow_set_close(struct shm_flow_set * set)
}
void shm_flow_set_zero(struct shm_flow_set * shm_set,
- ssize_t idx)
+ size_t idx)
{
ssize_t i = 0;
- assert(!(idx < 0) && idx < AP_MAX_FQUEUES);
+ assert(idx < AP_MAX_FQUEUES);
pthread_mutex_lock(shm_set->lock);
for (i = 0; i < IRMD_MAX_FLOWS; ++i)
- if (shm_set->mtable[i] == idx)
+ if (shm_set->mtable[i] == (ssize_t) idx)
shm_set->mtable[i] = -1;
shm_set->heads[idx] = 0;
@@ -268,12 +268,12 @@ void shm_flow_set_zero(struct shm_flow_set * shm_set,
int shm_flow_set_add(struct shm_flow_set * shm_set,
- ssize_t idx,
+ size_t idx,
int port_id)
{
assert(shm_set);
assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS);
- assert(!(idx < 0) && idx < AP_MAX_FQUEUES);
+ assert(idx < AP_MAX_FQUEUES);
pthread_mutex_lock(shm_set->lock);
@@ -290,34 +290,34 @@ int shm_flow_set_add(struct shm_flow_set * shm_set,
}
void shm_flow_set_del(struct shm_flow_set * shm_set,
- ssize_t idx,
+ size_t idx,
int port_id)
{
assert(shm_set);
assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS);
- assert(!(idx < 0) && idx < AP_MAX_FQUEUES);
+ assert(idx < AP_MAX_FQUEUES);
pthread_mutex_lock(shm_set->lock);
- if (shm_set->mtable[port_id] == idx)
+ if (shm_set->mtable[port_id] == (ssize_t) idx)
shm_set->mtable[port_id] = -1;
pthread_mutex_unlock(shm_set->lock);
}
int shm_flow_set_has(struct shm_flow_set * shm_set,
- ssize_t idx,
+ size_t idx,
int port_id)
{
int ret = 0;
assert(shm_set);
assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS);
- assert(!(idx < 0) && idx < AP_MAX_FQUEUES);
+ assert(idx < AP_MAX_FQUEUES);
pthread_mutex_lock(shm_set->lock);
- if (shm_set->mtable[port_id] == idx)
+ if (shm_set->mtable[port_id] == (ssize_t) idx)
ret = 1;
pthread_mutex_unlock(shm_set->lock);
@@ -346,16 +346,16 @@ void shm_flow_set_notify(struct shm_flow_set * shm_set, int port_id)
}
-int shm_flow_set_wait(const struct shm_flow_set * shm_set,
- ssize_t idx,
- int * fqueue,
- const struct timespec * timeout)
+ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set,
+ size_t idx,
+ int * fqueue,
+ const struct timespec * timeout)
{
- int ret = 0;
+ ssize_t ret = 0;
struct timespec abstime;
assert(shm_set);
- assert(!(idx < 0) && idx < AP_MAX_FQUEUES);
+ assert(idx < AP_MAX_FQUEUES);
#ifdef __APPLE__
pthread_mutex_lock(shm_set->lock);
@@ -397,11 +397,10 @@ int shm_flow_set_wait(const struct shm_flow_set * shm_set,
memcpy(fqueue,
fqueue_ptr(shm_set, idx),
shm_set->heads[idx] * sizeof(int));
- ret = shm_set->heads[idx];
shm_set->heads[idx] = 0;
}
pthread_cleanup_pop(true);
- return ret;
+ return 0;
}
diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c
index a933fbff..8b2e9229 100644
--- a/src/lib/shm_rbuff.c
+++ b/src/lib/shm_rbuff.c
@@ -44,14 +44,14 @@
#define FN_MAX_CHARS 255
-#define SHM_RBUFF_FILE_SIZE (SHM_BUFFER_SIZE * sizeof(ssize_t) \
+#define SHM_RBUFF_FILE_SIZE ((SHM_BUFFER_SIZE) * sizeof(ssize_t) \
+ 2 * sizeof(size_t) + sizeof(int8_t) \
+ sizeof(pthread_mutex_t) \
+ 2 * sizeof (pthread_cond_t))
-#define shm_rbuff_used(rb) ((*rb->head + SHM_BUFFER_SIZE - *rb->tail) \
- & (SHM_BUFFER_SIZE - 1))
-#define shm_rbuff_free(rb) (shm_rbuff_used(rb) + 1 < SHM_BUFFER_SIZE)
+#define shm_rbuff_used(rb) ((*rb->head + (SHM_BUFFER_SIZE) - *rb->tail) \
+ & ((SHM_BUFFER_SIZE) - 1))
+#define shm_rbuff_free(rb) (shm_rbuff_used(rb) + 1 < (SHM_BUFFER_SIZE))
#define shm_rbuff_empty(rb) (*rb->head == *rb->tail)
#define head_el_ptr(rb) (rb->shm_base + *rb->head)
#define tail_el_ptr(rb) (rb->shm_base + *rb->tail)
@@ -122,7 +122,7 @@ struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id)
}
rb->shm_base = shm_base;
- rb->head = (size_t *) (rb->shm_base + SHM_BUFFER_SIZE);
+ rb->head = (size_t *) (rb->shm_base + (SHM_BUFFER_SIZE));
rb->tail = rb->head + 1;
rb->acl = (int8_t *) (rb->tail + 1);
rb->lock = (pthread_mutex_t *) (rb->acl + 1);
@@ -198,7 +198,7 @@ struct shm_rbuff * shm_rbuff_open(pid_t api, int port_id)
}
rb->shm_base = shm_base;
- rb->head = (size_t *) (rb->shm_base + SHM_BUFFER_SIZE);
+ rb->head = (size_t *) (rb->shm_base + (SHM_BUFFER_SIZE));
rb->tail = rb->head + 1;
rb->acl = (int8_t *) (rb->tail + 1);
rb->lock = (pthread_mutex_t *) (rb->acl + 1);
@@ -236,10 +236,10 @@ void shm_rbuff_destroy(struct shm_rbuff * rb)
free(rb);
}
-int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx)
+int shm_rbuff_write(struct shm_rbuff * rb, size_t idx)
{
assert(rb);
- assert(idx >= 0);
+ assert(idx < SHM_BUFFER_SIZE);
#ifdef __APPLE__
pthread_mutex_lock(rb->lock);
@@ -262,8 +262,8 @@ int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx)
if (shm_rbuff_empty(rb))
pthread_cond_broadcast(rb->add);
- *head_el_ptr(rb) = idx;
- *rb->head = (*rb->head + 1) & (SHM_BUFFER_SIZE -1);
+ *head_el_ptr(rb) = (ssize_t) idx;
+ *rb->head = (*rb->head + 1) & ((SHM_BUFFER_SIZE) -1);
pthread_mutex_unlock(rb->lock);
@@ -272,7 +272,7 @@ int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx)
ssize_t shm_rbuff_read(struct shm_rbuff * rb)
{
- int ret = 0;
+ ssize_t ret = 0;
assert(rb);
@@ -286,11 +286,11 @@ ssize_t shm_rbuff_read(struct shm_rbuff * rb)
#endif
if (shm_rbuff_empty(rb)) {
pthread_mutex_unlock(rb->lock);
- return -1;
+ return -EAGAIN;
}
ret = *tail_el_ptr(rb);
- *rb->tail = (*rb->tail + 1) & (SHM_BUFFER_SIZE -1);
+ *rb->tail = (*rb->tail + 1) & ((SHM_BUFFER_SIZE) - 1);
pthread_mutex_unlock(rb->lock);
@@ -344,7 +344,7 @@ ssize_t shm_rbuff_read_b(struct shm_rbuff * rb,
if (idx != -ETIMEDOUT) {
idx = *tail_el_ptr(rb);
- *rb->tail = (*rb->tail + 1) & (SHM_BUFFER_SIZE -1);
+ *rb->tail = (*rb->tail + 1) & ((SHM_BUFFER_SIZE) - 1);
pthread_cond_broadcast(rb->del);
}
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index e5a37577..dc1feb10 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -41,30 +41,30 @@
#include <ouroboros/logs.h>
-#define SHM_BLOCKS_SIZE (SHM_BUFFER_SIZE * SHM_RDRB_BLOCK_SIZE)
-#define SHM_FILE_SIZE (SHM_BLOCKS_SIZE + 3 * sizeof (size_t) \
+#define SHM_BLOCKS_SIZE ((SHM_BUFFER_SIZE) * SHM_RDRB_BLOCK_SIZE)
+#define SHM_FILE_SIZE (SHM_BLOCKS_SIZE + 3 * sizeof(size_t) \
+ sizeof(pthread_mutex_t) + 2 * sizeof(pthread_cond_t) \
+ sizeof(pid_t))
#define get_head_ptr(rdrb) \
- ((struct shm_du_buff *)(rdrb->shm_base + (*rdrb->ptr_head * \
- SHM_RDRB_BLOCK_SIZE)))
+ ((struct shm_du_buff *) (rdrb->shm_base + (*rdrb->ptr_head \
+ * SHM_RDRB_BLOCK_SIZE)))
#define get_tail_ptr(rdrb) \
- ((struct shm_du_buff *)(rdrb->shm_base + (*rdrb->ptr_tail * \
- SHM_RDRB_BLOCK_SIZE)))
+ ((struct shm_du_buff *) (rdrb->shm_base + (*rdrb->ptr_tail \
+ * SHM_RDRB_BLOCK_SIZE)))
#define idx_to_du_buff_ptr(rdrb, idx) \
- ((struct shm_du_buff *)(rdrb->shm_base + (idx * SHM_RDRB_BLOCK_SIZE)))
+ ((struct shm_du_buff *) (rdrb->shm_base + idx * SHM_RDRB_BLOCK_SIZE))
#define block_ptr_to_idx(rdrb, sdb) \
(((uint8_t *)sdb - rdrb->shm_base) / SHM_RDRB_BLOCK_SIZE)
#define shm_rdrb_used(rdrb) \
- ((*rdrb->ptr_head + SHM_BUFFER_SIZE - *rdrb->ptr_tail) \
- & (SHM_BUFFER_SIZE - 1))
+ ((*rdrb->ptr_head + (SHM_BUFFER_SIZE) - *rdrb->ptr_tail) \
+ & ((SHM_BUFFER_SIZE) - 1))
#define shm_rdrb_free(rdrb, i) \
- (shm_rdrb_used(rdrb) + i < SHM_BUFFER_SIZE)
+ (shm_rdrb_used(rdrb) + i < (SHM_BUFFER_SIZE))
#define shm_rdrb_empty(rdrb) \
(*rdrb->ptr_tail == *rdrb->ptr_head)
@@ -99,11 +99,11 @@ static void garbage_collect(struct shm_rdrbuff * rdrb)
while (!shm_rdrb_empty(rdrb) &&
(sdb = get_tail_ptr(rdrb))->dst_api == -1)
*rdrb->ptr_tail = (*rdrb->ptr_tail + sdb->blocks)
- & (SHM_BUFFER_SIZE - 1);
+ & ((SHM_BUFFER_SIZE) - 1);
#else
while (!shm_rdrb_empty(rdrb) && get_tail_ptr(rdrb)->dst_api == -1)
*rdrb->ptr_tail =
- (*rdrb->ptr_tail + 1) & (SHM_BUFFER_SIZE - 1);
+ (*rdrb->ptr_tail + 1) & ((SHM_BUFFER_SIZE) - 1);
#endif
}
@@ -118,9 +118,9 @@ static void clean_sdus(struct shm_rdrbuff * rdrb, pid_t api)
if (buf->dst_api == api)
buf->dst_api = -1;
#ifdef SHM_RDRB_MULTI_BLOCK
- idx = (idx + buf->blocks) & (SHM_BUFFER_SIZE - 1);
+ idx = (idx + buf->blocks) & ((SHM_BUFFER_SIZE) - 1);
#else
- idx = (idx + 1) & (SHM_BUFFER_SIZE - 1);
+ idx = (idx + 1) & ((SHM_BUFFER_SIZE) - 1);
#endif
}
@@ -131,7 +131,7 @@ static void clean_sdus(struct shm_rdrbuff * rdrb, pid_t api)
static char * rdrb_filename(enum qos_cube qos)
{
- int chars = 0;
+ size_t chars = 0;
char * str;
int qm = QOS_MAX;
@@ -440,10 +440,10 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
struct shm_du_buff * sdb;
size_t size = headspace + len + tailspace;
#ifdef SHM_RDRB_MULTI_BLOCK
- long blocks = 0;
- long padblocks = 0;
+ size_t blocks = 0;
+ size_t padblocks = 0;
#endif
- int sz = size + sizeof *sdb;
+ ssize_t sz = size + sizeof(*sdb);
uint8_t * write_pos;
assert(rdrb);
@@ -469,10 +469,10 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
++blocks;
}
- if (blocks + *rdrb->ptr_head > SHM_BUFFER_SIZE)
- padblocks = SHM_BUFFER_SIZE - *rdrb->ptr_head;
+ if (blocks + *rdrb->ptr_head > (SHM_BUFFER_SIZE))
+ padblocks = (SHM_BUFFER_SIZE) - *rdrb->ptr_head;
- if (!shm_rdrb_free(rdrb, (blocks + padblocks))) {
+ if (!shm_rdrb_free(rdrb, blocks + padblocks)) {
#else
if (!shm_rdrb_free(rdrb, 1)) {
#endif
@@ -508,9 +508,9 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->idx = *rdrb->ptr_head;
#ifdef SHM_RDRB_MULTI_BLOCK
- *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & (SHM_BUFFER_SIZE - 1);
+ *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & ((SHM_BUFFER_SIZE) - 1);
#else
- *rdrb->ptr_head = (*rdrb->ptr_head + 1) & (SHM_BUFFER_SIZE - 1);
+ *rdrb->ptr_head = (*rdrb->ptr_head + 1) & ((SHM_BUFFER_SIZE) - 1);
#endif
pthread_mutex_unlock(rdrb->lock);
@@ -527,10 +527,10 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
struct shm_du_buff * sdb;
size_t size = headspace + len + tailspace;
#ifdef SHM_RDRB_MULTI_BLOCK
- long blocks = 0;
- long padblocks = 0;
+ size_t blocks = 0;
+ size_t padblocks = 0;
#endif
- int sz = size + sizeof *sdb;
+ ssize_t sz = size + sizeof(*sdb);
uint8_t * write_pos;
assert(rdrb);
@@ -550,7 +550,7 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
pthread_mutex_consistent(rdrb->lock);
}
#endif
- pthread_cleanup_push((void(*)(void *))pthread_mutex_unlock,
+ pthread_cleanup_push((void (*) (void *)) pthread_mutex_unlock,
(void *) rdrb->lock);
#ifdef SHM_RDRB_MULTI_BLOCK
@@ -559,8 +559,8 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
++blocks;
}
- if (blocks + *rdrb->ptr_head > SHM_BUFFER_SIZE)
- padblocks = SHM_BUFFER_SIZE - *rdrb->ptr_head;
+ if (blocks + *rdrb->ptr_head > (SHM_BUFFER_SIZE))
+ padblocks = (SHM_BUFFER_SIZE) - *rdrb->ptr_head;
while (!shm_rdrb_free(rdrb, (blocks + padblocks))) {
#else
@@ -597,27 +597,26 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->idx = *rdrb->ptr_head;
#ifdef SHM_RDRB_MULTI_BLOCK
- *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & (SHM_BUFFER_SIZE - 1);
+ *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & ((SHM_BUFFER_SIZE) - 1);
#else
- *rdrb->ptr_head = (*rdrb->ptr_head + 1) & (SHM_BUFFER_SIZE - 1);
+ *rdrb->ptr_head = (*rdrb->ptr_head + 1) & ((SHM_BUFFER_SIZE) - 1);
#endif
pthread_cleanup_pop(true);
return sdb->idx;
}
-int shm_rdrbuff_read(uint8_t ** dst,
- struct shm_rdrbuff * rdrb,
- ssize_t idx)
+ssize_t shm_rdrbuff_read(uint8_t ** dst,
+ struct shm_rdrbuff * rdrb,
+ size_t idx)
{
- size_t len = 0;
+ ssize_t len = 0;
struct shm_du_buff * sdb;
assert(dst);
assert(rdrb);
+ assert(idx < (SHM_BUFFER_SIZE));
- if (idx > SHM_BUFFER_SIZE)
- return -1;
#ifdef __APPLE__
pthread_mutex_lock(rdrb->lock);
#else
@@ -632,7 +631,7 @@ int shm_rdrbuff_read(uint8_t ** dst,
}
sdb = idx_to_du_buff_ptr(rdrb, idx);
- len = sdb->du_tail - sdb->du_head;
+ len = (ssize_t) (sdb->du_tail - sdb->du_head);
*dst = ((uint8_t *) (sdb + 1)) + sdb->du_head;
pthread_mutex_unlock(rdrb->lock);
@@ -640,14 +639,13 @@ int shm_rdrbuff_read(uint8_t ** dst,
return len;
}
-struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, ssize_t idx)
+struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
{
struct shm_du_buff * sdb;
assert(rdrb);
+ assert(idx < (SHM_BUFFER_SIZE));
- if (idx > SHM_BUFFER_SIZE)
- return NULL;
#ifdef __APPLE__
pthread_mutex_lock(rdrb->lock);
#else
@@ -668,12 +666,11 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, ssize_t idx)
return sdb;
}
-int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, ssize_t idx)
+int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx)
{
assert(rdrb);
+ assert(idx < (SHM_BUFFER_SIZE));
- if (idx > SHM_BUFFER_SIZE)
- return -1;
#ifdef __APPLE__
pthread_mutex_lock(rdrb->lock);
#else
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index c8375c22..db1f3f6b 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -144,7 +144,6 @@ static irm_msg_t * send_recv_irm_msg_timed(irm_msg_t * msg, bool timed)
if (write(sockfd, buf.data, buf.len) != -1)
count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE);
-
if (count > 0)
recv_msg = irm_msg__unpack(NULL, count, buf.data);
diff --git a/src/lib/tests/bitmap_test.c b/src/lib/tests/bitmap_test.c
index 4d2d0c73..7eb72fe7 100644
--- a/src/lib/tests/bitmap_test.c
+++ b/src/lib/tests/bitmap_test.c
@@ -35,6 +35,9 @@ int bitmap_test(int argc, char ** argv)
ssize_t r;
ssize_t offset = 100;
+ (void) argc;
+ (void) argv;
+
srand(time(NULL));
bmp = bmp_create(bits, offset);