aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2025-05-19 16:10:01 +0200
committerFriedemann Kleint <[email protected]>2025-05-20 17:56:25 +0200
commitd417218c4fd94ab47afe7d097760f6185b70cc70 (patch)
tree41008f4be00b40f188042e541fcca4f9af53c08f /sources/shiboken6
parentb140341b44fe5f8faf2d8dec8c57cef7ef16cc02 (diff)
shiboken6/Bucket test: Use an atomic<bool>
Task-number: PYSIDE-2221 Change-Id: I45db5a10308338d446bb2ac888219477fed6e405 Reviewed-by: Christian Tismer <[email protected]>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/tests/libsample/bucket.cpp14
-rw-r--r--sources/shiboken6/tests/libsample/bucket.h6
2 files changed, 13 insertions, 7 deletions
diff --git a/sources/shiboken6/tests/libsample/bucket.cpp b/sources/shiboken6/tests/libsample/bucket.cpp
index cafd382a9..43a32f414 100644
--- a/sources/shiboken6/tests/libsample/bucket.cpp
+++ b/sources/shiboken6/tests/libsample/bucket.cpp
@@ -40,15 +40,21 @@ bool Bucket::empty()
void Bucket::lock()
{
- m_locked = true;
- while (m_locked) {
- SLEEP(300);
+ bool expected = false;
+ if (m_locked.compare_exchange_strong(expected, true)) {
+ while (m_locked) {
+ SLEEP(300);
+ }
+ } else {
+ std::cerr << __FUNCTION__ << " Attempt to lock twice.\n";
}
}
void Bucket::unlock()
{
- m_locked = false;
+ bool expected = true;
+ if (!m_locked.compare_exchange_strong(expected, false))
+ std::cerr << __FUNCTION__ << " Attempt to unlock twice.\n";
}
bool Bucket::virtualBlockerMethod()
diff --git a/sources/shiboken6/tests/libsample/bucket.h b/sources/shiboken6/tests/libsample/bucket.h
index 73e8edd78..677069fe7 100644
--- a/sources/shiboken6/tests/libsample/bucket.h
+++ b/sources/shiboken6/tests/libsample/bucket.h
@@ -7,6 +7,7 @@
#include "libsamplemacros.h"
#include "objecttype.h"
+#include <atomic>
#include <list>
class ObjectType;
@@ -19,7 +20,7 @@ public:
int pop();
bool empty();
void lock();
- inline bool locked() { return m_locked; }
+ bool locked() { return m_locked.load(); }
void unlock();
virtual bool virtualBlockerMethod();
@@ -27,8 +28,7 @@ public:
private:
std::list<int> m_data;
-
- volatile bool m_locked = false;
+ std::atomic<bool> m_locked{false};
};
#endif // BUCKET_H