File tree 2 files changed +12
-2
lines changed
2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ class appender {
179
179
180
180
template <bool sync = false , bool enable_console = false >
181
181
void write_record (record_t &record) {
182
- std::lock_guard guard (get_mutex<sync >());
182
+ std::unique_lock guard (get_mutex<sync >());
183
183
if constexpr (sync == true ) {
184
184
if (max_files_ > 0 && file_size_ > max_file_size_ &&
185
185
static_cast <size_t >(-1 ) != file_size_) {
@@ -204,6 +204,8 @@ class appender {
204
204
write_file (msg);
205
205
206
206
if constexpr (enable_console) {
207
+ guard.unlock ();
208
+ std::unique_lock guard1 (get_mutex<true >());
207
209
add_color (record.get_severity ());
208
210
std::cout << time_str;
209
211
clean_color (record.get_severity ());
@@ -405,7 +407,7 @@ class appender {
405
407
bool has_init_ = false ;
406
408
std::string filename_;
407
409
408
- bool enable_console_ = false ;
410
+ std::atomic< bool > enable_console_ = false ;
409
411
bool flush_every_time_;
410
412
size_t file_size_ = 0 ;
411
413
size_t max_file_size_ = 0 ;
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class session_manager {
60
60
}
61
61
62
62
void start_check_session_timer () {
63
+ std::lock_guard lock (timer_mtx_);
63
64
std::weak_ptr<asio::steady_timer> timer = check_session_timer_;
64
65
check_session_timer_->expires_after (check_session_duration_);
65
66
check_session_timer_->async_wait ([this , timer](auto ec) {
@@ -79,6 +80,12 @@ class session_manager {
79
80
80
81
void set_check_session_duration (auto duration) {
81
82
check_session_duration_ = duration;
83
+ {
84
+ std::lock_guard lock (timer_mtx_);
85
+ std::error_code ec;
86
+ check_session_timer_->cancel (ec);
87
+ }
88
+
82
89
start_check_session_timer ();
83
90
}
84
91
@@ -100,6 +107,7 @@ class session_manager {
100
107
// session_timeout_ should be no less than 0
101
108
std::size_t session_timeout_ = 86400 ;
102
109
std::atomic<bool > stop_timer_ = false ;
110
+ std::mutex timer_mtx_;
103
111
std::shared_ptr<asio::steady_timer> check_session_timer_;
104
112
std::atomic<std::chrono::steady_clock::duration> check_session_duration_ = {
105
113
std::chrono::seconds (15 )};
You can’t perform that action at this time.
0 commit comments