[Libreoffice-commits] online.git: loolwsd/Util.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Aug 15 03:13:20 UTC 2016
loolwsd/Util.hpp | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
New commits:
commit 359731f0969b33a8a4f387678831baba4a12c5ae
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Aug 14 00:01:45 2016 -0400
loolwsd: cleanup of RuntimeConstant class
Change-Id: If3d57e73445cdb0b92c6b3721b4b7b0ca030a2d7
Reviewed-on: https://gerrit.libreoffice.org/28129
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index f3425fe..c69315e 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -202,28 +202,32 @@ namespace Util
std::set<std::string> _denied;
};
+ /// A logical constant that is allowed to initialize
+ /// exactly once and checks usage before initialization.
template<typename T>
class RuntimeConstant
{
T _value;
- bool _initialized;
+ std::atomic<bool> _initialized;
public:
RuntimeConstant()
: _value()
, _initialized(false)
- {}
+ {
+ }
+
+ /// Use a compile-time const instead.
+ RuntimeConstant(const T& value) = delete;
const T& get()
{
- if(_initialized)
+ if (_initialized)
{
return _value;
}
- else
- {
- throw std::runtime_error("RuntimeConstant instance read before being initialized.");
- }
+
+ throw std::runtime_error("RuntimeConstant instance read before being initialized.");
}
void set(const T& value)
More information about the Libreoffice-commits
mailing list