From 1c255a5f54918d9f800ef49e9cbde6b0d349f096 Mon Sep 17 00:00:00 2001 From: cwx1272435 Date: Fri, 16 Aug 2024 06:36:10 +0000 Subject: [PATCH 01/11] memory_utils code modify Signed-off-by: cwx1272435 --- libdmabufheap/src/dmabuf_alloc.c | 5 +++-- libpurgeablemem/c/src/purgeable_memory.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libdmabufheap/src/dmabuf_alloc.c b/libdmabufheap/src/dmabuf_alloc.c index 02dec9d..3db3851 100644 --- a/libdmabufheap/src/dmabuf_alloc.c +++ b/libdmabufheap/src/dmabuf_alloc.c @@ -32,8 +32,9 @@ static bool IsHeapNameValid(const char *heapName) { - if ((heapName == NULL) || (strlen(heapName) == 0) || - (strlen(heapName) > HEAP_NAME_MAX_LEN)) { + size_t len = strlen(heapName); + if ((heapName == NULL) || (len == 0) || + (len > HEAP_NAME_MAX_LEN)) { return false; } diff --git a/libpurgeablemem/c/src/purgeable_memory.c b/libpurgeablemem/c/src/purgeable_memory.c index b0cf21b..918a616 100644 --- a/libpurgeablemem/c/src/purgeable_memory.c +++ b/libpurgeablemem/c/src/purgeable_memory.c @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "pthread.h" +#include #include "purgeable_mem_builder_c.h" #include "purgeable_mem_c.h" -- Gitee From 2de3926d9ae11ecaded52fd2aa42b623aca53aa8 Mon Sep 17 00:00:00 2001 From: cwx1272435 Date: Fri, 23 Aug 2024 09:04:30 +0000 Subject: [PATCH 02/11] IsHeapNameValid modify Signed-off-by: cwx1272435 --- libdmabufheap/src/dmabuf_alloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libdmabufheap/src/dmabuf_alloc.c b/libdmabufheap/src/dmabuf_alloc.c index 3db3851..558ea6b 100644 --- a/libdmabufheap/src/dmabuf_alloc.c +++ b/libdmabufheap/src/dmabuf_alloc.c @@ -32,12 +32,13 @@ static bool IsHeapNameValid(const char *heapName) { + if (heapName == NULL) { + return false; + } size_t len = strlen(heapName); - if ((heapName == NULL) || (len == 0) || - (len > HEAP_NAME_MAX_LEN)) { + if ( (len == 0) || (len > HEAP_NAME_MAX_LEN)) { return false; } - return true; } -- Gitee From af10e27520a9b0dc10e46baf3cbd798203aa9803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=9C=88=E5=85=B3?= Date: Fri, 23 Aug 2024 10:57:00 +0000 Subject: [PATCH 03/11] update libdmabufheap/src/dmabuf_alloc.c. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李月关 --- libdmabufheap/src/dmabuf_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdmabufheap/src/dmabuf_alloc.c b/libdmabufheap/src/dmabuf_alloc.c index 558ea6b..6d759f9 100644 --- a/libdmabufheap/src/dmabuf_alloc.c +++ b/libdmabufheap/src/dmabuf_alloc.c @@ -36,7 +36,7 @@ static bool IsHeapNameValid(const char *heapName) return false; } size_t len = strlen(heapName); - if ( (len == 0) || (len > HEAP_NAME_MAX_LEN)) { + if ((len == 0) || (len > HEAP_NAME_MAX_LEN)) { return false; } return true; -- Gitee From 7b37b95164a6bd9006dc8bd6d20f3f674834e4a2 Mon Sep 17 00:00:00 2001 From: cwx1272435 Date: Fri, 6 Sep 2024 05:39:59 +0000 Subject: [PATCH 04/11] Add mutex locks to functions that lack mutex locks Signed-off-by: cwx1272435 --- libpurgeablemem/cpp/src/purgeable_mem_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp index 5fe2900..0c5a935 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp @@ -97,6 +97,7 @@ bool PurgeableMemBase::BeginRead() void PurgeableMemBase::EndRead() { + std::lock_guard lock(dataLock_); if (isDataValid_) { Unpin(); } @@ -141,6 +142,7 @@ bool PurgeableMemBase::BeginWrite() void PurgeableMemBase::EndWrite() { + std::lock_guard lock(dataLock_); PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str()); Unpin(); } @@ -233,6 +235,7 @@ inline std::string PurgeableMemBase::ToString() const void PurgeableMemBase::SetRebuildSuccessCallback(std::function &callback) { + std::lock_guard lock(dataLock_); if (builder_) { builder_->SetRebuildSuccessCallback(callback); } @@ -240,11 +243,13 @@ void PurgeableMemBase::SetRebuildSuccessCallback(std::function &callback bool PurgeableMemBase::IsDataValid() { + std::lock_guard lock(dataLock_); return isDataValid_; } void PurgeableMemBase::SetDataValid(bool target) { + std::lock_guard lock(dataLock_); isDataValid_ = target; } } /* namespace PurgeableMem */ -- Gitee From 6054e3c1d4a782e8eead1ffd05f46b764cddc577 Mon Sep 17 00:00:00 2001 From: "zhoumengjie7@huawei.com" Date: Wed, 18 Sep 2024 16:40:23 +0800 Subject: [PATCH 05/11] add annotation Signed-off-by: zhoumengjie7@huawei.com Change-Id: Ic90e5ca6745938b2f89562374fc1e78ad06fdfd9 --- .../cpp/include/purgeable_mem_base.h | 22 +++++++++++++++++-- .../interfaces/kits/c/purgeable_memory.h | 18 +++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libpurgeablemem/cpp/include/purgeable_mem_base.h b/libpurgeablemem/cpp/include/purgeable_mem_base.h index 1567e85..49b48fc 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem_base.h +++ b/libpurgeablemem/cpp/include/purgeable_mem_base.h @@ -39,6 +39,15 @@ public: * While return true if content recover success. * OS cannot reclaim the memory of the obj's content when this * function return true, until EndRead() is called. + * + * Attension: the return value must be recevied and handled, + * since the visiting of this object with the failure result + * will cause unsuspected result. + * For example: + * if (BeginRead()) { + * // visit this object + * EndRead(); + * } */ bool BeginRead(); @@ -50,13 +59,22 @@ public: void EndRead(); /* - * BeginRead: begin read the PurgeableMem obj. + * BeginRead: begin write the PurgeableMem obj. * Return: return true if the obj's content is present. * If content is purged(no present), system will recover its data, * return false if content is purged and recover failed. * While return true if content recover success. * OS cannot reclaim the memory of the obj's content when this - * function return true, until EndRead() is called. + * function return true, until EndWrite() is called. + * + * Attension: the return value must be recevied and handled, + * since the visiting of this object with the failure result + * will cause unsuspected result. + * For example: + * if (BeginWrite()) { + * // visit this object + * EndWrite(); + * } */ bool BeginWrite(); diff --git a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h index a228044..6d87f51 100644 --- a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h +++ b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h @@ -108,6 +108,15 @@ bool OH_PurgeableMemory_Destroy(OH_PurgeableMemory *purgObj); * OS cannot reclaim the memory of @purgObj's content when this * function return true, until PurgMemEndRead() is called. * + * Attension: the return value must be recevied and handled, + * since the visiting of this object with the failure result + * will cause unsuspected result. + * For example: + * if (OH_PurgeableMemory_BeginRead()) { + * // visit this object + * OH_PurgeableMemory_EndRead(); + * } + * * @since 10 * @version 1.0 */ @@ -138,6 +147,15 @@ void OH_PurgeableMemory_EndRead(OH_PurgeableMemory *purgObj); * OS cannot reclaim the memory of @purgObj's content when this * function return true, until PurgMemEndWrite() is called. * + * Attension: the return value must be recevied and handled, + * since the visiting of this object with the failure result + * will cause unsuspected result. + * For example: + * if (OH_PurgeableMemory_BeginWrite()) { + * // visit this object + * OH_PurgeableMemory_EndWrite(); + * } + * * @since 10 * @version 1.0 */ -- Gitee From 560bbb443910cba6b084cf1bda3d8bfc765e4d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=A2=A6=E6=9D=B0?= Date: Thu, 19 Sep 2024 02:14:12 +0000 Subject: [PATCH 06/11] update libpurgeablemem/cpp/include/purgeable_mem_base.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周梦杰 --- libpurgeablemem/cpp/include/purgeable_mem_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libpurgeablemem/cpp/include/purgeable_mem_base.h b/libpurgeablemem/cpp/include/purgeable_mem_base.h index 49b48fc..7ea386d 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem_base.h +++ b/libpurgeablemem/cpp/include/purgeable_mem_base.h @@ -39,7 +39,7 @@ public: * While return true if content recover success. * OS cannot reclaim the memory of the obj's content when this * function return true, until EndRead() is called. - * + * * Attension: the return value must be recevied and handled, * since the visiting of this object with the failure result * will cause unsuspected result. @@ -66,7 +66,7 @@ public: * While return true if content recover success. * OS cannot reclaim the memory of the obj's content when this * function return true, until EndWrite() is called. - * + * * Attension: the return value must be recevied and handled, * since the visiting of this object with the failure result * will cause unsuspected result. -- Gitee From 1b2b5850f55da5c61e7bf980a03b86178da60159 Mon Sep 17 00:00:00 2001 From: "zhoumengjie7@huawei.com" Date: Mon, 23 Sep 2024 11:30:15 +0800 Subject: [PATCH 07/11] modify the access permission of PurgeableMemBase Signed-off-by: zhoumengjie7@huawei.com Change-Id: I6732b6af29721d1480f3cfbad365c0ff205fdada --- libpurgeablemem/cpp/include/purgeable_mem_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libpurgeablemem/cpp/include/purgeable_mem_base.h b/libpurgeablemem/cpp/include/purgeable_mem_base.h index 1567e85..f5f8d89 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem_base.h +++ b/libpurgeablemem/cpp/include/purgeable_mem_base.h @@ -104,6 +104,8 @@ public: PurgeableMemBase& operator = (PurgeableMemBase&) = delete; PurgeableMemBase(PurgeableMemBase&&) noexcept = delete; PurgeableMemBase& operator = (PurgeableMemBase&&) noexcept = delete; + virtual int GetPinStatus() const; + virtual bool Pin(); protected: void *dataPtr_ = nullptr; @@ -114,10 +116,8 @@ protected: unsigned int buildDataCount_ = 0; bool BuildContent(); bool IfNeedRebuild(); - virtual bool Pin(); virtual bool Unpin(); virtual bool IsPurged(); - virtual int GetPinStatus() const; virtual void AfterRebuildSucc(); virtual std::string ToString() const; }; -- Gitee From 2e1b19fbd3bd43074bb6fa39f3fefde08ef5bdc0 Mon Sep 17 00:00:00 2001 From: "zhoumengjie7@huawei.com" Date: Wed, 25 Sep 2024 17:02:06 +0800 Subject: [PATCH 08/11] add test cases about purgeable_memory Signed-off-by: zhoumengjie7@huawei.com Change-Id: I59fb21d11202ced8bfa9ff7feb210fce40646249 --- libpurgeablemem/test/BUILD.gn | 12 + .../test/purgeable_memory_test.cpp | 220 ++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 libpurgeablemem/test/purgeable_memory_test.cpp diff --git a/libpurgeablemem/test/BUILD.gn b/libpurgeablemem/test/BUILD.gn index 64e4b12..baf20f0 100644 --- a/libpurgeablemem/test/BUILD.gn +++ b/libpurgeablemem/test/BUILD.gn @@ -45,6 +45,17 @@ ohos_unittest("purgeable_cpp_test") { part_name = "memory_utils" } +ohos_unittest("purgeable_memory_test") { + module_out_path = module_output_path + sources = [ "purgeable_memory_test.cpp" ] + if (is_standard_system) { + external_deps = purgeable_external_deps + } + + subsystem_name = "commonlibrary" + part_name = "memory_utils" +} + ohos_unittest("purgeableashmem_test") { module_out_path = module_output_path sources = [ "purgeableashmem_test.cpp" ] @@ -61,6 +72,7 @@ group("libpurgeablemem_test") { deps = [ ":purgeable_c_test", ":purgeable_cpp_test", + ":purgeable_memory_test", ":purgeableashmem_test", ] } diff --git a/libpurgeablemem/test/purgeable_memory_test.cpp b/libpurgeablemem/test/purgeable_memory_test.cpp new file mode 100644 index 0000000..2f27398 --- /dev/null +++ b/libpurgeablemem/test/purgeable_memory_test.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "purgeable_memory.h" + +namespace { +using namespace testing; +using namespace testing::ext; + +struct AlphabetInitParam { + char start; + char end; +}; + +struct AlphabetModifyParam { + char src; + char dst; +}; + +static constexpr int PRINT_INTERVAL_SECONDS = 1; +static constexpr int RECLAIM_INTERVAL_SECONDS = 1; +static constexpr int MODIFY_INTERVAL_SECONDS = 2; + +bool InitData(void *data, size_t size, char start, char end); +bool ModifyData(void *data, size_t size, char src, char dst); +bool InitAlphabet(void *data, size_t size, void *param); +bool ModifyAlphabetX2Y(void *data, size_t size, void *param); +void LoopPrintAlphabet(OH_PurgeableMemory *pdata, unsigned int loopCount); +bool ReclaimPurgeable(void); +void LoopReclaimPurgeable(unsigned int loopCount); +void ModifyPurgMemByFunc(OH_PurgeableMemory *pdata, OH_PurgeableMemory_ModifyFunc Modfunc, void *param); + +class PurgeableMemoryTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void PurgeableMemoryTest::SetUpTestCase() +{ +} + +void PurgeableMemoryTest::TearDownTestCase() +{ +} + +void PurgeableMemoryTest::SetUp() +{ +} + +void PurgeableMemoryTest::TearDown() +{ +} + +HWTEST_F(PurgeableMemoryTest, MultiObjCreateTest, TestSize.Level1) +{ + const char alphabetFinal[] = "BBCDEFGHIJKLMNOPQRSTUVWXYZ\0"; + struct AlphabetInitParam initPara = {'A', 'Z'}; + OH_PurgeableMemory *pobj1 = OH_PurgeableMemory_Create(27, InitAlphabet, &initPara); + LoopPrintAlphabet(pobj1, 1); + struct AlphabetModifyParam a2b = {'A', 'B'}; + ModifyPurgMemByFunc(pobj1, ModifyAlphabetX2Y, static_cast(&a2b)); + LoopPrintAlphabet(pobj1, 1); + LoopReclaimPurgeable(1); + + if (OH_PurgeableMemory_BeginRead(pobj1)) { + ASSERT_STREQ(alphabetFinal, static_cast(OH_PurgeableMemory_GetContent(pobj1))); + OH_PurgeableMemory_EndRead(pobj1); + } + + EXPECT_EQ(OH_PurgeableMemory_Destroy(pobj1), true); +} + + +HWTEST_F(PurgeableMemoryTest, WriteTest, TestSize.Level1) +{ + const char alphabet[] = "CCCDEFGHIJKLMNOPQRSTUVWXYZ\0"; + struct AlphabetInitParam initPara = {'A', 'Z'}; + OH_PurgeableMemory *pobj = OH_PurgeableMemory_Create(27, InitAlphabet, &initPara); + LoopReclaimPurgeable(1); + + struct AlphabetModifyParam a2b = {'A', 'B'}; + struct AlphabetModifyParam b2c = {'B', 'C'}; + ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&a2b)); + ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&b2c)); + + if (OH_PurgeableMemory_BeginRead(pobj)) { + ASSERT_STREQ(alphabet, static_cast(OH_PurgeableMemory_GetContent(pobj))); + OH_PurgeableMemory_EndRead(pobj); + } else { + std::cout << __func__ << ": ERROR! BeginRead failed." << std::endl; + } + + OH_PurgeableMemory_Destroy(pobj); + LoopReclaimPurgeable(3); +} + +bool InitData(void *data, size_t size, char start, char end) +{ + char *str = (char *)data; + size_t len = 0; + for (char ch = start; ch <= end && len < size; ch++) { + str[len++] = ch; + } + str[len] = 0; + return true; +} + +bool InitAlphabet(void *data, size_t size, void *param) +{ + struct AlphabetInitParam *para = (struct AlphabetInitParam *)param; + std::cout << "inter " << __func__ << std::endl; + bool ret = InitData(data, size, para->start, para->end); + std::cout << "quit " << __func__ << ": " << para->start << "-" << para->end << + ", data=[" << (char *)data << "]" << ", ret=" << (ret ? "true" : "false") << std::endl; + return ret; +} + +bool ModifyData(void *data, size_t size, char src, char dst) +{ + char *str = (char *)data; + size_t i = 0; + for (; i < size && str[i]; i++) { + if (str[i] == src) { + str[i] = dst; + } + } + str[i] = 0; + return true; +} + +bool ModifyAlphabetX2Y(void *data, size_t size, void *param) +{ + struct AlphabetModifyParam *para = (struct AlphabetModifyParam *)param; + std::cout << "inter " << __func__ << ": " << para->src << "->" << para->dst << + ", data=[" << (char *)data << "]" << std::endl; + bool ret = ModifyData(data, size, para->src, para->dst); + std::cout << "quit , data=[" << (char *)data << "]" << __func__ << + ", ret=" << (ret ? "true" : "false") << std::endl; + return ret; +} + +void LoopPrintAlphabet(OH_PurgeableMemory *pdata, unsigned int loopCount) +{ + std::cout << "inter " << __func__ << std::endl; + for (unsigned int i = 0; i < loopCount; i++) { + if (!OH_PurgeableMemory_BeginRead(pdata)) { + std::cout << __func__ << ": " << i << ". ERROR! BeginRead failed." << std::endl; + break; + } + std::cout << __func__ << ": " << i << ". data=[" << + (char *)OH_PurgeableMemory_GetContent(pdata) << "]" << std::endl; + OH_PurgeableMemory_EndRead(pdata); + std::this_thread::sleep_for(std::chrono::seconds(PRINT_INTERVAL_SECONDS)); + } + std::cout << "quit " << __func__ << std::endl; +} + +bool ReclaimPurgeable(void) +{ + FILE *f = fopen("/proc/sys/kernel/purgeable", "w"); + if (!f) { + std::cout << __func__ << ": open file failed" << std::endl; + return false; + } + bool succ = true; + if (fputs("1", f) == EOF) { + succ = false; + } + + if (fclose(f) == EOF) { + std::cout << __func__ << ": close file failed" << std::endl; + } + + return succ; +} + +void LoopReclaimPurgeable(unsigned int loopCount) +{ + bool ret = false; + std::cout << "inter " << __func__ << std::endl; + for (unsigned int i = 0; i < loopCount; i++) { + ret = ReclaimPurgeable(); + std::cout << __func__ << ": " << i << ". Reclaim result=" << (ret ? "succ" : "fail") << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(RECLAIM_INTERVAL_SECONDS)); /* wait reclaim finish */ + } + std::cout << "quit " << __func__ << std::endl; +} + +void ModifyPurgMemByFunc(OH_PurgeableMemory *pdata, OH_PurgeableMemory_ModifyFunc Modfunc, void *param) +{ + if (OH_PurgeableMemory_BeginWrite(pdata)) { + std::this_thread::sleep_for(std::chrono::seconds(MODIFY_INTERVAL_SECONDS)); + OH_PurgeableMemory_AppendModify(pdata, Modfunc, param); + std::cout<< __func__ << " after mod data=[" << (char *)OH_PurgeableMemory_GetContent(pdata) << "]" << std::endl; + + std::cout << __func__ << " data=[" << (char *)OH_PurgeableMemory_GetContent(pdata) << "]" << std::endl; + OH_PurgeableMemory_EndWrite(pdata); + } +} +} /* namespace */ -- Gitee From e273f22be2d000b8c123b0d7f7d72fb978cac7d2 Mon Sep 17 00:00:00 2001 From: cwx1272435 Date: Wed, 16 Oct 2024 05:54:28 +0000 Subject: [PATCH 09/11] 1016 Signed-off-by: cwx1272435 --- OAT.xml | 1 + libsync/src/sync.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/OAT.xml b/OAT.xml index 0c2b65b..20cc6bc 100644 --- a/OAT.xml +++ b/OAT.xml @@ -22,6 +22,7 @@ + diff --git a/libsync/src/sync.c b/libsync/src/sync.c index 5d216be..755df16 100644 --- a/libsync/src/sync.c +++ b/libsync/src/sync.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright 2012 Google, Inc * 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 -- Gitee From 7fc8dae52d5ccd803d838e6b8c67706b9650efd6 Mon Sep 17 00:00:00 2001 From: chenziang_sjtu <1094744965@qq.com> Date: Fri, 25 Oct 2024 14:20:29 +0800 Subject: [PATCH 10/11] =?UTF-8?q?Libsync=E4=BB=A3=E7=A0=81=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenziang_sjtu <1094744965@qq.com> --- OAT.xml | 3 +-- libsync/include/sync.h | 4 ++-- libsync/src/sync.c | 31 +++++++++++++++---------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/OAT.xml b/OAT.xml index 20cc6bc..95921d6 100644 --- a/OAT.xml +++ b/OAT.xml @@ -22,8 +22,7 @@ - - \ No newline at end of file + diff --git a/libsync/include/sync.h b/libsync/include/sync.h index cf0eabe..7f6adfa 100644 --- a/libsync/include/sync.h +++ b/libsync/include/sync.h @@ -15,6 +15,6 @@ #ifndef COMM_UTILS_SYNC_H #define COMM_UTILS_SYNC_H -int SyncWait(int num, int time); +int SyncWait(int fileDescriptor, int timeout); -#endif \ No newline at end of file +#endif diff --git a/libsync/src/sync.c b/libsync/src/sync.c index 755df16..8291466 100644 --- a/libsync/src/sync.c +++ b/libsync/src/sync.c @@ -1,5 +1,5 @@ /* - * Copyright 2012 Google, Inc + * Copyright (c) 2024 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 @@ -17,32 +17,31 @@ #include #include -int SyncWait(int num, int time) +int SyncWait(int fileDescriptor, int timeout) { - struct pollfd work; - int result; - - if (num < 0) { + if (fileDescriptor < 0) { errno = EINVAL; return -1; } - work.fd = num; - work.events = POLLIN; + struct pollfd pfd = { .fd = fileDescriptor, .events = POLLIN }; + int pollResult; + + while (1) { + pollResult = poll(&pfd, 1, timeout); - do { - result = poll(&work, 1, time); - if (result > 0) { - if (work.revents & (POLLERR | POLLNVAL)) { + if (pollResult > 0) { + if (pfd.revents & (POLLERR | POLLNVAL)) { errno = EINVAL; return -1; } return 0; - } else if (result == 0) { + } else if (pollResult == 0) { errno = ETIME; return -1; + } else if (pollResult != -1 || (errno != EINTR && errno != EAGAIN)) { + break; } - } while (result == -1 && (errno == EINTR || errno == EAGAIN)); - - return result; + } + return pollResult; } -- Gitee From ed4c2641c6e9e9ab7209842c16d1e889e6d3833e Mon Sep 17 00:00:00 2001 From: chenziang_sjtu <1094744965@qq.com> Date: Thu, 7 Nov 2024 15:23:25 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=88=A0=E9=99=A4libsync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenziang_sjtu <1094744965@qq.com> --- bundle.json | 10 --------- libsync/BUILD.gn | 34 ------------------------------ libsync/include/sync.h | 20 ------------------ libsync/src/sync.c | 47 ------------------------------------------ 4 files changed, 111 deletions(-) delete mode 100644 libsync/BUILD.gn delete mode 100644 libsync/include/sync.h delete mode 100644 libsync/src/sync.c diff --git a/bundle.json b/bundle.json index 29817f7..9db5bf7 100644 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,6 @@ "//commonlibrary/memory_utils/libdmabufheap:libdmabufheap", "//commonlibrary/memory_utils/libmeminfo:libmeminfo", "//commonlibrary/memory_utils/libpurgeablemem:libpurgeablemem", - "//commonlibrary/memory_utils/libsync:libsync", "//commonlibrary/memory_utils/libpurgeablemem:purgeable_memory_ndk" ], "inner_kits": [ @@ -54,15 +53,6 @@ "header_base": "//commonlibrary/memory_utils/libmeminfo/include" } }, - { - "name": "//commonlibrary/memory_utils/libsync:libsync", - "header": { - "header_files": [ - "sync.h" - ], - "header_base": "//commonlibrary/memory_utils/libsync/include" - } - }, { "name": "//commonlibrary/memory_utils/libpurgeablemem:libpurgeablemem", "header": { diff --git a/libsync/BUILD.gn b/libsync/BUILD.gn deleted file mode 100644 index 13ee1ca..0000000 --- a/libsync/BUILD.gn +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2024 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 -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") - -config("libsync_config") { - include_dirs = [ "include" ] -} - -ohos_shared_library("libsync") { - sources = [ "src/sync.c" ] - include_dirs = [ "include" ] - - public_configs = [ ":libsync_config" ] - subsystem_name = "commonlibrary" - part_name = "memory_utils" - - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - branch_protector_ret = "pac_ret" -} diff --git a/libsync/include/sync.h b/libsync/include/sync.h deleted file mode 100644 index 7f6adfa..0000000 --- a/libsync/include/sync.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2024 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef COMM_UTILS_SYNC_H -#define COMM_UTILS_SYNC_H - -int SyncWait(int fileDescriptor, int timeout); - -#endif diff --git a/libsync/src/sync.c b/libsync/src/sync.c deleted file mode 100644 index 8291466..0000000 --- a/libsync/src/sync.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2024 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "sync.h" -#include -#include -#include - -int SyncWait(int fileDescriptor, int timeout) -{ - if (fileDescriptor < 0) { - errno = EINVAL; - return -1; - } - - struct pollfd pfd = { .fd = fileDescriptor, .events = POLLIN }; - int pollResult; - - while (1) { - pollResult = poll(&pfd, 1, timeout); - - if (pollResult > 0) { - if (pfd.revents & (POLLERR | POLLNVAL)) { - errno = EINVAL; - return -1; - } - return 0; - } else if (pollResult == 0) { - errno = ETIME; - return -1; - } else if (pollResult != -1 || (errno != EINTR && errno != EAGAIN)) { - break; - } - } - return pollResult; -} -- Gitee