summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/fmgr.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-12 11:55:52 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-12 11:55:52 +0200
commit44cc6aaa41d88dc978a087178fd74a1c2dba70fd (patch)
tree10b398bf23356751a961c332a9dff053c6927f24 /src/ipcpd/normal/fmgr.c
parentcf30e07cf862b117013e8c7fa2fb5c2ac8fef245 (diff)
parent5432e665fd6eac776c5985d98058e5c4645ec0e4 (diff)
downloadouroboros-44cc6aaa41d88dc978a087178fd74a1c2dba70fd.tar.gz
ouroboros-44cc6aaa41d88dc978a087178fd74a1c2dba70fd.zip
Merged in sandervrijders/ouroboros/be-state-mutex (pull request #209)
ipcpd: Add condition variable to IPCP state
Diffstat (limited to 'src/ipcpd/normal/fmgr.c')
-rw-r--r--src/ipcpd/normal/fmgr.c30
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;