summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2022-03-29 20:43:20 +0200
committerSander Vrijders <sander@ouroboros.rocks>2022-03-30 15:12:25 +0200
commit8a1f7dc159cc7a85e92975e1b25fdce1368e8c8e (patch)
tree37f51528030dfe81d9568006c33ae3af65d49305
parente38f7c74dc0383fc5daf3eea7a7ab63fae6379fa (diff)
downloadouroboros-8a1f7dc159cc7a85e92975e1b25fdce1368e8c8e.tar.gz
ouroboros-8a1f7dc159cc7a85e92975e1b25fdce1368e8c8e.zip
lib: Use struct portevent internally
The fqueues were relying on the fact that the portevent were two integers. This cleans that up a bit. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--include/ouroboros/shm_flow_set.h7
-rw-r--r--src/lib/dev.c27
-rw-r--r--src/lib/shm_flow_set.c21
3 files changed, 32 insertions, 23 deletions
diff --git a/include/ouroboros/shm_flow_set.h b/include/ouroboros/shm_flow_set.h
index ba085aef..62bf24e9 100644
--- a/include/ouroboros/shm_flow_set.h
+++ b/include/ouroboros/shm_flow_set.h
@@ -27,6 +27,11 @@
#include <sys/time.h>
+struct portevent {
+ int flow_id;
+ int event;
+};
+
struct shm_flow_set;
struct shm_flow_set * shm_flow_set_create(pid_t pid);
@@ -58,7 +63,7 @@ void shm_flow_set_notify(struct shm_flow_set * set,
ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set,
size_t idx,
- int * fqueue,
+ struct portevent * fqueue,
const struct timespec * abstime);
#endif /* OUROBOROS_SHM_FLOW_SET_H */
diff --git a/src/lib/dev.c b/src/lib/dev.c
index db6c9827..7ffc2a0a 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -122,9 +122,9 @@ struct flow_set {
};
struct fqueue {
- int fqueue[2 * SHM_BUFFER_SIZE]; /* Safe copy from shm. */
- size_t fqsize;
- size_t next;
+ struct portevent fqueue[SHM_BUFFER_SIZE]; /* Safe copy from shm. */
+ size_t fqsize;
+ size_t next;
};
struct {
@@ -1509,7 +1509,7 @@ struct fqueue * fqueue_create()
if (fq == NULL)
return NULL;
- memset(fq->fqueue, -1, (SHM_BUFFER_SIZE) * sizeof(*fq->fqueue));
+ memset(fq->fqueue, -1, SHM_BUFFER_SIZE * sizeof(*fq->fqueue));
fq->fqsize = 0;
fq->next = 0;
@@ -1618,12 +1618,12 @@ static int fqueue_filter(struct fqueue * fq)
struct frcti * frcti;
while (fq->next < fq->fqsize) {
- if (fq->fqueue[fq->next + 1] != FLOW_PKT)
+ if (fq->fqueue[fq->next].event != FLOW_PKT)
return 1;
pthread_rwlock_rdlock(&ai.lock);
- fd = ai.ports[fq->fqueue[fq->next]].fd;
+ fd = ai.ports[fq->fqueue[fq->next].flow_id].fd;
frcti = ai.flows[fd].frcti;
if (frcti == NULL) {
pthread_rwlock_unlock(&ai.lock);
@@ -1654,7 +1654,7 @@ static int fqueue_filter(struct fqueue * fq)
pthread_rwlock_unlock(&ai.lock);
- fq->next += 2;
+ ++fq->next;
}
return fq->next < fq->fqsize;
@@ -1662,7 +1662,8 @@ static int fqueue_filter(struct fqueue * fq)
int fqueue_next(struct fqueue * fq)
{
- int fd;
+ int fd;
+ struct portevent * e;
if (fq == NULL)
return -EINVAL;
@@ -1675,9 +1676,11 @@ int fqueue_next(struct fqueue * fq)
pthread_rwlock_rdlock(&ai.lock);
- fd = ai.ports[fq->fqueue[fq->next]].fd;
+ e = fq->fqueue + fq->next;
+
+ fd = ai.ports[e->flow_id].fd;
- fq->next += 2;
+ ++fq->next;
pthread_rwlock_unlock(&ai.lock);
@@ -1692,7 +1695,7 @@ enum fqtype fqueue_type(struct fqueue * fq)
if (fq->fqsize == 0 || fq->next == 0)
return -EPERM;
- return fq->fqueue[fq->next - 1];
+ return fq->fqueue[(fq->next - 1)].event;
}
ssize_t fevent(struct flow_set * set,
@@ -1721,7 +1724,7 @@ ssize_t fevent(struct flow_set * set,
if (ret == -ETIMEDOUT)
return -ETIMEDOUT;
- fq->fqsize = ret << 1;
+ fq->fqsize = ret;
fq->next = 0;
ret = fqueue_filter(fq);
diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index d325a253..25e7e32b 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -63,11 +63,6 @@
#define fqueue_ptr(fs, idx) (fs->fqueues + (SHM_BUFFER_SIZE) * idx)
-struct portevent {
- int flow_id;
- int event;
-};
-
struct shm_flow_set {
ssize_t * mtable;
size_t * heads;
@@ -307,6 +302,8 @@ void shm_flow_set_notify(struct shm_flow_set * set,
int flow_id,
int event)
{
+ struct portevent * e;
+
assert(set);
assert(!(flow_id < 0) && flow_id < SYS_MAX_FLOWS);
@@ -317,10 +314,14 @@ void shm_flow_set_notify(struct shm_flow_set * set,
return;
}
- (fqueue_ptr(set, set->mtable[flow_id]) +
- (set->heads[set->mtable[flow_id]]))->flow_id = flow_id;
- (fqueue_ptr(set, set->mtable[flow_id]) +
- (set->heads[set->mtable[flow_id]])++)->event = event;
+
+ e = fqueue_ptr(set, set->mtable[flow_id]) +
+ set->heads[set->mtable[flow_id]];
+
+ e->flow_id = flow_id;
+ e->event = event;
+
+ ++set->heads[set->mtable[flow_id]];
pthread_cond_signal(&set->conds[set->mtable[flow_id]]);
@@ -330,7 +331,7 @@ void shm_flow_set_notify(struct shm_flow_set * set,
ssize_t shm_flow_set_wait(const struct shm_flow_set * set,
size_t idx,
- int * fqueue,
+ struct portevent * fqueue,
const struct timespec * abstime)
{
ssize_t ret = 0;