Initial commit

This commit is contained in:
Nav
2021-04-04 21:04:12 +01:00
commit a29c5e1fec
549 changed files with 441216 additions and 0 deletions

42
src/Helpers/DateTime.hpp Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <mutex>
#include <QDateTime>
namespace Bloom
{
/**
* Some (maybe all) QDateTime static functions are not thread-safe and thus can result in data races.
* This trivial helper class wraps some of these functions and employs a mutex to prevent data races.
*/
class DateTime
{
private:
static inline std::mutex currentDateTimeMutex;
public:
/**
* The QDateTime::currentDateTime() static function is not thread-safe. This may be caused by the
* underlying interfacing with the system clock.
*
* @return
*/
static QDateTime currentDateTime() {
auto lock = std::unique_lock(DateTime::currentDateTimeMutex);
return QDateTime::currentDateTime();
}
/**
* The QDateTime::timeZoneAbbreviation() is a non-static member function but it may still interface with the
* system clock. This can result in race conditions when called simultaneously to QDateTime::currentDateTime(),
* and so any calls to it must require possession of the mutex.
*
* @param dateTime
* @return
*/
static QString getTimeZoneAbbreviation(const QDateTime& dateTime) {
auto lock = std::unique_lock(DateTime::currentDateTimeMutex);
return dateTime.timeZoneAbbreviation();
}
};
}