diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2018-10-25 21:58:21 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2018-10-26 08:52:31 +0200 |
commit | 96682a8284cc234207d2ba6a60b8f9939c17834f (patch) | |
tree | 98b523a2f05e0f5777a177bddc1926a7658244fc /src/lib/dev.c | |
parent | 991470de0c7b59c69dd2de8110ba1ddef042a473 (diff) | |
download | ouroboros-96682a8284cc234207d2ba6a60b8f9939c17834f.tar.gz ouroboros-96682a8284cc234207d2ba6a60b8f9939c17834f.zip |
lib: Revise du buff API towards a memory allocator
This changes the API to the rdrbuff to treat it as a pool memory
allocator. The head and tailspace to allocate in a buffer is now set
system-wide instead of being passed as a parameter.
Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be>
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 3c1494ee..d596758e 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -855,6 +855,7 @@ ssize_t flow_write(int fd, struct timespec abs; struct timespec * abstime = NULL; struct shm_du_buff * sdb; + uint8_t * ptr; if (buf == NULL) return 0; @@ -886,22 +887,20 @@ ssize_t flow_write(int fd, return -EPERM; if (flags & FLOWFWNOBLOCK) - idx = shm_rdrbuff_write(ai.rdrb, - DU_BUFF_HEADSPACE, - DU_BUFF_TAILSPACE, - buf, - count); + idx = shm_rdrbuff_alloc(ai.rdrb, + count, + &ptr, + &sdb); else /* Blocking. */ - idx = shm_rdrbuff_write_b(ai.rdrb, - DU_BUFF_HEADSPACE, - DU_BUFF_TAILSPACE, - buf, + idx = shm_rdrbuff_alloc_b(ai.rdrb, count, + &ptr, + &sdb, abstime); if (idx < 0) return idx; - sdb = shm_rdrbuff_get(ai.rdrb, idx); + memcpy(ptr, buf, count); if (frcti_snd(flow->frcti, sdb) < 0) { shm_rdrbuff_remove(ai.rdrb, idx); @@ -1442,21 +1441,7 @@ int ipcp_flow_write(int fd, int ipcp_sdb_reserve(struct shm_du_buff ** sdb, size_t len) { - ssize_t idx; - - idx = shm_rdrbuff_write_b(ai.rdrb, - DU_BUFF_HEADSPACE, - DU_BUFF_TAILSPACE, - NULL, - len, - NULL); - - if (idx < 0) - return -1; - - *sdb = shm_rdrbuff_get(ai.rdrb, idx); - - return 0; + return shm_rdrbuff_alloc_b(ai.rdrb, len, NULL, sdb, NULL) < 0 ? -1 : 0; } void ipcp_sdb_release(struct shm_du_buff * sdb) |