summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-07-12 10:31:13 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-07-12 10:31:13 +0000
commit3e9ee89b3ccf48dcabf7de2ecafcfbf637595cfe (patch)
treec2e257101d4f52190a5fc6e2e00e8b6d8d637932
parent9bbc7b4ba57a13e425fcfdfd6bd7ba5248255721 (diff)
parenteaa2dff945366ed43b28fb1ae8e5c10ce95d9964 (diff)
downloadouroboros-3e9ee89b3ccf48dcabf7de2ecafcfbf637595cfe.tar.gz
ouroboros-3e9ee89b3ccf48dcabf7de2ecafcfbf637595cfe.zip
Merged in dstaesse/ouroboros/be-irmd-shutdown (pull request #527)
irmd: Shutdown sanitizer without cancellation
-rw-r--r--include/ouroboros/shm_rdrbuff.h4
-rw-r--r--src/irmd/main.c9
-rw-r--r--src/lib/shm_rdrbuff.c31
3 files changed, 31 insertions, 13 deletions
diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h
index fb12be74..1af8d0c9 100644
--- a/include/ouroboros/shm_rdrbuff.h
+++ b/include/ouroboros/shm_rdrbuff.h
@@ -26,6 +26,7 @@
#include <ouroboros/shm_du_buff.h>
#include <ouroboros/qoscube.h>
+#include <ouroboros/time_utils.h>
#include <stdint.h>
#include <pthread.h>
@@ -41,7 +42,8 @@ void shm_rdrbuff_close(struct shm_rdrbuff * rdrb);
void shm_rdrbuff_destroy(struct shm_rdrbuff * rdrb);
-void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb);
+int shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb,
+ struct timespec * timeo);
/* returns the index of the buffer in the DU map */
ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
diff --git a/src/irmd/main.c b/src/irmd/main.c
index b2e6ba9c..db6f33de 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1514,8 +1514,9 @@ void * shm_sanitize(void * o)
(void) o;
- while (true) {
- shm_rdrbuff_wait_full(irmd.rdrb);
+ while (irmd_get_state() == IRMD_RUNNING) {
+ if (shm_rdrbuff_wait_full(irmd.rdrb, &ts) == -ETIMEDOUT)
+ continue;
pthread_rwlock_wrlock(&irmd.flows_lock);
@@ -1536,8 +1537,6 @@ void * shm_sanitize(void * o)
}
pthread_rwlock_unlock(&irmd.flows_lock);
-
- nanosleep(&ts, NULL);
}
return (void *) 0;
@@ -2247,8 +2246,6 @@ int main(int argc,
pthread_join(irmd.tpm, NULL);
pthread_join(irmd.irm_sanitize, NULL);
-
- pthread_cancel(irmd.shm_sanitize);
pthread_join(irmd.shm_sanitize, NULL);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index ed9c3847..1f999f93 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -264,8 +264,15 @@ struct shm_rdrbuff * shm_rdrbuff_open()
return rdrb;
}
-void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb)
+int shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb,
+ struct timespec * timeo)
{
+ struct timespec abstime;
+
+ if (timeo != NULL) {
+ clock_gettime(PTHREAD_COND_CLOCK, &abstime);
+ ts_add(&abstime, timeo, &abstime);
+ }
#ifdef __APPLE__
pthread_mutex_lock(rdrb->lock);
@@ -273,21 +280,33 @@ void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb)
if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD)
pthread_mutex_consistent(rdrb->lock);
#endif
- pthread_cleanup_push((void (*)(void *)) pthread_mutex_unlock,
- (void *) rdrb->lock);
while (shm_rdrb_free(rdrb, WAIT_BLOCKS)) {
#ifdef __APPLE__
- pthread_cond_wait(rdrb->full, rdrb->lock);
+ if (pthread_cond_timedwait(rdrb->full,
+ rdrb->lock
+ &abstime) == ETIMEDOUT) {
+ pthread_mutex_unlock(rdrb->lock);
+ return -ETIMEDOUT;
+ }
#else
- if (pthread_cond_wait(rdrb->full, rdrb->lock) == EOWNERDEAD)
+ int ret = pthread_cond_timedwait(rdrb->full,
+ rdrb->lock,
+ &abstime);
+ if (ret == EOWNERDEAD)
pthread_mutex_consistent(rdrb->lock);
+ if (ret == ETIMEDOUT) {
+ pthread_mutex_unlock(rdrb->lock);
+ return -ETIMEDOUT;
+ }
#endif
}
garbage_collect(rdrb);
- pthread_cleanup_pop(true);
+ pthread_mutex_unlock(rdrb->lock);
+
+ return 0;
}
void shm_rdrbuff_close(struct shm_rdrbuff * rdrb)