OSDN Git Service

Various improvements to known_folder() function, again.
[mutilities/MUtilities.git] / src / CriticalSection_Win32.h
index e55b30e..9848de3 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -78,11 +78,10 @@ namespace MUtils
                public:
                        inline CSLocker(CriticalSection &criticalSection)
                        :
-                               m_locked(false),
                                m_criticalSection(criticalSection)
                        {
                                m_criticalSection.enter();
-                               m_locked = true;
+                               m_locked.ref();
                        }
 
                        inline ~CSLocker(void)
@@ -92,14 +91,13 @@ namespace MUtils
 
                        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;
                };
        }