From eb45a7913d83fe2a3dc03033230950e78fb9755d Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Fri, 20 Oct 2017 04:28:53 +0300 Subject: Added CMake support --- utils/gen_adldata/measurer.h | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 utils/gen_adldata/measurer.h (limited to 'utils/gen_adldata/measurer.h') diff --git a/utils/gen_adldata/measurer.h b/utils/gen_adldata/measurer.h new file mode 100644 index 0000000..b9ae3c6 --- /dev/null +++ b/utils/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(int(std::thread::hardware_concurrency()) * 2), + 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