summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-03-31 22:41:43 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-04-01 14:25:39 +0200
commit67fcb9107ae73fd1a4ccb30e4922f0dee0bd29a5 (patch)
treeefd58bca3a7c0d2302bbc9c9eaffa1d0dc95ad89 /src
parent304bf4f90f58f28d6941d3e3b14bb04d48f52392 (diff)
downloadouroboros-67fcb9107ae73fd1a4ccb30e4922f0dee0bd29a5.tar.gz
ouroboros-67fcb9107ae73fd1a4ccb30e4922f0dee0bd29a5.zip
lib: Fix data race in rdrbuff
The blocks should be accessed inside the lock (or later with CAS).
Diffstat (limited to 'src')
-rw-r--r--src/lib/shm_rdrbuff.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index b8d73650..9dffdf74 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -380,6 +380,8 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->flags = SDB_VALID;
sdb->idx = *rdrb->head;
#ifdef SHM_RDRB_MULTI_BLOCK
+ sdb->blocks = blocks;
+
*rdrb->head = (*rdrb->head + blocks) & ((SHM_BUFFER_SIZE) - 1);
#else
*rdrb->head = (*rdrb->head + 1) & ((SHM_BUFFER_SIZE) - 1);
@@ -389,9 +391,7 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->size = size;
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
-#ifdef SHM_RDRB_MULTI_BLOCK
- sdb->blocks = blocks;
-#endif
+
memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
@@ -461,6 +461,8 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->flags = SDB_VALID;
sdb->idx = *rdrb->head;
#ifdef SHM_RDRB_MULTI_BLOCK
+ sdb->blocks = blocks;
+
*rdrb->head = (*rdrb->head + blocks) & ((SHM_BUFFER_SIZE) - 1);
#else
*rdrb->head = (*rdrb->head + 1) & ((SHM_BUFFER_SIZE) - 1);
@@ -470,12 +472,8 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->size = size;
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
-#ifdef SHM_RDRB_MULTI_BLOCK
- sdb->blocks = blocks;
-#endif
memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
-
return sdb->idx;
}