Some improvements to Lazy<T> class.

This commit is contained in:
LoRd_MuldeR 2018-04-15 15:12:13 +02:00
parent 5673c6f14a
commit a9f2eeb3be

View File

@ -53,26 +53,20 @@ namespace MUtils
T& operator*(void)
{
T *value;
do
while (!(value = m_value.fetchAndAddOrdered(0)))
{
if (!(value = m_value.fetchAndAddOrdered(0)))
if (!(value = m_initializer()))
{
if (value = m_initializer())
{
if (!m_value.testAndSetOrdered(NULL, value))
{
delete value;
value = NULL;
}
}
else
{
MUTILS_THROW("Initializer returned NULL pointer!");
}
MUTILS_THROW("Initializer returned NULL pointer!");
}
if (m_value.testAndSetOrdered(NULL, value))
{
break; /*success*/
}
delete value;
value = NULL;
}
while (!value);
return *m_value;
return *value;
}
~Lazy(void)