summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-04-04 18:01:56 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-04-04 18:01:56 +0000
commit99ff1ce1bd4602b471b758a144f372bc6e1570f8 (patch)
treed42bb5c12ef262f2e343ab3b6369837ebbe65954 /src/ipcpd
parentc6bda726506552db2135b15df97d3ba76d6ae0a5 (diff)
parent8ccd10988661b9e5070cd08b0a1ce8d911e17270 (diff)
downloadouroboros-99ff1ce1bd4602b471b758a144f372bc6e1570f8.tar.gz
ouroboros-99ff1ce1bd4602b471b758a144f372bc6e1570f8.zip
Merged in dstaesse/ouroboros/be-irmd-res (pull request #460)
Be irmd res
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/ipcp.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index ee5bd76e..fc0e3587 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -522,27 +522,19 @@ int ipcp_init(int argc,
return 0;
}
-static bool is_thread_alive(ssize_t id)
-{
- bool ret;
- pthread_mutex_lock(&ipcpi.threads_lock);
-
- ret = bmp_is_id_used(ipcpi.thread_ids, id);
-
- pthread_mutex_unlock(&ipcpi.threads_lock);
-
- return ret;
-}
-
void * threadpoolmgr(void * o)
{
- struct timespec to = {(IPCP_TPM_TIMEOUT / 1000),
- (IPCP_TPM_TIMEOUT % 1000) * MILLION};
+ pthread_attr_t pattr;
struct timespec dl;
- size_t t;
-
+ struct timespec to = {(IRMD_TPM_TIMEOUT / 1000),
+ (IRMD_TPM_TIMEOUT % 1000) * MILLION};
(void) o;
+ if (pthread_attr_init(&pattr))
+ return (void *) -1;
+
+ pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED);
+
while (true) {
clock_gettime(PTHREAD_COND_CLOCK, &dl);
ts_add(&dl, &to, &dl);
@@ -551,12 +543,13 @@ void * threadpoolmgr(void * o)
if (ipcp_get_state() == IPCP_SHUTDOWN ||
ipcp_get_state() == IPCP_NULL) {
pthread_rwlock_unlock(&ipcpi.state_lock);
- log_dbg("Threadpool manager exiting.");
- for (t = 0; t < IPCP_MAX_THREADS; ++t)
- if (is_thread_alive(t)) {
- log_dbg("Waiting for thread %zd.", t);
- pthread_join(ipcpi.threadpool[t], NULL);
- }
+ pthread_attr_destroy(&pattr);
+ log_dbg("Waiting for threads to exit.");
+ pthread_mutex_lock(&ipcpi.threads_lock);
+ while (ipcpi.threads > 0)
+ pthread_cond_wait(&ipcpi.threads_cond,
+ &ipcpi.threads_lock);
+ pthread_mutex_unlock(&ipcpi.threads_lock);
log_dbg("Threadpool manager done.");
break;
@@ -578,7 +571,7 @@ void * threadpoolmgr(void * o)
}
if (pthread_create(&ipcpi.threadpool[id],
- NULL, ipcp_main_loop,
+ &pattr, ipcp_main_loop,
(void *) id))
log_warn("Failed to start new thread.");
else