From b15f8552d629021c3cadef3e7afcae2fa98dad1b Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Sun, 30 Jul 2017 05:06:18 +0300 Subject: Improve gen_adldata program - Now it caches all generated data, so, we won't have to re-calculate same - File is writing by gen_adldata nor by stdout forward - Instead of hardcoded list of banks, I made the INI file which declares list of banks to generate - Add simple validators to tell which bank is absense and can't be loaded - Split code of gen_adldata.cc into multiple files of different role --- src/gen_adldata/measurer.h | 105 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/gen_adldata/measurer.h (limited to 'src/gen_adldata/measurer.h') diff --git a/src/gen_adldata/measurer.h b/src/gen_adldata/measurer.h new file mode 100644 index 0000000..ba60ad7 --- /dev/null +++ b/src/gen_adldata/measurer.h @@ -0,0 +1,105 @@ +#ifndef MEASURER_H +#define MEASURER_H + +#include +#include +#include +#include +#include + +#include "progs_cache.h" + +struct DurationInfo +{ + uint64_t peak_amplitude_time; + double peak_amplitude_value; + double quarter_amplitude_time; + double begin_amplitude; + double interval; + double keyoff_out_time; + int64_t ms_sound_kon; + int64_t ms_sound_koff; + bool nosound; + uint8_t padding[7]; +}; + +class Semaphore +{ +public: + Semaphore(int count_ = 0) + : m_count(count_) {} + + inline void notify() + { + std::unique_lock lock(mtx); + m_count++; + cv.notify_one(); + } + + inline void wait() + { + std::unique_lock lock(mtx); + while(m_count == 0) + { + cv.wait(lock); + } + m_count--; + } + +private: + std::mutex mtx; + std::condition_variable cv; + std::atomic_int m_count; +}; + +struct MeasureThreaded +{ + typedef std::map DurationInfoCache; + + MeasureThreaded() : + m_semaphore(9), + m_done(0), + m_cache_matches(0) + {} + + Semaphore m_semaphore; + std::mutex m_durationInfo_mx; + DurationInfoCache m_durationInfo; + std::atomic_bool m_delete_tail; + size_t m_total = 0; + std::atomic m_done; + std::atomic m_cache_matches; + + void LoadCache(const char *fileName); + void SaveCache(const char *fileName); + + struct destData + { + destData() + { + m_works = true; + } + ~destData() + { + m_work.join(); + } + MeasureThreaded *myself; + std::map > >::const_iterator i; + std::thread m_work; + std::atomic_bool m_works; + + void start(); + static void callback(void *myself); + }; + + std::vector m_threads; + + void printProgress(); + void printFinal(); + void run(InstrumentsData::const_iterator i); + void waitAll(); +}; + +extern DurationInfo MeasureDurations(const ins &in); + +#endif // MEASURER_H -- cgit v1.2.3