summaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests/test1/testatomic.cpp
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-01-07 01:40:34 +0100
committerGitHub <noreply@github.com>2017-01-07 01:40:34 +0100
commit8b774509af8df6d2bd5825796d8a066a38db93e1 (patch)
treeb6116441b0e65f69f0486240875c936ac0e7406b /vespamalloc/src/tests/test1/testatomic.cpp
parentb815ae29f5a58f271114df351d4d01785413c1da (diff)
parent4e6b1987ae73852d0855b6e46e7cd36d8e6989fd (diff)
Merge pull request #1443 from yahoo/balder/vespamalloc-should-not-depend-on-anything-else-rebased-2
Balder/vespamalloc should not depend on anything else rebased 2
Diffstat (limited to 'vespamalloc/src/tests/test1/testatomic.cpp')
-rw-r--r--vespamalloc/src/tests/test1/testatomic.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/vespamalloc/src/tests/test1/testatomic.cpp b/vespamalloc/src/tests/test1/testatomic.cpp
index 1222493446c..78d94429a3f 100644
--- a/vespamalloc/src/tests/test1/testatomic.cpp
+++ b/vespamalloc/src/tests/test1/testatomic.cpp
@@ -1,10 +1,8 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/fastos/fastos.h>
+#include <vespa/fastos/thread.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/atomic.h>
-#include <vector>
-
-using vespalib::Atomic;
+#include <vespamalloc/malloc/allocchunk.h>
class Test : public vespalib::TestApp
{
@@ -39,10 +37,10 @@ void Test::testSwap(T initial)
{
T value(initial);
- ASSERT_TRUE(Atomic::cmpSwap(&value, initial+1, initial));
+ ASSERT_TRUE(vespalib::Atomic::cmpSwap(&value, initial+1, initial));
ASSERT_TRUE(value == initial+1);
- ASSERT_TRUE(!Atomic::cmpSwap(&value, initial+2, initial));
+ ASSERT_TRUE(!vespalib::Atomic::cmpSwap(&value, initial+2, initial));
ASSERT_TRUE(value == initial+1);
}
@@ -91,7 +89,7 @@ template <typename T>
void Stress<T>::stressSwap(T & value)
{
for (T old = value; old > 0; old = value) {
- if (Atomic::cmpSwap(&value, old-1, old)) {
+ if (vespalib::Atomic::cmpSwap(&value, old-1, old)) {
_successCount++;
} else {
_failedCount++;
@@ -103,6 +101,20 @@ int Test::Main()
{
TEST_INIT("atomic");
+ {
+ std::atomic<uint32_t> uint32V;
+ ASSERT_TRUE(uint32V.is_lock_free());
+ }
+ {
+ std::atomic<uint64_t> uint64V;
+ ASSERT_TRUE(uint64V.is_lock_free());
+ }
+ {
+ std::atomic<vespamalloc::TaggedPtr> taggedPtr;
+ ASSERT_EQUAL(16, sizeof(vespamalloc::TaggedPtr));
+ ASSERT_TRUE(taggedPtr.is_lock_free());
+ }
+
testSwap<uint32_t>(6);
testSwap<uint32_t>(7);
testSwap<uint32_t>(uint32_t(-6));