mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-09 15:09:50 +03:00
Use atomic in timer struct
This commit is contained in:
@@ -51,7 +51,6 @@ void timer::start_of_cycle() {
|
||||
if (history_counter >= HISTORY_COUNT)
|
||||
history_counter = 0;
|
||||
|
||||
std::unique_lock<std::mutex> u_lock(freq_mtx);
|
||||
freq_hist = 1000.0 / (freq / HISTORY_COUNT);
|
||||
}
|
||||
|
||||
@@ -70,17 +69,14 @@ void timer::end_of_cycle() {
|
||||
}
|
||||
|
||||
double_t timer::get_freq() {
|
||||
std::unique_lock<std::mutex> u_lock(freq_mtx);
|
||||
return freq;
|
||||
}
|
||||
|
||||
void timer::set_freq(double_t freq) {
|
||||
std::unique_lock<std::mutex> u_lock(freq_mtx);
|
||||
this->freq = freq;
|
||||
void timer::set_freq(double_t value) {
|
||||
freq = value;
|
||||
}
|
||||
|
||||
double_t timer::get_freq_hist() {
|
||||
std::unique_lock<std::mutex> u_lock(freq_hist_mtx);
|
||||
return freq_hist;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "default.hpp"
|
||||
#include "waitable_timer.hpp"
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
#define HISTORY_COUNT 0x08
|
||||
|
||||
@@ -17,10 +17,8 @@ struct timer {
|
||||
LARGE_INTEGER curr_time;
|
||||
LARGE_INTEGER prev_time;
|
||||
double_t inv_freq;
|
||||
double_t freq;
|
||||
double_t freq_hist;
|
||||
std::mutex freq_mtx;
|
||||
std::mutex freq_hist_mtx;
|
||||
std::atomic<double_t> freq;
|
||||
std::atomic<double_t> freq_hist;
|
||||
waitable_timer wait_timer;
|
||||
|
||||
timer(double_t freq);
|
||||
@@ -29,7 +27,7 @@ struct timer {
|
||||
void start_of_cycle();
|
||||
void end_of_cycle();
|
||||
double_t get_freq();
|
||||
void set_freq(double_t freq);
|
||||
void set_freq(double_t value);
|
||||
double_t get_freq_hist();
|
||||
void reset();
|
||||
void sleep(double_t msec);
|
||||
|
||||
Reference in New Issue
Block a user