diff --git a/services/distributeddataservice/libs/distributeddb/BUILD.gn b/services/distributeddataservice/libs/distributeddb/BUILD.gn index 4eb85e9390bdeadc935769e5031c6e55ec59a9b6..6001241c037430f0716a5d8ff07f771fd761956a 100755 --- a/services/distributeddataservice/libs/distributeddb/BUILD.gn +++ b/services/distributeddataservice/libs/distributeddb/BUILD.gn @@ -82,7 +82,7 @@ ohos_shared_library("distributeddb") { "common/src/runtime_context_impl.cpp", "common/src/schema_object.cpp", "common/src/schema_utils.cpp", - "common/src/semaphore.cpp", + "common/src/semaphore_utils.cpp", "common/src/task_pool.cpp", "common/src/task_pool_impl.cpp", "common/src/task_queue.cpp", diff --git a/services/distributeddataservice/libs/distributeddb/common/include/semaphore.h b/services/distributeddataservice/libs/distributeddb/common/include/semaphore_utils.h similarity index 84% rename from services/distributeddataservice/libs/distributeddb/common/include/semaphore.h rename to services/distributeddataservice/libs/distributeddb/common/include/semaphore_utils.h index 6372363f0ce756e3662ea0045bb263a4887f6c05..9cdb3f561dc4bec5784670af7ab9c798b0dc957d 100755 --- a/services/distributeddataservice/libs/distributeddb/common/include/semaphore.h +++ b/services/distributeddataservice/libs/distributeddb/common/include/semaphore_utils.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SEMAPHORE_H -#define SEMAPHORE_H +#ifndef SEMAPHORE_UTILS_H +#define SEMAPHORE_UTILS_H #include #include @@ -23,13 +23,13 @@ #include "macro_utils.h" namespace DistributedDB { -class Semaphore { +class SemaphoreUtils { public: - explicit Semaphore(int count); - ~Semaphore(); + explicit SemaphoreUtils(int count); + ~SemaphoreUtils(); // Delete the copy and assign constructors - DISABLE_COPY_ASSIGN_MOVE(Semaphore); + DISABLE_COPY_ASSIGN_MOVE(SemaphoreUtils); bool WaitSemaphore(int waitSecond); diff --git a/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp b/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp index a1bc6fb681b4107a379c2d611a83e016eacb2c2e..1354f8ee4cb992b2d6cb1951808e8e0c07dd3aa7 100755 --- a/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp +++ b/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp @@ -24,7 +24,7 @@ #include "kvdb_manager.h" #include "kv_store_changed_data_impl.h" #include "sync_able_kvdb_connection.h" -#include "semaphore.h" +#include "semaphore_utils.h" #include "kv_store_nb_conflict_data_impl.h" #include "db_common.h" #include "param_check_utils.h" @@ -561,7 +561,7 @@ void AutoLaunch::GetConnInDoOpenMap(std::map &doOpe if (doOpenMap.empty()) { return; } - Semaphore sema(1 - doOpenMap.size()); + SemaphoreUtils sema(1 - doOpenMap.size()); for (auto &iter : doOpenMap) { int errCode = RuntimeContext::GetInstance()->ScheduleTask([&sema, &iter, this] { int errCode; diff --git a/services/distributeddataservice/libs/distributeddb/common/src/semaphore.cpp b/services/distributeddataservice/libs/distributeddb/common/src/semaphore_utils.cpp similarity index 73% rename from services/distributeddataservice/libs/distributeddb/common/src/semaphore.cpp rename to services/distributeddataservice/libs/distributeddb/common/src/semaphore_utils.cpp index f2ef2096a364348a7b240752533b4eb7e785844a..f2ab5388defdb3cf5221277860dfac620c240716 100755 --- a/services/distributeddataservice/libs/distributeddb/common/src/semaphore.cpp +++ b/services/distributeddataservice/libs/distributeddb/common/src/semaphore_utils.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "semaphore.h" +#include "semaphore_utils.h" #include @@ -22,39 +22,39 @@ using std::unique_lock; using std::mutex; using std::condition_variable; -Semaphore::Semaphore(int count) +SemaphoreUtils::SemaphoreUtils(int count) : count_(count) {} -Semaphore::~Semaphore() +SemaphoreUtils::~SemaphoreUtils() {} -bool Semaphore::WaitSemaphore(int waitSecond) +bool SemaphoreUtils::WaitSemaphore(int waitSecond) { unique_lock lock(lockMutex_); bool result = cv_.wait_for(lock, std::chrono::seconds(waitSecond), - std::bind(&Semaphore::CompareCount, this)); + std::bind(&SemaphoreUtils::CompareCount, this)); if (result == true) { --count_; } return result; } -void Semaphore::WaitSemaphore() +void SemaphoreUtils::WaitSemaphore() { unique_lock lock(lockMutex_); - cv_.wait(lock, std::bind(&Semaphore::CompareCount, this)); + cv_.wait(lock, std::bind(&SemaphoreUtils::CompareCount, this)); --count_; } -void Semaphore::SendSemaphore() +void SemaphoreUtils::SendSemaphore() { unique_lock lock(lockMutex_); count_++; cv_.notify_one(); } -bool Semaphore::CompareCount() const +bool SemaphoreUtils::CompareCount() const { return count_ > 0; } diff --git a/services/distributeddataservice/libs/distributeddb/communicator/include/frame_combiner.h b/services/distributeddataservice/libs/distributeddb/communicator/include/frame_combiner.h index b2a2bd04940f9a6c7c1b1414b2b2261f99a4d8c2..0fe738698db488a8ad92af4244202c0a2cef0516 100755 --- a/services/distributeddataservice/libs/distributeddb/communicator/include/frame_combiner.h +++ b/services/distributeddataservice/libs/distributeddb/communicator/include/frame_combiner.h @@ -19,7 +19,7 @@ #include #include #include -#include "semaphore.h" +#include "semaphore_utils.h" #include "macro_utils.h" #include "parse_result.h" #include "combine_status.h" @@ -68,7 +68,7 @@ private: TimerId timerId_ = 0; // 0 is invalid timerId bool isTimerWork_ = false; - Semaphore timerRemovedIndicator_{0}; + SemaphoreUtils timerRemovedIndicator_{0}; uint64_t incProgressId_ = 0; uint64_t totalSizeByByte_ = 0; std::map> combineWorkPool_; diff --git a/services/distributeddataservice/libs/distributeddb/syncer/include/sync_operation.h b/services/distributeddataservice/libs/distributeddb/syncer/include/sync_operation.h index 995526d1f0027895562d82cfa44f31485e4ca3e5..913252f4f6393a1f5549b328924563a1bf3874d2 100755 --- a/services/distributeddataservice/libs/distributeddb/syncer/include/sync_operation.h +++ b/services/distributeddataservice/libs/distributeddb/syncer/include/sync_operation.h @@ -24,7 +24,7 @@ #include "ikvdb_sync_interface.h" #include "ref_object.h" -#include "semaphore.h" +#include "semaphore_utils.h" #include "notification_chain.h" #include "runtime_context.h" @@ -148,7 +148,7 @@ private: bool isFinished_; // Used for block sync - std::unique_ptr semaphore_; + std::unique_ptr semaphore_; }; } // namespace DistributedDB diff --git a/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h b/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h index 27f69eba7e19e2900c7cdb8197f9d54f4795ec2f..44d5733d791d2abf42a9b88fde0454650f1148a2 100755 --- a/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h +++ b/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h @@ -21,7 +21,7 @@ #include "sync_state_machine.h" #include "sync_target.h" -#include "semaphore.h" +#include "semaphore_utils.h" #include "message.h" #include "single_ver_sync_task_context.h" #include "time_sync.h" diff --git a/services/distributeddataservice/libs/distributeddb/syncer/src/sync_operation.cpp b/services/distributeddataservice/libs/distributeddb/syncer/src/sync_operation.cpp index bc26dda79ca149ec8e66bb5103a180be61824f54..e5c6996fd43dde6a096803f6f3d716ff7b4c6c93 100755 --- a/services/distributeddataservice/libs/distributeddb/syncer/src/sync_operation.cpp +++ b/services/distributeddataservice/libs/distributeddb/syncer/src/sync_operation.cpp @@ -55,7 +55,7 @@ int SyncOperation::Initialize() } if (isBlockSync_) { - semaphore_ = std::make_unique(0); + semaphore_ = std::make_unique(0); } return E_OK; diff --git a/services/distributeddataservice/libs/distributeddb/syncer/src/sync_task_context.h b/services/distributeddataservice/libs/distributeddb/syncer/src/sync_task_context.h index b293f4523d92fcac57d3e25cc67c3ee2b021655a..3a542cafe94970b405dd3c3c97396c094994ef8c 100755 --- a/services/distributeddataservice/libs/distributeddb/syncer/src/sync_task_context.h +++ b/services/distributeddataservice/libs/distributeddb/syncer/src/sync_task_context.h @@ -21,7 +21,7 @@ #include "isync_task_context.h" #include "sync_target.h" -#include "semaphore.h" +#include "semaphore_utils.h" #include "sync_operation.h" #include "icommunicator.h" #include "ikvdb_sync_interface.h" diff --git a/services/distributeddataservice/libs/distributeddb/test/BUILD.gn b/services/distributeddataservice/libs/distributeddb/test/BUILD.gn index 36adae090fe80d59768fc48a6bc658d2fb0d338a..10dffa5acc901307bc450cea773cef181f52528b 100755 --- a/services/distributeddataservice/libs/distributeddb/test/BUILD.gn +++ b/services/distributeddataservice/libs/distributeddb/test/BUILD.gn @@ -85,7 +85,7 @@ ohos_source_set("src_file") { "../common/src/runtime_context_impl.cpp", "../common/src/schema_object.cpp", "../common/src/schema_utils.cpp", - "../common/src/semaphore.cpp", + "../common/src/semaphore_utils.cpp", "../common/src/task_pool.cpp", "../common/src/task_pool_impl.cpp", "../common/src/task_queue.cpp", @@ -439,8 +439,8 @@ ohos_unittest("DistributedDBStorageEncryptTest") { ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ - "//third_party/openssl:libcrypto_static", "//third_party/googletest:gtest_main", + "//third_party/openssl:libcrypto_static", "//utils/native/base:utils", ] }