summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-06 16:46:52 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-04-06 16:51:02 +0200
commita4ce5e7d47d27c8b582e27b38ce61c9cb9735992 (patch)
treeec99dad12704ff9728d408fb93b356d449fe70c8 /src/ipcpd/ipcp.c
parent0f9954dd086834a996d5585d923364b765b752e4 (diff)
downloadouroboros-a4ce5e7d47d27c8b582e27b38ce61c9cb9735992.tar.gz
ouroboros-a4ce5e7d47d27c8b582e27b38ce61c9cb9735992.zip
ipcpd: Fix race condition with concurrent allocs
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r--src/ipcpd/ipcp.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index f08e4ce7..587d70c5 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -262,11 +262,9 @@ static void * ipcp_main_loop(void * o)
}
ret_msg.has_result = true;
- pthread_mutex_lock(&ipcpi.alloc_lock);
ret_msg.result =
ipcpi.ops->ipcp_flow_alloc_resp(fd,
msg->response);
- pthread_mutex_unlock(&ipcpi.alloc_lock);
break;
case IPCP_MSG_CODE__IPCP_FLOW_DEALLOC:
if (ipcpi.ops->ipcp_flow_dealloc == NULL) {
@@ -455,6 +453,13 @@ int ipcp_init(int argc,
goto fail_alloc_lock;
}
+ if (pthread_cond_init(&ipcpi.alloc_cond, NULL)) {
+ log_err("Failed to init convar.");
+ goto fail_alloc_cond;
+ }
+
+ ipcpi.alloc_id = -1;
+
if (type == IPCP_NORMAL) {
pthread_condattr_destroy(&cattr);
return 0;
@@ -471,6 +476,8 @@ int ipcp_init(int argc,
return 0;
fail_shim_data:
+ pthread_cond_destroy(&ipcpi.alloc_cond);
+ fail_alloc_cond:
pthread_mutex_destroy(&ipcpi.alloc_lock);
fail_alloc_lock:
bmp_destroy(ipcpi.thread_ids);
@@ -601,6 +608,8 @@ void ipcp_fini()
pthread_mutex_destroy(&ipcpi.threads_lock);
pthread_mutex_destroy(&ipcpi.state_mtx);
pthread_rwlock_destroy(&ipcpi.state_lock);
+ pthread_cond_destroy(&ipcpi.alloc_cond);
+ pthread_mutex_destroy(&ipcpi.alloc_lock);
log_fini();