summaryrefslogtreecommitdiff
path: root/src/lib/shm_rdrbuff.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-09-07 15:00:12 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-09-07 15:00:12 +0200
commitab83ed430081d2833faa31b7f1cf187b043e56be (patch)
treebc432f673bb453b8fc7789cff363b9b49e8fbaf5 /src/lib/shm_rdrbuff.c
parentdd1047b0e457c45d45a1b5b83972d4a75968cce2 (diff)
parent2cf4f88fc8b957c15ae93a2eb3e56ebdb07a0381 (diff)
downloadouroboros-ab83ed430081d2833faa31b7f1cf187b043e56be.tar.gz
ouroboros-ab83ed430081d2833faa31b7f1cf187b043e56be.zip
Merged in sandervrijders/ouroboros/be-shm-pci (pull request #247)
ipcpd: normal: Add operations to get and set the PCI
Diffstat (limited to 'src/lib/shm_rdrbuff.c')
-rw-r--r--src/lib/shm_rdrbuff.c117
1 files changed, 29 insertions, 88 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index 3eae8f97..7c4927fc 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -688,32 +688,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;
}
@@ -721,37 +721,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;
}
@@ -759,78 +741,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;
}