From 8a1f7dc159cc7a85e92975e1b25fdce1368e8c8e Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 29 Mar 2022 20:43:20 +0200 Subject: 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 Signed-off-by: Sander Vrijders --- src/lib/dev.c | 27 +++++++++++++++------------ src/lib/shm_flow_set.c | 21 +++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src/lib') 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; -- cgit v1.2.3