*/
#define MUTILS_BOOL2STR(X) ((X) ? "1" : "0")
+/** \brief Converts a given expression into a boolean expression, by application of double negation operator.
+*/
+#define MUTILS_BOOLIFY(X) (!(!(X)))
+
/** \brief Disables copy constructor and assignment operator in the specified class. This macro should be used in the "private" section of the class' declaration.
*/
#define MUTILS_NO_COPY(CLASS) \
const QString m_binaryGnuPG;
const QString m_binaryKeys;
- volatile bool m_success;
+ QAtomicInt m_success;
QAtomicInt m_cancelled;
int m_status;
public:
inline CSLocker(CriticalSection &criticalSection)
:
- m_locked(false),
m_criticalSection(criticalSection)
{
m_criticalSection.enter();
- m_locked = true;
+ m_locked.ref();
}
inline ~CSLocker(void)
inline void forceUnlock(void)
{
- if(m_locked)
+ if (m_locked.fetchAndStoreOrdered(0) > 0)
{
m_criticalSection.leave();
- m_locked = false;
}
}
protected:
- volatile bool m_locked;
+ QAtomicInt m_locked;
CriticalSection &m_criticalSection;
};
}
{ \
return false; \
} \
- if(!(p->initialized || initialize())) \
+ if(!(MUTILS_BOOLIFY(p->initialized) || initialize())) \
{ \
qWarning("Taskbar initialization failed!"); \
return false; \
Taskbar7_Private(void)
{
taskbarList = NULL;
- supported = false;
- initialized = false;
}
ITaskbarList3 *taskbarList;
- volatile bool supported;
- volatile bool initialized;
+ QAtomicInt supported;
+ QAtomicInt initialized;
};
}
{
MUTILS_THROW("Taskbar7: Window pointer must not be NULL!");
}
- if(!(p->supported = (OS::os_version() >= OS::Version::WINDOWS_WIN70)))
+ if (!p->supported)
{
- qWarning("Taskbar7: Taskbar progress not supported on this platform.");
+ if (OS::os_version() >= OS::Version::WINDOWS_WIN70)
+ {
+ p->supported.ref();
+ }
+ else
+ {
+ qWarning("Taskbar7: Taskbar progress not supported on this platform.");
+ }
}
}
p->taskbarList = ptbl;
}
- while(!p->initialized)
+ if(!p->initialized)
{
bool okay = false;
for(int i = 0; i < 8; i++)
qWarning("ITaskbarList3::HrInit() has failed!");
return false;
}
- p->initialized = true;
+ p->initialized.ref(); /*success*/
}
return true;
static MUtils::Internal::CriticalSection g_terminal_lock;
//Is terminal attached?
-static volatile bool g_terminal_attached = false;
+static QAtomicInt g_terminal_attached;
//Terminal output buffer
static const size_t BUFF_SIZE = 8192;
{
MUtils::Internal::CSLocker lock(g_terminal_lock);
- if (g_terminal_attached)
+ if (g_terminal_attached.fetchAndStoreOrdered(0) > 0)
{
g_fileBuf_stdout.reset();
g_fileBuf_stderr.reset();
if(stderr) freopen_s(&temp[1], "NUL", "wb", stderr);
FreeConsole();
set_hicon(&g_terminal_icon, NULL);
- g_terminal_attached = false;
}
}
if(enableConsole)
{
- if(!g_terminal_attached)
+ if(!g_terminal_attached.fetchAndStoreOrdered(1))
{
if(AllocConsole() != FALSE)
{
_snprintf_s(title, 128, _TRUNCATE, "%s | Debug Console", appName);
SetConsoleTitleA(title);
}
- g_terminal_attached = true;
+ }
+ else
+ {
+ g_terminal_attached.fetchAndStoreOrdered(0); /*failed*/
}
}
- if(g_terminal_attached)
+ if(MUTILS_BOOLIFY(g_terminal_attached))
{
g_fileBuf_stdout.reset(terminal_connect(stdout, std::cout));
g_fileBuf_stderr.reset(terminal_connect(stderr, std::cerr));
{
MUtils::Internal::CSLocker lock(g_terminal_lock);
- if(g_terminal_attached)
+ if(MUTILS_BOOLIFY(g_terminal_attached))
{
write_to_terminal(type, message);
}
{
MUtils::Internal::CSLocker lock(g_terminal_lock);
- if(g_terminal_attached && (!(icon.isNull() || MUtils::OS::running_on_wine())))
+ if(MUTILS_BOOLIFY(g_terminal_attached) && (!(icon.isNull() || MUtils::OS::running_on_wine())))
{
if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(&icon, 16, 16))
{
static const int VERSION_INFO_EXPIRES_MONTHS = 6;
static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0"; /*use something innocuous*/
-#define IS_CANCELLED (!(!m_cancelled))
#define CHECK_CANCELLED() do \
{ \
- if(IS_CANCELLED) \
+ if(MUTILS_BOOLIFY(m_cancelled)) \
{ \
- m_success = false; \
+ m_success.fetchAndStoreOrdered(0); \
log("", "Update check has been cancelled by user!"); \
setProgress(m_maxProgress); \
setStatus(UpdateStatus_CancelledByUser); \
m_testMode(testMode),
m_maxProgress(getMaxProgress())
{
- m_success = false;
m_status = UpdateStatus_NotStartedYet;
m_progress = 0;
void UpdateChecker::start(Priority priority)
{
- m_success = false;
+ m_success.fetchAndStoreOrdered(0);
m_cancelled.fetchAndStoreOrdered(0);
QThread::start(priority);
}
const bool isQuick = (mirrorCount++ < QUICK_MIRRORS);
if(tryUpdateMirror(m_updateInfo.data(), currentMirror, isQuick))
{
- m_success = true; /*success*/
+ m_success.ref(); /*success*/
break;
}
if (isQuick)
// ----- Generate final result ----- //
- if(m_success)
+ if(MUTILS_BOOLIFY(m_success))
{
if(m_updateInfo->m_buildNo > m_installedBuildNo)
{
{
return true;
}
- if (IS_CANCELLED)
+ if (MUTILS_BOOLIFY(m_cancelled))
{
break; /*cancelled*/
}
const QString line = QString::fromLatin1(process.readLine()).simplified();
log(line);
}
- if (bTimeOut || IS_CANCELLED)
+ if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
{
qWarning("WGet process timed out <-- killing!");
process.kill();
QString line = QString::fromLatin1(process.readLine()).simplified();
log(line);
}
- if (bTimeOut || IS_CANCELLED)
+ if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
{
qWarning("MCat process timed out <-- killing!");
process.kill();