Skip to content

Commit da791f3

Browse files
committed
fix: make thread safe
1 parent 160bdec commit da791f3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

app/src/core/time/time.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <chrono>
44
#include <ctime>
55
#include <iomanip>
6+
#include <mutex>
67
#include <optional>
78
#include <sstream>
89
#include <string>
@@ -15,6 +16,8 @@ namespace fastchess::time {
1516

1617
namespace sc = std::chrono;
1718

19+
inline std::mutex mutex_time;
20+
1821
// Get the current date and time in a given format.
1922
[[nodiscard]] inline std::optional<std::string> datetime(const std::string &format) {
2023
// Get the current time in UTC
@@ -43,6 +46,8 @@ namespace sc = std::chrono;
4346
}
4447

4548
[[nodiscard]] inline std::string datetime_iso() {
49+
std::lock_guard<std::mutex> lock(mutex_time);
50+
4651
auto now = std::chrono::system_clock::now();
4752
auto now_c = std::chrono::system_clock::to_time_t(now);
4853

0 commit comments

Comments
 (0)