diff options
author | Sander Vrijders <[email protected]> | 2016-09-06 10:29:02 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-09-07 13:58:21 +0200 |
commit | 2cf4f88fc8b957c15ae93a2eb3e56ebdb07a0381 (patch) | |
tree | 1b3bd39aa4b84132559cc8032024f44a1e9c8015 /src/lib/shm_rdrbuff.c | |
parent | ee2235c62cf0c51f7188fdeb6ac283c1e2ea0335 (diff) | |
download | ouroboros-2cf4f88fc8b957c15ae93a2eb3e56ebdb07a0381.tar.gz ouroboros-2cf4f88fc8b957c15ae93a2eb3e56ebdb07a0381.zip |
ipcpd: normal: Add operations to get and set the PCI
This adds the operations needed in the normal IPCP to get and set the
Protocol Control Information. It allows to allocate or release space
in the current DU. The struct pci can be serialized into newly
allocate space. Vice versa, a struct pci can be deserialized given a
DU. It allows for decreasing the TTL in the DU and for calculating the
CRC32. The TTL and CRC32 can now be selected when creating a new DIF.
Diffstat (limited to 'src/lib/shm_rdrbuff.c')
-rw-r--r-- | src/lib/shm_rdrbuff.c | 117 |
1 files changed, 29 insertions, 88 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 93a889ce..b0d295d9 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -690,32 +690,32 @@ int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, ssize_t idx) return 0; } -uint8_t * shm_du_buff_head_alloc(struct shm_rdrbuff * rdrb, - ssize_t idx, - size_t size) +uint8_t * shm_du_buff_head(struct shm_du_buff * sdb) { - struct shm_du_buff * sdb; - uint8_t * buf; - - if (rdrb == NULL) + if (sdb == NULL) return NULL; - if (idx < 0 || idx > SHM_BUFFER_SIZE) + return (uint8_t *) (sdb + 1) + sdb->du_head; +} + +uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb) +{ + if (sdb == NULL) return NULL; -#ifdef __APPLE__ - pthread_mutex_lock(rdrb->lock); -#else - if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) { - LOG_DBGF("Recovering dead mutex."); - pthread_mutex_consistent(rdrb->lock); - } -#endif - sdb = idx_to_du_buff_ptr(rdrb, idx); + return (uint8_t *) (sdb + 1) + sdb->du_tail; +} + +uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb, + size_t size) +{ + uint8_t * buf = NULL; + + if (sdb == NULL) + return NULL; if ((long) (sdb->du_head - size) < 0) { - pthread_mutex_unlock(rdrb->lock); - LOG_DBGF("Failed to allocate PCI headspace."); + LOG_ERR("Failed to allocate PCI headspace."); return NULL; } @@ -723,37 +723,19 @@ uint8_t * shm_du_buff_head_alloc(struct shm_rdrbuff * rdrb, buf = (uint8_t *) (sdb + 1) + sdb->du_head; - pthread_mutex_unlock(rdrb->lock); - return buf; } -uint8_t * shm_du_buff_tail_alloc(struct shm_rdrbuff * rdrb, - ssize_t idx, +uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb, size_t size) { - struct shm_du_buff * sdb; - uint8_t * buf; - - if (rdrb == NULL) - return NULL; + uint8_t * buf = NULL; - if (idx < 0 || idx > SHM_BUFFER_SIZE) + if (sdb == NULL) return NULL; -#ifdef __APPLE__ - pthread_mutex_lock(rdrb->lock); -#else - if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) { - LOG_DBGF("Recovering dead mutex."); - pthread_mutex_consistent(rdrb->lock); - } -#endif - sdb = idx_to_du_buff_ptr(rdrb, idx); - if (sdb->du_tail + size >= sdb->size) { - pthread_mutex_unlock(rdrb->lock); - LOG_DBGF("Failed to allocate PCI tailspace."); + LOG_ERR("Failed to allocate PCI tailspace."); return NULL; } @@ -761,78 +743,37 @@ uint8_t * shm_du_buff_tail_alloc(struct shm_rdrbuff * rdrb, sdb->du_tail += size; - pthread_mutex_unlock(rdrb->lock); - return buf; } -int shm_du_buff_head_release(struct shm_rdrbuff * rdrb, - ssize_t idx, +int shm_du_buff_head_release(struct shm_du_buff * sdb, size_t size) { - struct shm_du_buff * sdb; - - if (rdrb == NULL) - return -1; - - if (idx < 0 || idx > SHM_BUFFER_SIZE) + if (sdb == NULL) return -1; -#ifdef __APPLE__ - pthread_mutex_lock(rdrb->lock); -#else - if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) { - LOG_DBGF("Recovering dead mutex."); - pthread_mutex_consistent(rdrb->lock); - } -#endif - - sdb = idx_to_du_buff_ptr(rdrb, idx); - if (size > sdb->du_tail - sdb->du_head) { - pthread_mutex_unlock(rdrb->lock); - LOG_DBGF("Tried to release beyond sdu boundary."); + LOG_DBGF("Tried to release beyond SDU boundary."); return -EOVERFLOW; } sdb->du_head += size; - pthread_mutex_unlock(rdrb->lock); - return 0; } -int shm_du_buff_tail_release(struct shm_rdrbuff * rdrb, - ssize_t idx, +int shm_du_buff_tail_release(struct shm_du_buff * sdb, size_t size) { - struct shm_du_buff * sdb; - - if (rdrb == NULL) - return -1; - - if (idx < 0 || idx > SHM_BUFFER_SIZE) + if (sdb == NULL) return -1; -#ifdef __APPLE__ - pthread_mutex_lock(rdrb->lock); -#else - if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) { - LOG_DBGF("Recovering dead mutex."); - pthread_mutex_consistent(rdrb->lock); - } -#endif - sdb = idx_to_du_buff_ptr(rdrb, idx); - if (size > sdb->du_tail - sdb->du_head) { - pthread_mutex_unlock(rdrb->lock); - LOG_DBGF("Tried to release beyond sdu boundary."); + LOG_ERR("Tried to release beyond SDU boundary."); return -EOVERFLOW; } sdb->du_tail -= size; - pthread_mutex_unlock(rdrb->lock); - return 0; } |