From feeb5bff6fb4e9bb46ffa74672d6c5a78c87cbb0 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 6 Apr 2016 11:43:47 -0700 Subject: [PATCH] Move AudioThread con/destruction to proper places. --- firmware/application/audio_thread.hpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/firmware/application/audio_thread.hpp b/firmware/application/audio_thread.hpp index 2a8cac18e..6f87c1df6 100644 --- a/firmware/application/audio_thread.hpp +++ b/firmware/application/audio_thread.hpp @@ -59,8 +59,12 @@ class AudioThread { public: AudioThread( std::string file_path - ) : file_path { std::move(file_path) } + ) : write_buffer { std::make_unique>() } { + if( !file.open_for_append(file_path) ) { + return; + } + // Need significant stack for FATFS thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this); } @@ -84,8 +88,7 @@ private: static constexpr size_t write_size = 4096; static constexpr eventmask_t EVT_FIFO_HIGHWATER = 1; - const std::string file_path; - + std::unique_ptr> write_buffer; File file; static Thread* thread; @@ -97,15 +100,6 @@ private: } void run() { - auto write_buffer = std::make_unique>(); - if( !write_buffer ) { - return; - } - - if( !file.open_for_append(file_path) ) { - return; - } - bool success = true; while( success && !chThdShouldTerminate() ) { chEvtWaitAny(EVT_FIFO_HIGHWATER); @@ -125,8 +119,6 @@ private: if( !success ) { led_tx.on(); } - - file.close(); } bool transfer(StreamOutput& stream, std::array* const write_buffer) {