summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-09-29 18:54:52 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-10-07 08:54:50 +0100
commit45eb0d5c014707614710d39287c264e7428ad0dd (patch)
tree8d7759f485272d78df20f0c81081f59eab1947ee
parent4a6ee3e1e958e489a35a1cf9d6b7ce2c906ba148 (diff)
Wait proper writer thread termination
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--tun.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/tun.c b/tun.c
index 0b91f18..6cfbce9 100644
--- a/tun.c
+++ b/tun.c
@@ -257,8 +257,14 @@ get_packet(void)
unsigned n;
pthread_mutex_lock(&pkt_buf_mtx);
- while (buf_allocated() == 0)
+ while (!term && buf_allocated() == 0) {
pthread_cond_wait(&pkt_cond_write, &pkt_buf_mtx);
+ }
+ if (term) {
+ pthread_mutex_unlock(&pkt_buf_mtx);
+ return NULL;
+ }
+
/* get the flow with the packet with minimum time to send */
min_flow = NULL;
@@ -464,4 +470,13 @@ handle_tun(void)
add_packet(flow, pkt);
pkt = alloc_packet();
}
+ term = 1;
+
+ /* wake up write if blocked to pick up the termination */
+ pthread_mutex_lock(&pkt_buf_mtx);
+ pthread_cond_signal(&pkt_cond_write);
+ pthread_mutex_unlock(&pkt_buf_mtx);
+
+ /* wait writer termination */
+ pthread_join(writer, NULL);
}