diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2016-09-29 18:54:52 +0100 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2016-10-07 08:54:50 +0100 |
commit | 45eb0d5c014707614710d39287c264e7428ad0dd (patch) | |
tree | 8d7759f485272d78df20f0c81081f59eab1947ee | |
parent | 4a6ee3e1e958e489a35a1cf9d6b7ce2c906ba148 (diff) |
Wait proper writer thread termination
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | tun.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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); } |