refactor: clean the code of lock module

This commit is contained in:
yangzhifeng
2022-12-06 07:42:35 +00:00
committed by ob-robot
parent e01e420726
commit e6af47ade7
19 changed files with 64 additions and 168 deletions

View File

@ -52,7 +52,6 @@ storage_unittest(test_ob_occam_timer)
storage_unittest(test_ob_occam_thread_pool)
#ob_unittest(test_tenant_tablet_checksum_iterator)
ob_unittest(test_ob_future)
ob_unittest(test_qsync_lock lock/test_qsync_lock.cpp)
ob_unittest(test_ob_occam_time_guard)
ob_unittest(test_cluster_version)
ob_unittest(test_scn)

View File

@ -1,76 +0,0 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <gtest/gtest.h>
#include <thread>
#include <vector>
#include "share/lock/ob_qsync_lock.h"
#include "lib/time/ob_time_utility.h"
namespace oceanbase
{
namespace share
{
using namespace common;
TEST(TestQSyncLock, basic)
{
lib::ObMemAttr mem_attr(OB_SERVER_TENANT_ID, "TestQSyncLock");
ObQSyncLock lock;
lock.init(mem_attr);
for (int i=0;i<100;i++) {
ObQSyncLockReadGuard read_guard(lock);
}
ObQSyncLockWriteGuard write_guard(lock);
}
TEST(TestQSyncLock, concurrent)
{
lib::ObMemAttr mem_attr(OB_SERVER_TENANT_ID, "TestQSyncLock");
ObQSyncLock lock;
lock.init(mem_attr);
std::vector<std::thread> ths;
bool g_stop = false;
for (int i=0;i<10;i++) {
std::thread th([&](){
while (!g_stop) {
ObQSyncLockReadGuard read_guard(lock);
}
});
ths.push_back(std::move(th));
}
::sleep(1);
{
auto start = ObTimeUtility::current_time();
ObQSyncLockWriteGuard write_guard(lock);
auto end = ObTimeUtility::current_time();
std::cout << end-start << std::endl;
ASSERT_TRUE(end - start < 1000000);
}
g_stop = true;
for (auto &it : ths) {
it.join();
}
}
} // end share
} // oceanbase
int main(int argc, char **argv)
{
OB_LOGGER.set_log_level("INFO");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}