summaryrefslogtreecommitdiff
path: root/src/ipcpd/local
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-04-05 14:28:24 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-05 14:28:24 +0200
commitc5b092665c219c679ede91b3dc816c61f2f9dabe (patch)
treee60083545da6ce0dc5fdacd06610d907b90c5aee /src/ipcpd/local
parentfa1590539e66c17902bb4f09221e6447b3233bfb (diff)
downloadouroboros-c5b092665c219c679ede91b3dc816c61f2f9dabe.tar.gz
ouroboros-c5b092665c219c679ede91b3dc816c61f2f9dabe.zip
ipcpd: Add lock for allocation requests
This adds a lock to prevent a race condition between flow_req_arr and flow_alloc_resp.
Diffstat (limited to 'src/ipcpd/local')
-rw-r--r--src/ipcpd/local/main.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 3e5c4803..88d0912e 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -223,33 +223,22 @@ static int ipcp_local_flow_alloc(int fd,
return -1; /* -ENOTENROLLED */
}
- /*
- * This function needs to return completely before
- * flow_resp. Taking the wrlock on the data is the simplest
- * way to achieve this.
- */
-
- pthread_rwlock_wrlock(&local_data.lock);
+ pthread_mutex_lock(&ipcpi.alloc_lock);
out_fd = ipcp_flow_req_arr(getpid(), dst_name, cube);
if (out_fd < 0) {
- pthread_rwlock_unlock(&local_data.lock);
+ pthread_mutex_unlock(&ipcpi.alloc_lock);
log_dbg("Flow allocation failed: %d", out_fd);
return -1;
}
- /*
- * The idea of the port_wait_assign in dev.c was to do the
- * above synchronisation. But if the lock is not taken, the
- * resp() function may be called before a lock would be taken
- * here. This shim will be deprecated, but ideally the sync is
- * fixed in ipcp.c.
- */
+ pthread_rwlock_wrlock(&local_data.lock);
local_data.in_out[fd] = out_fd;
local_data.in_out[out_fd] = fd;
pthread_rwlock_unlock(&local_data.lock);
+ pthread_mutex_unlock(&ipcpi.alloc_lock);
flow_set_add(local_data.flows, fd);