diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-11 17:39:39 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-11 17:39:39 +0200 |
commit | 5432e665fd6eac776c5985d98058e5c4645ec0e4 (patch) | |
tree | 10b398bf23356751a961c332a9dff053c6927f24 /src/ipcpd/normal/fmgr.c | |
parent | cf30e07cf862b117013e8c7fa2fb5c2ac8fef245 (diff) | |
download | ouroboros-5432e665fd6eac776c5985d98058e5c4645ec0e4.tar.gz ouroboros-5432e665fd6eac776c5985d98058e5c4645ec0e4.zip |
ipcpd: Add condition variable to IPCP state
This adds a condition variable to the IPCP state, so that upon state
changes any listeners to state changes can be notified. It also
replaces the read/write lock with a mutex in order to be able to do
so.
Diffstat (limited to 'src/ipcpd/normal/fmgr.c')
-rw-r--r-- | src/ipcpd/normal/fmgr.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index f9de16c4..70afff37 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -80,21 +80,22 @@ static void * fmgr_listen(void * o) int fd; char * ae_name; - /* FIXME: Avoid busy wait and react to pthread_cond_t */ - pthread_rwlock_rdlock(&_ipcp->state_lock); - while (!(_ipcp->state == IPCP_ENROLLED || - _ipcp->state == IPCP_SHUTDOWN)) { - pthread_rwlock_unlock(&_ipcp->state_lock); - sched_yield(); - pthread_rwlock_rdlock(&_ipcp->state_lock); - } + while (true) { + pthread_mutex_lock(&_ipcp->state_lock); + while (!(_ipcp->state == IPCP_ENROLLED || + _ipcp->state == IPCP_SHUTDOWN)) + pthread_cond_wait(&_ipcp->state_cond, + &_ipcp->state_lock); + + if (_ipcp->state == IPCP_SHUTDOWN) { + pthread_mutex_unlock(&_ipcp->state_lock); + return 0; + } + pthread_mutex_unlock(&_ipcp->state_lock); - while (_ipcp->state != IPCP_SHUTDOWN) { - pthread_rwlock_unlock(&_ipcp->state_lock); fd = flow_accept(&ae_name); if (fd < 0) { LOG_ERR("Failed to accept flow."); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } @@ -103,14 +104,12 @@ static void * fmgr_listen(void * o) if (flow_alloc_resp(fd, -1)) LOG_ERR("Failed to reply to flow allocation."); flow_dealloc(fd); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } if (flow_alloc_resp(fd, 0)) { LOG_ERR("Failed to reply to flow allocation."); flow_dealloc(fd); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } @@ -121,7 +120,6 @@ static void * fmgr_listen(void * o) if (ribmgr_add_flow(fd)) { LOG_ERR("Failed to hand fd to RIB."); flow_dealloc(fd); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } } @@ -130,7 +128,6 @@ static void * fmgr_listen(void * o) if (frct_dt_flow(fd)) { LOG_ERR("Failed to hand fd to FRCT."); flow_dealloc(fd); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } } @@ -138,11 +135,8 @@ static void * fmgr_listen(void * o) if (add_n_1_fd(fd, ae_name)) { LOG_ERR("Failed to add file descriptor to list."); flow_dealloc(fd); - pthread_rwlock_rdlock(&_ipcp->state_lock); continue; } - - pthread_rwlock_rdlock(&_ipcp->state_lock); } return (void *) 0; |