summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-15 02:31:54 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-05-15 02:31:54 +0200
commite79f151adc07538fbb1057442df2c1fe6ac01836 (patch)
treeeb5162928789f8c0eed25a8d00a53d2f93d9cb9e /src
parentcbd6ccb7fa372832715b0e143c816f569bd07ccd (diff)
downloadouroboros-e79f151adc07538fbb1057442df2c1fe6ac01836.tar.gz
ouroboros-e79f151adc07538fbb1057442df2c1fe6ac01836.zip
lib: shm_ap_rbuff: simplified file offsets
Used simpler pointer arithmetic to calculate the file offset pointers.
Diffstat (limited to 'src')
-rw-r--r--src/lib/shm_ap_rbuff.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index da6f0e33..0524a96c 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -38,7 +38,7 @@
#define SHM_RBUFF_FILE_SIZE (SHM_RBUFF_SIZE * sizeof(struct rb_entry) \
+ 2 * sizeof(size_t) + sizeof(pthread_mutex_t))
-#define shm_rbuff_used(rb)((*rb->ptr_head + SHM_RBUFF_SIZE - *rb->ptr_tail)\
+#define shm_rbuff_used(rb)((*rb->ptr_head + SHM_RBUFF_SIZE - *rb->ptr_tail) \
& (SHM_RBUFF_SIZE - 1))
#define shm_rbuff_free(rb)(shm_rbuff_used(rb) + 1 < SHM_RBUFF_SIZE)
@@ -105,12 +105,10 @@ struct shm_ap_rbuff * shm_ap_rbuff_create()
return NULL;
}
- rb->shm_base = shm_base;
- rb->ptr_head = (size_t *) (rb->shm_base + SHM_RBUFF_SIZE);
- rb->ptr_tail = (size_t *)
- ((uint8_t *) rb->ptr_head + sizeof(size_t));
- rb->shm_mutex = (pthread_mutex_t *)
- ((uint8_t *) rb->ptr_tail + sizeof(size_t));
+ rb->shm_base = shm_base;
+ rb->ptr_head = (size_t *) (rb->shm_base + SHM_RBUFF_SIZE);
+ rb->ptr_tail = rb->ptr_head + 1;
+ rb->shm_mutex = (pthread_mutex_t *) (rb->ptr_tail + 1);
pthread_mutexattr_init(&attr);
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
@@ -165,12 +163,10 @@ struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid)
return NULL;
}
- rb->shm_base = shm_base;
- rb->ptr_head = (size_t *) (rb->shm_base + SHM_RBUFF_SIZE);
- rb->ptr_tail = (size_t *)
- ((uint8_t *) rb->ptr_head + sizeof(size_t));
- rb->shm_mutex = (pthread_mutex_t *)
- ((uint8_t *) rb->ptr_tail + sizeof(size_t));
+ rb->shm_base = shm_base;
+ rb->ptr_head = (size_t *) (rb->shm_base + SHM_RBUFF_SIZE);
+ rb->ptr_tail = rb->ptr_head + 1;
+ rb->shm_mutex = (pthread_mutex_t *) (rb->ptr_tail + 1);
rb->fd = shm_fd;
rb->pid = pid;