void timeshift_destroy(streaming_target_t *pad) { timeshift_t *ts = (timeshift_t*)pad; streaming_message_t *sm; /* Must hold global lock */ lock_assert(&global_lock); /* Ensure the threads exits */ // Note: this is a workaround for the fact the Q might have been flushed // in reader thread (VERY unlikely) pthread_mutex_lock(&ts->state_mutex); sm = streaming_msg_create(SMT_EXIT); streaming_target_deliver2(&ts->wr_queue.sq_st, sm); timeshift_write_exit(ts->rd_pipe.wr); pthread_mutex_unlock(&ts->state_mutex); /* Wait for all threads */ pthread_join(ts->rd_thread, NULL); pthread_join(ts->wr_thread, NULL); /* Shut stuff down */ streaming_queue_deinit(&ts->wr_queue); close(ts->rd_pipe.rd); close(ts->rd_pipe.wr); /* Flush files */ timeshift_filemgr_flush(ts, NULL); free(ts->path); free(ts); }
void timeshift_destroy(streaming_target_t *pad) { timeshift_t *ts = (timeshift_t*)pad; streaming_message_t *sm; int i; /* Must hold global lock */ lock_assert(&global_lock); /* Ensure the threads exits */ // Note: this is a workaround for the fact the Q might have been flushed // in reader thread (VERY unlikely) pthread_mutex_lock(&ts->state_mutex); sm = streaming_msg_create(SMT_EXIT); streaming_target_deliver2(&ts->wr_queue.sq_st, sm); timeshift_write_exit(ts->rd_pipe.wr); pthread_mutex_unlock(&ts->state_mutex); /* Wait for all threads */ pthread_join(ts->rd_thread, NULL); pthread_join(ts->wr_thread, NULL); /* Shut stuff down */ streaming_queue_deinit(&ts->wr_queue); for (i = 0; i < TIMESHIFT_BACKLOG_MAX; i++) streaming_queue_clear(&ts->backlog[i]); close(ts->rd_pipe.rd); close(ts->rd_pipe.wr); /* Flush files */ timeshift_filemgr_flush(ts, NULL); /* Release SMT_START index */ if (ts->smt_start) streaming_start_unref(ts->smt_start); if (ts->path) free(ts->path); free(ts); }