ao_write: Join threads before returning an error from aow_post_select().
[paraslash.git] / ao_write.c
index af6882420f02377e9a48c695b72af6fdb20b43e8..4281f536d87ffaa58f3621c0edf95535893188ca 100644 (file)
@@ -40,10 +40,7 @@ static void aow_close(struct writer_node *wn)
 
        if (!pawd)
                return;
-       if (pawd->thread_btrn) {
-               pthread_cancel(pawd->thread);
-               pthread_join(pawd->thread, NULL);
-       }
+       assert(!pawd->thread_btrn);
        ao_close(pawd->dev);
        free(pawd);
        wn->private_data = NULL;
@@ -352,8 +349,10 @@ static int aow_post_select(__a_unused struct sched *s,
                return 0;
        }
        if (!wn->btrn) {
-               if (!pawd->thread_btrn)
+               if (!pawd->thread_btrn) {
+                       pthread_join(pawd->thread, NULL);
                        return -E_AO_EOF;
+               }
                PARA_INFO_LOG("waiting for play thread to terminate\n");
                return 0;
        }