X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftest%2Fsimple_spin.cc;fp=src%2Fceph%2Fsrc%2Ftest%2Fsimple_spin.cc;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=04b4fc07e5f6b6033d0196ac6ab16f6eca571d03;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/test/simple_spin.cc b/src/ceph/src/test/simple_spin.cc deleted file mode 100644 index 04b4fc0..0000000 --- a/src/ceph/src/test/simple_spin.cc +++ /dev/null @@ -1,58 +0,0 @@ -#include "gtest/gtest.h" - -#include "common/simple_spin.h" - -#include - -TEST(SimpleSpin, Test0) -{ - std::atomic_flag lock0 = ATOMIC_FLAG_INIT; - simple_spin_lock(&lock0); - simple_spin_unlock(&lock0); -} - -static std::atomic_flag lock = ATOMIC_FLAG_INIT; -static uint32_t counter = 0; - -static void* mythread(void *v) -{ - for (int j = 0; j < 1000000; ++j) { - simple_spin_lock(&lock); - counter++; - simple_spin_unlock(&lock); - } - return NULL; -} - -TEST(SimpleSpin, Test1) -{ - counter = 0; - const auto n = 2000000U; - - int ret; - pthread_t thread1; - pthread_t thread2; - ret = pthread_create(&thread1, NULL, mythread, NULL); - ASSERT_EQ(0, ret); - ret = pthread_create(&thread2, NULL, mythread, NULL); - ASSERT_EQ(0, ret); - ret = pthread_join(thread1, NULL); - ASSERT_EQ(0, ret); - ret = pthread_join(thread2, NULL); - ASSERT_EQ(0, ret); - ASSERT_EQ(n, counter); - - - // Should also work with pass-by-reference: - // (Note that we don't care about cross-threading here as-such.) - counter = 0; - async(std::launch::async, []() { - for(int i = 0; n != i; ++i) { - simple_spin_lock(lock); - counter++; - simple_spin_unlock(lock); - } - }); - ASSERT_EQ(n, counter); -} -