summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-08-16 12:11:21 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-08-16 12:11:21 +0200
commit6b33850f488ddd23fa29952a8c5d2a7c544617d3 (patch)
tree0ac36f828e5bafc09f2b2d72dbadd3608e7d239e
parentc8283ea410e7d640537303c6b644bbc3afb35cd5 (diff)
downloadouroboros-6b33850f488ddd23fa29952a8c5d2a7c544617d3.tar.gz
ouroboros-6b33850f488ddd23fa29952a8c5d2a7c544617d3.zip
irmd, ipcpd: Signal acceptor only
This adds an extra condvar so the mainloops can signal the acceptor thread without waking up all mainloops.
-rw-r--r--src/ipcpd/ipcp.c12
-rw-r--r--src/ipcpd/ipcp.h1
-rw-r--r--src/irmd/main.c16
3 files changed, 24 insertions, 5 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index c5769f9e..7066fb04 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -138,7 +138,7 @@ static void * acceptloop(void * o)
pthread_cond_signal(&ipcpi.cmd_cond);
while (ipcpi.csockfd != -1)
- pthread_cond_wait(&ipcpi.cmd_cond, &ipcpi.cmd_lock);
+ pthread_cond_wait(&ipcpi.acc_cond, &ipcpi.cmd_lock);
pthread_mutex_unlock(&ipcpi.cmd_lock);
}
@@ -189,7 +189,7 @@ static void * mainloop(void * o)
continue;
}
- pthread_cond_broadcast(&ipcpi.cmd_cond);
+ pthread_cond_signal(&ipcpi.acc_cond);
msg = ipcp_msg__unpack(NULL, ipcpi.cmd_len, ipcpi.cbuf);
if (msg == NULL) {
@@ -591,6 +591,11 @@ int ipcp_init(int argc,
goto fail_cmd_cond;
}
+ if (pthread_cond_init(&ipcpi.acc_cond, &cattr)) {
+ log_err("Failed to init convar.");
+ goto fail_acc_cond;
+ }
+
ipcpi.alloc_id = -1;
ipcpi.csockfd = -1;
@@ -607,6 +612,8 @@ int ipcp_init(int argc,
return 0;
fail_shim_data:
+ pthread_cond_destroy(&ipcpi.acc_cond);
+ fail_acc_cond:
pthread_cond_destroy(&ipcpi.cmd_cond);
fail_cmd_cond:
pthread_mutex_destroy(&ipcpi.cmd_lock);
@@ -702,6 +709,7 @@ void ipcp_fini()
pthread_mutex_destroy(&ipcpi.state_mtx);
pthread_cond_destroy(&ipcpi.alloc_cond);
pthread_mutex_destroy(&ipcpi.alloc_lock);
+ pthread_cond_destroy(&ipcpi.acc_cond);
pthread_cond_destroy(&ipcpi.cmd_cond);
pthread_mutex_destroy(&ipcpi.cmd_lock);
diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h
index d2ad7cde..422670d7 100644
--- a/src/ipcpd/ipcp.h
+++ b/src/ipcpd/ipcp.h
@@ -93,6 +93,7 @@ struct ipcp {
uint8_t cbuf[IPCP_MSG_BUF_SIZE];
size_t cmd_len;
int csockfd;
+ pthread_cond_t acc_cond;
pthread_cond_t cmd_cond;
pthread_mutex_t cmd_lock;
diff --git a/src/irmd/main.c b/src/irmd/main.c
index a316b3cf..61ce6a49 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -101,6 +101,7 @@ struct {
uint8_t cbuf[IB_LEN]; /* cmd message buffer */
size_t cmd_len; /* length of cmd in cbuf */
int csockfd; /* cmd UNIX socket */
+ pthread_cond_t acc_cond; /* cmd accepted condvar */
pthread_cond_t cmd_cond; /* cmd signal condvar */
pthread_mutex_t cmd_lock; /* cmd signal lock */
@@ -1476,6 +1477,7 @@ static void irm_fini(void)
lockfile_destroy(irmd.lf);
pthread_mutex_destroy(&irmd.cmd_lock);
+ pthread_cond_destroy(&irmd.acc_cond);
pthread_cond_destroy(&irmd.cmd_cond);
pthread_rwlock_destroy(&irmd.reg_lock);
pthread_rwlock_destroy(&irmd.state_lock);
@@ -1737,7 +1739,7 @@ static void * acceptloop(void * o)
pthread_cond_signal(&irmd.cmd_cond);
while(irmd.csockfd != -1)
- pthread_cond_wait(&irmd.cmd_cond, &irmd.cmd_lock);
+ pthread_cond_wait(&irmd.acc_cond, &irmd.cmd_lock);
pthread_mutex_unlock(&irmd.cmd_lock);
}
@@ -1762,7 +1764,7 @@ void * mainloop(void * o)
struct irm_flow * e = NULL;
pid_t * apis = NULL;
struct timespec * timeo = NULL;
- struct timespec ts = {0,0};
+ struct timespec ts = {0, 0};
ret_msg.code = IRM_MSG_CODE__IRM_REPLY;
@@ -1788,7 +1790,7 @@ void * mainloop(void * o)
continue;
}
- pthread_cond_broadcast(&irmd.cmd_cond);
+ pthread_cond_signal(&irmd.acc_cond);
msg = irm_msg__unpack(NULL, irmd.cmd_len, irmd.cbuf);
if (msg == NULL) {
@@ -2013,6 +2015,12 @@ static int irm_init(void)
goto fail_cmd_cond;
}
+ if (pthread_cond_init(&irmd.acc_cond, &cattr)) {
+ log_err("Failed to initialize condvar.");
+ pthread_condattr_destroy(&cattr);
+ goto fail_acc_cond;
+ }
+
pthread_condattr_destroy(&cattr);
list_head_init(&irmd.ipcps);
@@ -2100,6 +2108,8 @@ static int irm_init(void)
fail_lockfile:
bmp_destroy(irmd.port_ids);
fail_port_ids:
+ pthread_cond_destroy(&irmd.acc_cond);
+ fail_acc_cond:
pthread_cond_destroy(&irmd.cmd_cond);
fail_cmd_cond:
pthread_mutex_destroy(&irmd.cmd_lock);