summaryrefslogtreecommitdiff
path: root/src/lib/shm_rdrbuff.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-03-31 22:41:43 +0200
committerdimitri staessens <[email protected]>2017-04-01 08:32:14 +0200
commitd426058a82137d3186a245b0548a262fbd35761b (patch)
tree4984d594cb171f6333d99b3a858a5cfa6f372106 /src/lib/shm_rdrbuff.c
parent47c24ddbd6d2766797e4c2f3e05a93f0cb45f2cd (diff)
downloadouroboros-d426058a82137d3186a245b0548a262fbd35761b.tar.gz
ouroboros-d426058a82137d3186a245b0548a262fbd35761b.zip
lib: Fix data race in rdrbuff
The blocks should be accessed inside the lock (or later with CAS).
Diffstat (limited to 'src/lib/shm_rdrbuff.c')
-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;
}