From 38879f099b6fabb0d8378104abf70cd3464c74fa Mon Sep 17 00:00:00 2001 From: fwx1246009 Date: Thu, 13 Apr 2023 09:03:07 +0800 Subject: [PATCH 1/2] Code specification modification Issue: I6USYS Test: unittest Change-Id: Ib076da7e766b8667265f1009b9829a8e8eb4aebe Signed-off-by: fwx1246009 --- .../unittest/common/utils_parcel_test.cpp | 30 +++++++++---------- .../unittest/common/utils_rwlock_test.cpp | 6 ++-- .../unittest/common/utils_thread_test.cpp | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/base/test/unittest/common/utils_parcel_test.cpp b/base/test/unittest/common/utils_parcel_test.cpp index 4dd9bd4..3b69095 100644 --- a/base/test/unittest/common/utils_parcel_test.cpp +++ b/base/test/unittest/common/utils_parcel_test.cpp @@ -509,7 +509,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) Parcel parcel(nullptr); std::vector val1; bool x1 = true; - for(int i = 0; i < cap/sizeof(bool); i++){ + for (int i = 0; i < cap / sizeof(bool); i++) { val1.push_back(x1); } bool result = parcel.WriteBoolVector(val1); @@ -518,7 +518,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val2; int8_t x2 = 1; - for(int i = 0; i < cap/sizeof(int8_t); i++){ + for (int i = 0; i < cap / sizeof(int8_t); i++) { val2.push_back(x2); } result = parcel.WriteInt8Vector(val2); @@ -527,7 +527,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val3; int16_t x3 = 1; - for(int i = 0; i < cap/sizeof(int16_t); i++){ + for (int i = 0; i < cap / sizeof(int16_t); i++) { val3.push_back(x3); } result = parcel.WriteInt16Vector(val3); @@ -536,7 +536,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val4; int32_t x4 = 1; - for(int i = 0; i < cap/sizeof(int32_t); i++){ + for (int i = 0; i < cap / sizeof(int32_t); i++) { val4.push_back(x4); } result = parcel.WriteInt32Vector(val4); @@ -545,7 +545,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val5; int64_t x5 = 1; - for(int i = 0; i < cap/sizeof(int64_t); i++){ + for (int i = 0; i < cap / sizeof(int64_t); i++) { val5.push_back(x5); } result = parcel.WriteInt64Vector(val5); @@ -554,7 +554,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val6; uint8_t x6 = 1; - for(int i = 0; i < cap/sizeof(uint8_t); i++){ + for (int i = 0; i < cap / sizeof(uint8_t); i++) { val6.push_back(x6); } result = parcel.WriteUInt8Vector(val6); @@ -563,7 +563,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val7; uint16_t x7 = 1; - for(int i = 0; i < cap/sizeof(uint16_t); i++){ + for (int i = 0; i < cap / sizeof(uint16_t); i++) { val7.push_back(x7); } result = parcel.WriteUInt16Vector(val7); @@ -572,7 +572,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val8; uint32_t x8 = 1; - for(int i = 0; i < cap/sizeof(uint32_t); i++){ + for (int i = 0; i < cap / sizeof(uint32_t); i++) { val8.push_back(x8); } result = parcel.WriteUInt32Vector(val8); @@ -581,7 +581,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val9; uint64_t x9 = 1; - for(int i = 0; i < cap/sizeof(uint64_t); i++){ + for (int i = 0; i < cap / sizeof(uint64_t); i++) { val9.push_back(x9); } result = parcel.WriteUInt64Vector(val9); @@ -590,7 +590,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val10; float x10 = 1; - for(int i = 0; i < cap/sizeof(float); i++){ + for (int i = 0; i < cap / sizeof(float); i++) { val10.push_back(x10); } result = parcel.WriteFloatVector(val10); @@ -599,7 +599,7 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val11; double x11 = 1; - for(int i = 0; i < cap/sizeof(double); i++){ + for (int i = 0; i < cap / sizeof(double); i++) { val11.push_back(x11); } result = parcel.WriteDoubleVector(val11); @@ -607,14 +607,14 @@ HWTEST_F(UtilsParcelTest, test_parcel_writevec_001, TestSize.Level0) parcel.FlushBuffer(); std::vector val12; - std::string x12((cap/sizeof(char)), 't'); + std::string x12((cap / sizeof(char)), 't'); val12.push_back(x12); result = parcel.WriteStringVector(val12); EXPECT_EQ(result, false); parcel.FlushBuffer(); std::vector val13; - std::u16string x13((cap/sizeof(char16_t)), u't'); + std::u16string x13((cap / sizeof(char16_t)), u't'); val13.push_back(x13); result = parcel.WriteString16Vector(val13); EXPECT_EQ(result, false); @@ -1294,8 +1294,8 @@ HWTEST_F(UtilsParcelTest, test_parcel_Data_Structure_002, TestSize.Level0) const string str = "test invalid input"; const string strOverflow = "test write with SIZE_MAX bytes"; - const string strWriteFail = string((DEFAULT_CPACITY+1)/sizeof(char), 'f'); - const string strWriteTermFail = string((DEFAULT_CPACITY-2)/sizeof(char), 't'); + const string strWriteFail = string((DEFAULT_CPACITY + 1) / sizeof(char), 'f'); + const string strWriteTermFail = string((DEFAULT_CPACITY - 2) / sizeof(char), 't'); bool result = parcel.WriteBuffer(nullptr, sizeof(string)); EXPECT_EQ(false, result); diff --git a/base/test/unittest/common/utils_rwlock_test.cpp b/base/test/unittest/common/utils_rwlock_test.cpp index a1ee2c2..5ed3139 100644 --- a/base/test/unittest/common/utils_rwlock_test.cpp +++ b/base/test/unittest/common/utils_rwlock_test.cpp @@ -38,7 +38,7 @@ public: rwLock.LockWrite(); for (auto it = str.begin(); it != str.end(); it++) { buf.push_back(*it); - this_thread::sleep_for(std::chrono::milliseconds(10)); // Extend time of holding the lock + this_thread::sleep_for(std::chrono::milliseconds(10)); // 10: Extend time of holding the lock } rwLock.UnLockWrite(); return; @@ -49,7 +49,7 @@ public: rwLock.LockRead(); for (auto it = buf.begin(); it != buf.end(); it++) { str.push_back(*it); - this_thread::sleep_for(std::chrono::milliseconds(10)); // Extend time of holding the lock + this_thread::sleep_for(std::chrono::milliseconds(10)); // 10: Extend time of holding the lock } rwLock.UnLockRead(); return; @@ -118,4 +118,4 @@ HWTEST_F(UtilsRWLockTest, testRWLock002, TestSize.Level1) EXPECT_EQ(readOut1, readOut2); } } // namespace -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/base/test/unittest/common/utils_thread_test.cpp b/base/test/unittest/common/utils_thread_test.cpp index 1359f97..1893200 100644 --- a/base/test/unittest/common/utils_thread_test.cpp +++ b/base/test/unittest/common/utils_thread_test.cpp @@ -304,7 +304,7 @@ HWTEST_F(UtilsThreadTest, testThread007, TestSize.Level0) ThreadStatus status = test->Start("", THREAD_PROI_LOW, 0); EXPECT_EQ(status == ThreadStatus::OK, true); - if(test->IsRunning()) + if (test->IsRunning()) { status = test->Start("", THREAD_PROI_NORMAL, 1024); EXPECT_EQ(status == ThreadStatus::INVALID_OPERATION, true); @@ -396,4 +396,4 @@ HWTEST_F(UtilsThreadTest, testThread009, TestSize.Level0) } } // namespace -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee From e21e370901aaed9a7bbefb96f8308868ddb02cbf Mon Sep 17 00:00:00 2001 From: fwx1246009 Date: Thu, 13 Apr 2023 17:14:09 +0800 Subject: [PATCH 2/2] Delete join function Issue: I6VGHN Test: unittest Signed-off-by: fwx1246009 Change-Id: Ie37106ebb471269123ce912bcdbb6c189d85641e --- base/include/thread_ex.h | 1 - base/src/thread_ex.cpp | 18 +----------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/base/include/thread_ex.h b/base/include/thread_ex.h index cc3edb4..7482134 100644 --- a/base/include/thread_ex.h +++ b/base/include/thread_ex.h @@ -128,7 +128,6 @@ private: Thread(const Thread&) = delete; Thread& operator=(const Thread&) = delete; static int ThreadStart(void* args); - ThreadStatus Join(); // pthread created as detached private: pthread_t thread_; // Thread ID diff --git a/base/src/thread_ex.cpp b/base/src/thread_ex.cpp index 4811191..dd8c093 100644 --- a/base/src/thread_ex.cpp +++ b/base/src/thread_ex.cpp @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. +/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -133,21 +132,6 @@ ThreadStatus Thread::Start(const std::string& name, int32_t priority, size_t sta return ThreadStatus::OK; } -ThreadStatus Thread::Join() -{ - // If the two thread IDs are equal, pthread_equal() returns a non-zero value; otherwise, it returns 0. - if (pthread_equal(thread_, pthread_self()) != 0) { - return ThreadStatus::WOULD_BLOCK; - } - - std::unique_lock lk(lock_); - while (running_) { - cvThreadExited_.wait(lk); - } - - return status_; -} - ThreadStatus Thread::NotifyExitSync() { // If the two thread IDs are equal, pthread_equal() returns a non-zero value; otherwise, it returns 0. -- Gitee