From 753225b14abc0f0727b8cdcdcd002b74de3ce85b Mon Sep 17 00:00:00 2001 From: zhoumengjie Date: Mon, 19 Jun 2023 15:11:46 +0800 Subject: [PATCH 1/3] add private variable _ Signed-off-by: zhoumengjie --- libpurgeablemem/test/purgeable_cpp_test.cpp | 28 ++++++++++--------- libpurgeablemem/test/purgeableashmem_test.cpp | 28 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/libpurgeablemem/test/purgeable_cpp_test.cpp b/libpurgeablemem/test/purgeable_cpp_test.cpp index 5813b2b..20fbcc5 100644 --- a/libpurgeablemem/test/purgeable_cpp_test.cpp +++ b/libpurgeablemem/test/purgeable_cpp_test.cpp @@ -37,8 +37,8 @@ class TestDataBuilder : public PurgeableMemBuilder { public: TestDataBuilder(char start, char end) { - this->start = start; - this->end = end; + this->start_ = start; + this->end_ = end; } bool Build(void *data, size_t size) @@ -48,12 +48,12 @@ public: } char *str = static_cast(data); size_t len = 0; - for (char ch = start; ch <= end && len < size; ch++) { + for (char ch = start_; ch <= end_ && len < size; ch++) { str[len++] = ch; } str[size - 1] = 0; std::cout << "rebuild addr("<< (unsigned long long)str <<") " << - start << "~" << end << ", data=[" << str << "]" << std::endl; + start_ << "~" << end_ << ", data=[" << str << "]" << std::endl; return true; } @@ -63,23 +63,24 @@ public: } private: - char start, end; + char start_; + char end_; }; class TestDataModifier : public PurgeableMemBuilder { public: TestDataModifier(char from, char to) { - this->from = from; - this->to = to; + this->from_ = from; + this->to_ = to; } bool Build(void *data, size_t size) { char *str = static_cast(data); for (size_t i = 0; i < size && str[i]; i++) { - if (str[i] == from) { - str[i] = to; + if (str[i] == from_) { + str[i] = to_; } } return true; @@ -91,14 +92,15 @@ public: } private: - char from, to; + char from_; + char to_; }; class TestBigDataBuilder : public PurgeableMemBuilder { public: explicit TestBigDataBuilder(char target) { - this->target = target; + this->target_ = target; } bool Build(void *data, size_t size) @@ -108,7 +110,7 @@ public: } char *str = static_cast(data); size_t len = 0; - for (char ch = target; len < size;) { + for (char ch = target_; len < size;) { str[len++] = ch; } str[size - 1] = 0; @@ -121,7 +123,7 @@ public: } private: - char target; + char target_; }; class PurgeableCppTest : public testing::Test { diff --git a/libpurgeablemem/test/purgeableashmem_test.cpp b/libpurgeablemem/test/purgeableashmem_test.cpp index fc1a95d..6bf930e 100644 --- a/libpurgeablemem/test/purgeableashmem_test.cpp +++ b/libpurgeablemem/test/purgeableashmem_test.cpp @@ -44,8 +44,8 @@ class TestDataBuilder : public PurgeableMemBuilder { public: TestDataBuilder(char start, char end) { - this->start = start; - this->end = end; + this->start_ = start; + this->end_ = end; } bool Build(void *data, size_t size) @@ -55,12 +55,12 @@ public: } char *str = static_cast(data); size_t len = 0; - for (char ch = start; ch <= end && len < size; ch++) { + for (char ch = start_; ch <= end_ && len < size; ch++) { str[len++] = ch; } str[size - 1] = 0; std::cout << "rebuild addr("<< (unsigned long long)str <<") " << - start << "~" << end << ", data=[" << str << "]" << std::endl; + start_ << "~" << end_ << ", data=[" << str << "]" << std::endl; return true; } @@ -70,23 +70,24 @@ public: } private: - char start, end; + char start_; + char end_; }; class TestDataModifier : public PurgeableMemBuilder { public: TestDataModifier(char from, char to) { - this->from = from; - this->to = to; + this->from_ = from; + this->to_ = to; } bool Build(void *data, size_t size) { char *str = static_cast(data); for (size_t i = 0; i < size && str[i]; i++) { - if (str[i] == from) { - str[i] = to; + if (str[i] == from_) { + str[i] = to_; } } return true; @@ -98,14 +99,15 @@ public: } private: - char from, to; + char from_; + char to_; }; class TestBigDataBuilder : public PurgeableMemBuilder { public: explicit TestBigDataBuilder(char target) { - this->target = target; + this->target_ = target; } bool Build(void *data, size_t size) @@ -115,7 +117,7 @@ public: } char *str = static_cast(data); size_t len = 0; - for (char ch = target; len < size;) { + for (char ch = target_; len < size;) { str[len++] = ch; } str[size - 1] = 0; @@ -128,7 +130,7 @@ public: } private: - char target; + char target_; }; class PurgeableAshmemTest : public testing::Test { -- Gitee From ff064b4479a099b74f97ff596ac3f590ed4a9796 Mon Sep 17 00:00:00 2001 From: zhoumengjie Date: Mon, 19 Jun 2023 15:16:27 +0800 Subject: [PATCH 2/3] add clang-format Signed-off-by: zhoumengjie --- .clang-format | 210 ++++++++++++++++++ format.sh | 24 ++ libdmabufheap/include/dmabuf_alloc.h | 2 +- .../libdmabufheap/dmabuf_alloc_test.cpp | 48 ++-- libmeminfo/src/meminfo.cpp | 3 +- libmeminfo/test/unittest/meminfo_test.cpp | 20 +- libpurgeablemem/c/include/pm_log_c.h | 12 +- .../c/include/purgeable_mem_builder_c.h | 4 +- libpurgeablemem/c/include/purgeable_mem_c.h | 2 +- .../common/include/ux_page_table_c.h | 4 +- libpurgeablemem/cpp/include/pm_log.h | 12 +- .../cpp/include/pm_smartptr_util.h | 22 +- .../cpp/include/purgeable_ashmem.h | 10 +- libpurgeablemem/cpp/include/purgeable_mem.h | 5 +- .../cpp/include/purgeable_mem_base.h | 12 +- .../cpp/include/purgeable_mem_builder.h | 2 +- .../cpp/include/purgeable_resource_manager.h | 18 +- libpurgeablemem/cpp/src/purgeable_ashmem.cpp | 20 +- libpurgeablemem/cpp/src/purgeable_mem.cpp | 17 +- .../cpp/src/purgeable_mem_base.cpp | 30 +-- .../cpp/src/purgeable_mem_builder.cpp | 8 +- .../cpp/src/purgeable_resource_manager.cpp | 34 +-- libpurgeablemem/cpp/src/ux_page_table.cpp | 1 - .../interfaces/kits/c/purgeable_memory.h | 8 +- libpurgeablemem/test/purgeable_c_test.cpp | 55 ++--- libpurgeablemem/test/purgeable_cpp_test.cpp | 24 +- libpurgeablemem/test/purgeableashmem_test.cpp | 24 +- .../include/purgeable_pixelmap_builder.h | 12 +- .../src/purgeable_pixelmap_builder.cpp | 29 +-- 29 files changed, 429 insertions(+), 243 deletions(-) create mode 100644 .clang-format create mode 100755 format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3ed2f41 --- /dev/null +++ b/.clang-format @@ -0,0 +1,210 @@ +# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto +Language: Cpp +# BasedOnStyle: LLVM +# 访问说明符(public、private等)的偏移 +AccessModifierOffset: -4 +# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行) +AlignAfterOpenBracket: DontAlign +# 连续赋值时,对齐所有等号 +AlignConsecutiveAssignments: false +# 连续声明时,对齐所有声明的变量名 +AlignConsecutiveDeclarations: false +# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 +AlignEscapedNewlinesLeft: true +# 水平对齐二元和三元表达式的操作数 +AlignOperands: true +# 对齐连续的尾随的注释 +AlignTrailingComments: true +# 允许函数声明的所有参数在放在下一行 +AllowAllParametersOfDeclarationOnNextLine: false +# 允许短的块放在同一行 +AllowShortBlocksOnASingleLine: false +# 允许短的case标签放在同一行 +AllowShortCaseLabelsOnASingleLine: false +# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All +AllowShortFunctionsOnASingleLine: Empty +# 允许短的if语句保持在同一行 +AllowShortIfStatementsOnASingleLine: false +# 允许短的循环保持在同一行 +AllowShortLoopsOnASingleLine: false +# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), +# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) +AlwaysBreakAfterReturnType: None +# 总是在多行string字面量前换行 +AlwaysBreakBeforeMultilineStrings: false +# 总是在template声明后换行 +AlwaysBreakTemplateDeclarations: Yes +# false表示函数实参要么都在同一行,要么都各自一行 +BinPackArguments: true +# false表示所有形参要么都在同一行,要么都各自一行 +BinPackParameters: true +# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), +# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), +# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom +# 注:这里认为语句块也属于函数 +BreakBeforeBraces: Custom +# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 +BraceWrapping: + # class定义后面 + AfterClass: false + # 控制语句后面 + AfterControlStatement: false + # enum定义后面 + AfterEnum: false + # 函数定义后面 + AfterFunction: true + # 命名空间定义后面 + AfterNamespace: false + # ObjC定义后面 + AfterObjCDeclaration: false + # struct定义后面 + AfterStruct: false + # union定义后面 + AfterUnion: false + AfterExternBlock: false + # catch之前 + BeforeCatch: false + # else之前 + BeforeElse: false + # 缩进大括号 + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) +BreakBeforeBinaryOperators: None + +BreakBeforeInheritanceComma: false + +# 在三元运算符前换行 +BreakBeforeTernaryOperators: true +# 构造函数的初始化列表 +BreakConstructorInitializers: BeforeColon + +BreakInheritanceList: BeforeColon + +BreakStringLiterals: true + +BreakAfterJavaFieldAnnotations: true +# 每行字符的限制,0表示没有限制 +ColumnLimit: 120 +# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 +CommentPragmas: '^ IWYU pragma:' + +CompactNamespaces: false + +# 构造函数的初始化列表要么都在同一行,要么都各自一行 +ConstructorInitializerAllOnOneLineOrOnePerLine: false +# 构造函数的初始化列表的缩进宽度 +ConstructorInitializerIndentWidth: 4 +# 延续的行的缩进宽度 +ContinuationIndentWidth: 4 +# 去除C++11的列表初始化的大括号{后和}前的空格 +Cpp11BracedListStyle: false +# 继承最常用的指针和引用的对齐方式 +DerivePointerAlignment: false +# 关闭格式化 +DisableFormat: false + +FixNamespaceComments: true + +# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) +# ExperimentalAutoDetectBinPacking: false + +# 需要被解读为foreach循环而不是函数调用的宏 +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] + +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^"(base|core|elements|rendering|adapter|dsl|frameworks|resource|accessibility|bridge)/' + Priority: 3 + - Regex: '<*>' + Priority: 1 + - Regex: '.*' + Priority: 2 + +IncludeBlocks: Preserve + +# 缩进case标签 +IndentCaseLabels: true + +IndentPPDirectives: None +# 缩进宽度 +IndentWidth: 4 +# 函数返回类型换行时,缩进函数声明或函数定义的函数名 +IndentWrappedFunctionNames: false + +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +# 保留在块开始处的空行 +KeepEmptyLinesAtTheStartOfBlocks: false +# 开始一个块的宏的正则表达式 +MacroBlockBegin: '' +# 结束一个块的宏的正则表达式 +MacroBlockEnd: '' +# 连续空行的最大数量 +MaxEmptyLinesToKeep: 1 +# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All +NamespaceIndentation: None +# 使用ObjC块时缩进宽度 +# ObjCBlockIndentWidth: 4 +# 在ObjC的@property后添加一个空格 +# ObjCSpaceAfterProperty: false +# 在ObjC的protocol列表前添加一个空格 +# ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +# 在call(后对函数调用换行的penalty +PenaltyBreakBeforeFirstCallParameter: 39 +# 在一个注释中引入换行的penalty +PenaltyBreakComment: 300 +# 第一次在<<前换行的penalty +PenaltyBreakFirstLessLess: 120 +# 在一个字符串字面量中引入换行的penalty +PenaltyBreakString: 1000 +# 对于每个在行字符数限制之外的字符的penalty +PenaltyExcessCharacter: 1000000 +# 将函数的返回类型放到它自己的行的penalty +PenaltyReturnTypeOnItsOwnLine: 80 +# 指针和引用的对齐: Left, Right, Middle +PointerAlignment: Right +# 允许重新排版注释 +ReflowComments: true +# 允许排序#include +SortIncludes: true + +SortUsingDeclarations: true +# 在C风格类型转换后添加空格 +SpaceAfterCStyleCast: false + +SpaceAfterTemplateKeyword: false +# 在赋值运算符之前添加空格 +SpaceBeforeAssignmentOperators: true + +SpaceBeforeCpp11BracedList: true + +SpaceBeforeCtorInitializerColon: true + +# 开圆括号之前添加一个空格: Never, ControlStatements, Always +SpaceBeforeParens: ControlStatements + +SpaceBeforeRangeBasedForLoopColon: true +# 在空的圆括号中添加空格 +SpaceInEmptyParentheses: false +# 在尾随的评论前添加的空格数(只适用于//) +SpacesBeforeTrailingComments: 1 +# 在尖括号的<后和>前添加空格 +SpacesInAngles: false +# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 +SpacesInContainerLiterals: true +# 在C风格类型转换的括号中添加空格 +SpacesInCStyleCastParentheses: false +# 在圆括号的(后和)前添加空格 +SpacesInParentheses: false +# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 +SpacesInSquareBrackets: false +# 标准: Cpp03, Cpp11, Auto +Standard: Cpp11 +# tab宽度 +TabWidth: 4 +# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always +UseTab: Never \ No newline at end of file diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..e3c683d --- /dev/null +++ b/format.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# clang-format -style=file -i code.cpp + +# echo `ls $1` + +read_dir(){ + for file in `ls $1` + do + dir_or_file=$1"/"$file + # echo $dir_or_file + if [ -d $dir_or_file ] + then + read_dir $1"/"$file + else + if [ "${file##*.}" = "cpp" ] || [ "${file##*.}" = "h" ] + then + clang-format -style=file -i $dir_or_file + fi + fi + done +} + +read_dir "." \ No newline at end of file diff --git a/libdmabufheap/include/dmabuf_alloc.h b/libdmabufheap/include/dmabuf_alloc.h index e823319..0f14a95 100644 --- a/libdmabufheap/include/dmabuf_alloc.h +++ b/libdmabufheap/include/dmabuf_alloc.h @@ -16,9 +16,9 @@ #ifndef LIB_DMA_BUF_HEAP_H #define LIB_DMA_BUF_HEAP_H -#include #include #include +#include #undef LOG_TAG #define LOG_TAG "dmabufheap" diff --git a/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp b/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp index e8c36d5..f2ae324 100644 --- a/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp +++ b/libdmabufheap/test/unittest/libdmabufheap/dmabuf_alloc_test.cpp @@ -13,21 +13,21 @@ * limitations under the License. */ +#include +#include #include #include +#include #include -#include -#include -#include -#include +#include #include +#include +#include #include -#include -#include -#include -#include "securec.h" -#include "gtest/gtest.h" +#include #include "dmabuf_alloc.h" +#include "gtest/gtest.h" +#include "securec.h" using namespace testing; using namespace testing::ext; @@ -44,13 +44,9 @@ public: std::string heapName; }; -void DmabufAllocTest::SetUpTestCase() -{ -} +void DmabufAllocTest::SetUpTestCase() {} -void DmabufAllocTest::TearDownTestCase() -{ -} +void DmabufAllocTest::TearDownTestCase() {} void DmabufAllocTest::SetUp() { @@ -71,9 +67,7 @@ void DmabufAllocTest::SetUp() closedir(dir); } -void DmabufAllocTest::TearDown() -{ -} +void DmabufAllocTest::TearDown() {} HWTEST_F(DmabufAllocTest, AllocSingleBuffer, TestSize.Level1) { @@ -103,7 +97,7 @@ HWTEST_F(DmabufAllocTest, AllocSingleBuffer, TestSize.Level1) ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, ShareBufferBetweenProcess, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, ShareBufferBetweenProcess, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -155,11 +149,11 @@ HWTEST_F(DmabufAllocTest, ShareBufferBetweenProcess, Function|MediumTest|Level1) ASSERT_EQ(0, munmap(ptr, BUFFER_SIZE)); ASSERT_EQ(0, DmabufHeapBufferFree(&buffer)); - + ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, OpenInvalidNameHeap, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, OpenInvalidNameHeap, Function | MediumTest | Level1) { int i; std::string invalidName = "invalid"; @@ -173,7 +167,7 @@ HWTEST_F(DmabufAllocTest, OpenInvalidNameHeap, Function|MediumTest|Level1) ASSERT_EQ(-EINVAL, heapFd); } -HWTEST_F(DmabufAllocTest, AllocInvalidSizeBuffer, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, AllocInvalidSizeBuffer, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -186,7 +180,7 @@ HWTEST_F(DmabufAllocTest, AllocInvalidSizeBuffer, Function|MediumTest|Level1) ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, BufferSyncWithWrongFd, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, BufferSyncWithWrongFd, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -212,7 +206,7 @@ HWTEST_F(DmabufAllocTest, BufferSyncWithWrongFd, Function|MediumTest|Level1) ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, BufferSyncWithWrongSyncType, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, BufferSyncWithWrongSyncType, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -238,7 +232,7 @@ HWTEST_F(DmabufAllocTest, BufferSyncWithWrongSyncType, Function|MediumTest|Level ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, SyncBufferTwice, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, SyncBufferTwice, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -270,7 +264,7 @@ HWTEST_F(DmabufAllocTest, SyncBufferTwice, Function|MediumTest|Level1) ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -HWTEST_F(DmabufAllocTest, ExchangeBufferSyncOrder, Function|MediumTest|Level1) +HWTEST_F(DmabufAllocTest, ExchangeBufferSyncOrder, Function | MediumTest | Level1) { ASSERT_STRNE(heapName.c_str(), ""); @@ -293,4 +287,4 @@ HWTEST_F(DmabufAllocTest, ExchangeBufferSyncOrder, Function|MediumTest|Level1) ASSERT_EQ(0, DmabufHeapClose(heapFd)); } -} \ No newline at end of file +} // namespace \ No newline at end of file diff --git a/libmeminfo/src/meminfo.cpp b/libmeminfo/src/meminfo.cpp index d790514..f6a7554 100644 --- a/libmeminfo/src/meminfo.cpp +++ b/libmeminfo/src/meminfo.cpp @@ -114,8 +114,7 @@ bool GetGraphicsMemory(const int pid, uint64_t &gl, uint64_t &graph) return ret; } const std::vector> MEMORY_TRACKER_TYPES = { - {MEMORY_TRACKER_TYPE_GL, "GL"}, {MEMORY_TRACKER_TYPE_GRAPH, "Graph"}, - {MEMORY_TRACKER_TYPE_OTHER, "Other"} + { MEMORY_TRACKER_TYPE_GL, "GL" }, { MEMORY_TRACKER_TYPE_GRAPH, "Graph" }, { MEMORY_TRACKER_TYPE_OTHER, "Other" } }; for (const auto &memTrackerType : MEMORY_TRACKER_TYPES) { diff --git a/libmeminfo/test/unittest/meminfo_test.cpp b/libmeminfo/test/unittest/meminfo_test.cpp index c6d3df5..d8230d1 100644 --- a/libmeminfo/test/unittest/meminfo_test.cpp +++ b/libmeminfo/test/unittest/meminfo_test.cpp @@ -31,21 +31,13 @@ public: void TearDown(); }; -void MemInfoTest::SetUpTestCase() -{ -} +void MemInfoTest::SetUpTestCase() {} -void MemInfoTest::TearDownTestCase() -{ -} +void MemInfoTest::TearDownTestCase() {} -void MemInfoTest::SetUp() -{ -} +void MemInfoTest::SetUp() {} -void MemInfoTest::TearDown() -{ -} +void MemInfoTest::TearDown() {} HWTEST_F(MemInfoTest, GetRssByPid_Test_001, TestSize.Level1) { @@ -82,5 +74,5 @@ HWTEST_F(MemInfoTest, GetPssByPid_Test_002, TestSize.Level1) size = GetPssByPid(pid); ASSERT_EQ(size == 0, true); } -} -} +} // namespace MemInfo +} // namespace OHOS diff --git a/libpurgeablemem/c/include/pm_log_c.h b/libpurgeablemem/c/include/pm_log_c.h index f581b6a..6d1e3fd 100644 --- a/libpurgeablemem/c/include/pm_log_c.h +++ b/libpurgeablemem/c/include/pm_log_c.h @@ -36,15 +36,15 @@ #define PM_FILENAME "purgeable" -#define PM_HILOG_ERROR_C(logCore, fmt, ...) \ - (void)HILOG_ERROR( \ +#define PM_HILOG_ERROR_C(logCore, fmt, ...) \ + (void)HILOG_ERROR( \ LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) -#define PM_HILOG_INFO_C(logCore, fmt, ...) \ - (void)HILOG_INFO( \ +#define PM_HILOG_INFO_C(logCore, fmt, ...) \ + (void)HILOG_INFO( \ LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) -#define PM_HILOG_DEBUG_C(logCore, fmt, ...) \ - (void)HILOG_DEBUG( \ +#define PM_HILOG_DEBUG_C(logCore, fmt, ...) \ + (void)HILOG_DEBUG( \ LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) #endif \ No newline at end of file diff --git a/libpurgeablemem/c/include/purgeable_mem_builder_c.h b/libpurgeablemem/c/include/purgeable_mem_builder_c.h index 488e5b2..494e7ac 100644 --- a/libpurgeablemem/c/include/purgeable_mem_builder_c.h +++ b/libpurgeablemem/c/include/purgeable_mem_builder_c.h @@ -29,14 +29,12 @@ struct PurgMemBuilder; typedef bool (*PurgMemBuilderFunc)(void *, size_t, void *); - struct PurgMemBuilder *PurgMemBuilderCreate(PurgMemBuilderFunc func, void *param, const char *name); /* If return true, @builder will be set to NULL to avoid Use-After-Free */ bool PurgMemBuilderDestroy(struct PurgMemBuilder *builder); -bool PurgMemBuilderAppendFunc(struct PurgMemBuilder *builder, PurgMemBuilderFunc func, void *param, - const char *name); +bool PurgMemBuilderAppendFunc(struct PurgMemBuilder *builder, PurgMemBuilderFunc func, void *param, const char *name); bool PurgMemBuilderAppendBuilder(struct PurgMemBuilder *builder, struct PurgMemBuilder *newcomer); diff --git a/libpurgeablemem/c/include/purgeable_mem_c.h b/libpurgeablemem/c/include/purgeable_mem_c.h index fb34147..dab172c 100644 --- a/libpurgeablemem/c/include/purgeable_mem_c.h +++ b/libpurgeablemem/c/include/purgeable_mem_c.h @@ -17,7 +17,7 @@ #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_C_INCLUDE_PURGEABLE_MEM_C_H #include /* bool */ -#include /* size_t */ +#include /* size_t */ #ifdef __cplusplus #if __cplusplus diff --git a/libpurgeablemem/common/include/ux_page_table_c.h b/libpurgeablemem/common/include/ux_page_table_c.h index 1ee3625..823e319 100644 --- a/libpurgeablemem/common/include/ux_page_table_c.h +++ b/libpurgeablemem/common/include/ux_page_table_c.h @@ -16,9 +16,9 @@ #ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_COMMON_INCLUDE_UX_PAGE_TABLE_C_H #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_COMMON_INCLUDE_UX_PAGE_TABLE_C_H -#include /* uint64_t */ #include /* bool */ -#include /* size_t */ +#include /* size_t */ +#include /* uint64_t */ #include "pm_state_c.h" #ifdef __cplusplus diff --git a/libpurgeablemem/cpp/include/pm_log.h b/libpurgeablemem/cpp/include/pm_log.h index 0a8f0df..db5a91d 100644 --- a/libpurgeablemem/cpp/include/pm_log.h +++ b/libpurgeablemem/cpp/include/pm_log.h @@ -34,15 +34,15 @@ static constexpr OHOS::HiviewDFX::HiLogLabel PM_LOG_LABEL = { LOG_CORE, 0xD00179 #define PM_FILENAME "purgeable" -#define PM_HILOG_ERROR(logCore, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Error( \ +#define PM_HILOG_ERROR(logCore, fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Error( \ PM_LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) -#define PM_HILOG_INFO(logCore, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Info( \ +#define PM_HILOG_INFO(logCore, fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Info( \ PM_LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) -#define PM_HILOG_DEBUG(logCore, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Debug( \ +#define PM_HILOG_DEBUG(logCore, fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Debug( \ PM_LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, PM_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) #endif \ No newline at end of file diff --git a/libpurgeablemem/cpp/include/pm_smartptr_util.h b/libpurgeablemem/cpp/include/pm_smartptr_util.h index ad77cdc..8ebee41 100644 --- a/libpurgeablemem/cpp/include/pm_smartptr_util.h +++ b/libpurgeablemem/cpp/include/pm_smartptr_util.h @@ -20,17 +20,17 @@ namespace OHOS { namespace PurgeableMem { -#define MAKE_UNIQUE(ptrSelf, classType, errLog, errAction, ...) \ - do { \ - ptrSelf = nullptr; \ - try { \ - ptrSelf = std::make_unique(__VA_ARGS__); \ - } catch (...) { \ - HILOG_ERROR(LOG_CORE, errLog); \ - } \ - if (ptrSelf == nullptr) { \ - errAction; \ - } \ +#define MAKE_UNIQUE(ptrSelf, classType, errLog, errAction, ...) \ + do { \ + ptrSelf = nullptr; \ + try { \ + ptrSelf = std::make_unique(__VA_ARGS__); \ + } catch (...) { \ + HILOG_ERROR(LOG_CORE, errLog); \ + } \ + if (ptrSelf == nullptr) { \ + errAction; \ + } \ } while (0) } /* namespace PurgeableMem */ } /* namespace OHOS */ diff --git a/libpurgeablemem/cpp/include/purgeable_ashmem.h b/libpurgeablemem/cpp/include/purgeable_ashmem.h index 42435d8..15a5c42 100644 --- a/libpurgeablemem/cpp/include/purgeable_ashmem.h +++ b/libpurgeablemem/cpp/include/purgeable_ashmem.h @@ -24,21 +24,21 @@ #include #include "ashmem.h" -#include "purgeable_mem_builder.h" #include "purgeable_mem_base.h" +#include "purgeable_mem_builder.h" #include "ux_page_table.h" #ifndef ASHMEM_SET_PURGEABLE -#define ASHMEM_SET_PURGEABLE _IO(__ASHMEMIOC, 11) +#define ASHMEM_SET_PURGEABLE _IO(__ASHMEMIOC, 11) #endif #ifndef ASHMEM_GET_PURGEABLE -#define ASHMEM_GET_PURGEABLE _IO(__ASHMEMIOC, 12) +#define ASHMEM_GET_PURGEABLE _IO(__ASHMEMIOC, 12) #endif #ifndef PURGEABLE_ASHMEM_IS_PURGED -#define PURGEABLE_ASHMEM_IS_PURGED _IO(__ASHMEMIOC, 13) +#define PURGEABLE_ASHMEM_IS_PURGED _IO(__ASHMEMIOC, 13) #endif #ifndef PURGEABLE_ASHMEM_REBUILD_SUCCESS -#define PURGEABLE_ASHMEM_REBUILD_SUCCESS _IO(__ASHMEMIOC, 14) +#define PURGEABLE_ASHMEM_REBUILD_SUCCESS _IO(__ASHMEMIOC, 14) #endif namespace OHOS { diff --git a/libpurgeablemem/cpp/include/purgeable_mem.h b/libpurgeablemem/cpp/include/purgeable_mem.h index 534edf0..2377506 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem.h +++ b/libpurgeablemem/cpp/include/purgeable_mem.h @@ -16,12 +16,12 @@ #ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_H #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_H -#include /* unique_ptr */ +#include /* unique_ptr */ #include /* shared_mutex */ #include -#include "purgeable_mem_builder.h" #include "purgeable_mem_base.h" +#include "purgeable_mem_builder.h" #include "ux_page_table.h" namespace OHOS { @@ -32,7 +32,6 @@ public: ~PurgeableMem(); void ResizeData(size_t newSize) override; - protected: std::unique_ptr pageTable_ = nullptr; bool Pin() override; diff --git a/libpurgeablemem/cpp/include/purgeable_mem_base.h b/libpurgeablemem/cpp/include/purgeable_mem_base.h index 4bf2f74..03d74bc 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem_base.h +++ b/libpurgeablemem/cpp/include/purgeable_mem_base.h @@ -16,7 +16,7 @@ #ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BASE_H #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BASE_H -#include /* unique_ptr */ +#include /* unique_ptr */ #include /* shared_mutex */ #include @@ -98,15 +98,15 @@ public: PurgeableMemBase(); virtual ~PurgeableMemBase(); - PurgeableMemBase(const PurgeableMemBase&) = delete; - PurgeableMemBase& operator = (PurgeableMemBase&) = delete; - PurgeableMemBase(PurgeableMemBase&&) noexcept = delete; - PurgeableMemBase& operator = (PurgeableMemBase&&) noexcept = delete; + PurgeableMemBase(const PurgeableMemBase &) = delete; + PurgeableMemBase &operator=(PurgeableMemBase &) = delete; + PurgeableMemBase(PurgeableMemBase &&) noexcept = delete; + PurgeableMemBase &operator=(PurgeableMemBase &&) noexcept = delete; protected: void *dataPtr_ = nullptr; std::mutex dataLock_; - bool isDataValid_ {true}; + bool isDataValid_ { true }; size_t dataSizeInput_ = 0; std::unique_ptr builder_ = nullptr; std::shared_mutex rwlock_; diff --git a/libpurgeablemem/cpp/include/purgeable_mem_builder.h b/libpurgeablemem/cpp/include/purgeable_mem_builder.h index 93b7e85..39d525f 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem_builder.h +++ b/libpurgeablemem/cpp/include/purgeable_mem_builder.h @@ -16,8 +16,8 @@ #ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BUILDER_H #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BUILDER_H -#include /* unique_ptr */ #include +#include /* unique_ptr */ namespace OHOS { namespace PurgeableMem { diff --git a/libpurgeablemem/cpp/include/purgeable_resource_manager.h b/libpurgeablemem/cpp/include/purgeable_resource_manager.h index c84aab1..527cb5c 100644 --- a/libpurgeablemem/cpp/include/purgeable_resource_manager.h +++ b/libpurgeablemem/cpp/include/purgeable_resource_manager.h @@ -43,30 +43,30 @@ public: /* * Visited: visit the cache entry with the given key. * If the entry is found, it will be move to the most-recent position in the cache. - */ + */ void Visited(std::shared_ptr key); /* * Insert: insert the PurgeableMemBase key in the lrucache. * Input: @key: ptr of PurgeableMemBase. - */ + */ void Insert(std::shared_ptr key); /* * Erase: erase the PurgeableMemBase key in the lrucache. * Input: @key: ptr of PurgeableMemBase. - */ + */ void Erase(std::shared_ptr key); /* * SetCapacity: set the capacity of the lrucache. * Input: the capacity of lrucache. - */ + */ void SetCapacity(int32_t capacity); /* * Clear: clear the resourcePtrList and positionMap of the lrucache. - */ + */ void Clear(); using ListSharedPtrIterator = std::list>::iterator; @@ -82,8 +82,8 @@ private: class PurgeableResourceManager { public: - PurgeableResourceManager(const PurgeableResourceManager&) = delete; - PurgeableResourceManager& operator=(const PurgeableResourceManager&) = delete; + PurgeableResourceManager(const PurgeableResourceManager &) = delete; + PurgeableResourceManager &operator=(const PurgeableResourceManager &) = delete; ~PurgeableResourceManager(); static PurgeableResourceManager &GetInstance(); @@ -105,8 +105,8 @@ private: mutable std::mutex mutex_; LruCache lruCache_; - ThreadPool threadPool_ {THREAD_POOL_NAME}; - bool isThreadPoolStarted_ {false}; + ThreadPool threadPool_ { THREAD_POOL_NAME }; + bool isThreadPoolStarted_ { false }; }; } /* namespace PurgeableMem */ } /* namespace OHOS */ diff --git a/libpurgeablemem/cpp/src/purgeable_ashmem.cpp b/libpurgeablemem/cpp/src/purgeable_ashmem.cpp index 3ac9630..251b044 100644 --- a/libpurgeablemem/cpp/src/purgeable_ashmem.cpp +++ b/libpurgeablemem/cpp/src/purgeable_ashmem.cpp @@ -15,12 +15,12 @@ #include /* mmap */ -#include "securec.h" -#include "pm_util.h" -#include "pm_state_c.h" +#include "pm_log.h" #include "pm_smartptr_util.h" +#include "pm_state_c.h" +#include "pm_util.h" #include "purgeable_ashmem.h" -#include "pm_log.h" +#include "securec.h" namespace OHOS { namespace PurgeableMem { @@ -45,7 +45,7 @@ PurgeableAshMem::PurgeableAshMem(std::unique_ptr builder) buildDataCount_ = 0; isSupport_ = false; isChange_ = false; - IF_NULL_LOG_ACTION(builder, "%{public}s: input builder nullptr", return); + IF_NULL_LOG_ACTION(builder, "%{public}s: input builder nullptr", return ); builder_ = std::move(builder); PM_HILOG_DEBUG(LOG_CORE, "%{public}s init succ. %{public}s", __func__, ToString().c_str()); } @@ -62,7 +62,7 @@ PurgeableAshMem::PurgeableAshMem(size_t dataSize, std::unique_ptr 0) { TEMP_FAILURE_RETRY(ioctl(ashmemFd_, ASHMEM_PIN, &pin_)); - PM_HILOG_DEBUG(LOG_CORE, "%{public}s: fd:%{pubilc}d PURGEABLE_GET_PIN_STATE: %{public}d", - __func__, ashmemFd_, ioctl(ashmemFd_, ASHMEM_GET_PIN_STATUS, &pin_)); + PM_HILOG_DEBUG(LOG_CORE, "%{public}s: fd:%{pubilc}d PURGEABLE_GET_PIN_STATE: %{public}d", __func__, ashmemFd_, + ioctl(ashmemFd_, ASHMEM_GET_PIN_STATUS, &pin_)); } else { PM_HILOG_DEBUG(LOG_CORE, "ashmemFd_ not exist!!"); return false; @@ -156,8 +156,8 @@ bool PurgeableAshMem::Unpin() } if (ashmemFd_ > 0) { TEMP_FAILURE_RETRY(ioctl(ashmemFd_, ASHMEM_UNPIN, &pin_)); - PM_HILOG_DEBUG(LOG_CORE, "%{public}s: fd:%{pubilc}d PURGEABLE_GET_PIN_STATE: %{public}d", - __func__, ashmemFd_, ioctl(ashmemFd_, ASHMEM_GET_PIN_STATUS, &pin_)); + PM_HILOG_DEBUG(LOG_CORE, "%{public}s: fd:%{pubilc}d PURGEABLE_GET_PIN_STATE: %{public}d", __func__, ashmemFd_, + ioctl(ashmemFd_, ASHMEM_GET_PIN_STATUS, &pin_)); } else { PM_HILOG_DEBUG(LOG_CORE, "ashmemFd_ not exist!!"); return false; diff --git a/libpurgeablemem/cpp/src/purgeable_mem.cpp b/libpurgeablemem/cpp/src/purgeable_mem.cpp index 896fd9f..ffd6e93 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem.cpp @@ -15,12 +15,12 @@ #include /* mmap */ -#include "securec.h" -#include "pm_util.h" -#include "pm_state_c.h" +#include "pm_log.h" #include "pm_smartptr_util.h" +#include "pm_state_c.h" +#include "pm_util.h" #include "purgeable_mem.h" -#include "pm_log.h" +#include "securec.h" namespace OHOS { namespace PurgeableMem { @@ -48,7 +48,7 @@ PurgeableMem::PurgeableMem(size_t dataSize, std::unique_ptr return; } dataSizeInput_ = dataSize; - IF_NULL_LOG_ACTION(builder, "%{public}s: input builder nullptr", return); + IF_NULL_LOG_ACTION(builder, "%{public}s: input builder nullptr", return ); CreatePurgeableData_(); builder_ = std::move(builder); @@ -111,9 +111,7 @@ bool PurgeableMem::Unpin() return true; } -void PurgeableMem::AfterRebuildSucc() -{ -} +void PurgeableMem::AfterRebuildSucc() {} int PurgeableMem::GetPinStatus() const { @@ -140,8 +138,7 @@ inline std::string PurgeableMem::ToString() const { std::string dataptrStr = dataPtr_ ? std::to_string((unsigned long long)dataPtr_) : "0"; std::string pageTableStr = pageTable_ ? pageTable_->ToString() : "0"; - return "dataAddr:" + dataptrStr + " dataSizeInput:" + std::to_string(dataSizeInput_) + - " " + pageTableStr; + return "dataAddr:" + dataptrStr + " dataSizeInput:" + std::to_string(dataSizeInput_) + " " + pageTableStr; } } /* namespace PurgeableMem */ } /* namespace OHOS */ diff --git a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp index cb070c9..7202f44 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp @@ -15,12 +15,12 @@ #include /* mmap */ -#include "securec.h" -#include "pm_util.h" -#include "pm_state_c.h" +#include "pm_log.h" #include "pm_smartptr_util.h" +#include "pm_state_c.h" +#include "pm_util.h" #include "purgeable_mem_base.h" -#include "pm_log.h" +#include "securec.h" namespace OHOS { namespace PurgeableMem { @@ -37,13 +37,9 @@ static inline size_t RoundUp_(size_t val, size_t align) return ((val + align - 1) / align) * align; } -PurgeableMemBase::PurgeableMemBase() -{ -} +PurgeableMemBase::PurgeableMemBase() {} -PurgeableMemBase::~PurgeableMemBase() -{ -} +PurgeableMemBase::~PurgeableMemBase() {} bool PurgeableMemBase::BeginRead() { @@ -63,8 +59,8 @@ bool PurgeableMemBase::BeginRead() break; } if (!IfNeedRebuild_()) { - PM_HILOG_DEBUG(LOG_CORE, "%{public}s: not purged, return true. MAP_PUR=0x%{public}x", - __func__, MAP_PURGEABLE); + PM_HILOG_DEBUG( + LOG_CORE, "%{public}s: not purged, return true. MAP_PUR=0x%{public}x", __func__, MAP_PURGEABLE); ret = true; break; } @@ -183,7 +179,7 @@ bool PurgeableMemBase::ModifyContentByBuilder(std::unique_ptrAppendBuilder(std::move(modifier)); + builder_->AppendBuilder(std::move(modifier)); } else { builder_ = std::move(modifier); } @@ -198,9 +194,7 @@ bool PurgeableMemBase::IfNeedRebuild_() return false; } -void PurgeableMemBase::AfterRebuildSucc() -{ -} +void PurgeableMemBase::AfterRebuildSucc() {} void *PurgeableMemBase::GetContent() { @@ -233,9 +227,7 @@ bool PurgeableMemBase::BuildContent_() return succ; } -void PurgeableMemBase::ResizeData(size_t newSize) -{ -} +void PurgeableMemBase::ResizeData(size_t newSize) {} bool PurgeableMemBase::Pin() { diff --git a/libpurgeablemem/cpp/src/purgeable_mem_builder.cpp b/libpurgeablemem/cpp/src/purgeable_mem_builder.cpp index 70b8df5..e6dc348 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem_builder.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem_builder.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "pm_smartptr_util.h" #include "purgeable_mem_builder.h" +#include "pm_smartptr_util.h" namespace OHOS { namespace PurgeableMem { @@ -32,7 +32,7 @@ PurgeableMemBuilder::~PurgeableMemBuilder() void PurgeableMemBuilder::AppendBuilder(std::unique_ptr builder) { - IF_NULL_LOG_ACTION(builder, "input builder is nullptr", return); + IF_NULL_LOG_ACTION(builder, "input builder is nullptr", return ); if (nextBuilder_) { nextBuilder_->AppendBuilder(std::move(builder)); } else { @@ -43,8 +43,8 @@ void PurgeableMemBuilder::AppendBuilder(std::unique_ptr bui bool PurgeableMemBuilder::BuildAll(void *data, size_t size) { if (!Build(data, size)) { - HILOG_ERROR(LOG_CORE, "%{public}s: build(0x%{public}llx, %{public}zu) fail", - __func__, (unsigned long long)data, size); + HILOG_ERROR( + LOG_CORE, "%{public}s: build(0x%{public}llx, %{public}zu) fail", __func__, (unsigned long long)data, size); return false; } if (!nextBuilder_) { diff --git a/libpurgeablemem/cpp/src/purgeable_resource_manager.cpp b/libpurgeablemem/cpp/src/purgeable_resource_manager.cpp index 4790342..b53b79d 100644 --- a/libpurgeablemem/cpp/src/purgeable_resource_manager.cpp +++ b/libpurgeablemem/cpp/src/purgeable_resource_manager.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ +#include "purgeable_resource_manager.h" #include "hitrace_meter.h" #include "parameters.h" #include "pm_log.h" -#include "purgeable_resource_manager.h" namespace OHOS { namespace PurgeableMem { @@ -167,8 +167,8 @@ void PurgeableResourceManager::BeginAccessPurgeableMem() } FinishTrace(HITRACE_TAG_COMMONLIBRARY); - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] BeginAccessPurgeableMem list size: %{public}zu", - lruCache_.Size()); + PM_HILOG_DEBUG( + LOG_CORE, "[PurgeableResourceManager] BeginAccessPurgeableMem list size: %{public}zu", lruCache_.Size()); } void PurgeableResourceManager::EndAccessPurgeableMem() @@ -194,8 +194,8 @@ void PurgeableResourceManager::EndAccessPurgeableMem() } FinishTrace(HITRACE_TAG_COMMONLIBRARY); - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] EndAccessPurgeableMem list size: %{public}zu", - lruCache_.Size()); + PM_HILOG_DEBUG( + LOG_CORE, "[PurgeableResourceManager] EndAccessPurgeableMem list size: %{public}zu", lruCache_.Size()); } void PurgeableResourceManager::AddResource(std::shared_ptr resourcePtr) @@ -209,8 +209,10 @@ void PurgeableResourceManager::AddResource(std::shared_ptr res lruCache_.Insert(resourcePtr); FinishTrace(HITRACE_TAG_COMMONLIBRARY); - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] AddResource resourcePtr: 0x%{public}lx, " - "list size: %{public}zu", (long)resourcePtr.get(), lruCache_.Size()); + PM_HILOG_DEBUG(LOG_CORE, + "[PurgeableResourceManager] AddResource resourcePtr: 0x%{public}lx, " + "list size: %{public}zu", + (long)resourcePtr.get(), lruCache_.Size()); } void PurgeableResourceManager::RemoveResource(std::shared_ptr resourcePtr) @@ -224,8 +226,10 @@ void PurgeableResourceManager::RemoveResource(std::shared_ptr lruCache_.Erase(resourcePtr); FinishTrace(HITRACE_TAG_COMMONLIBRARY); - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] RemoveResource resourcePtr: 0x%{public}lx, " - "list size: %{public}zu", (long)resourcePtr.get(), lruCache_.Size()); + PM_HILOG_DEBUG(LOG_CORE, + "[PurgeableResourceManager] RemoveResource resourcePtr: 0x%{public}lx, " + "list size: %{public}zu", + (long)resourcePtr.get(), lruCache_.Size()); } void PurgeableResourceManager::SetRecentUsedResource(std::shared_ptr resourcePtr) @@ -267,8 +271,10 @@ void PurgeableResourceManager::RemoveLastResource() lruCache_.Erase(resourcePtr); FinishTrace(HITRACE_TAG_COMMONLIBRARY); - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] RemoveLastResource resourcePtr: 0x%{public}lx, " - "list size: %{public}zu", (long)resourcePtr.get(), lruCache_.Size()); + PM_HILOG_DEBUG(LOG_CORE, + "[PurgeableResourceManager] RemoveLastResource resourcePtr: 0x%{public}lx, " + "list size: %{public}zu", + (long)resourcePtr.get(), lruCache_.Size()); } void PurgeableResourceManager::ShowLruCache() const @@ -278,8 +284,10 @@ void PurgeableResourceManager::ShowLruCache() const int cnt = 0; for (auto &resourcePtr : resourcePtrList) { cnt++; - PM_HILOG_DEBUG(LOG_CORE, "[PurgeableResourceManager] ShowLruCache (resourcePtr: 0x%{public}lx, " - "%{public}d th, list size: %{public}zu)", (long)resourcePtr.get(), cnt, lruCache_.Size()); + PM_HILOG_DEBUG(LOG_CORE, + "[PurgeableResourceManager] ShowLruCache (resourcePtr: 0x%{public}lx, " + "%{public}d th, list size: %{public}zu)", + (long)resourcePtr.get(), cnt, lruCache_.Size()); } } diff --git a/libpurgeablemem/cpp/src/ux_page_table.cpp b/libpurgeablemem/cpp/src/ux_page_table.cpp index d58e2b1..661db8f 100644 --- a/libpurgeablemem/cpp/src/ux_page_table.cpp +++ b/libpurgeablemem/cpp/src/ux_page_table.cpp @@ -63,7 +63,6 @@ void UxPageTable::PutUxpte(uint64_t addr, size_t len) UxptePut(uxpt_, addr, len); } - bool UxPageTable::CheckPresent(uint64_t addr, size_t len) { return UxpteIsPresent(uxpt_, addr, len); diff --git a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h index 4125045..60b4252 100644 --- a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h +++ b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h @@ -40,7 +40,7 @@ #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_C_INCLUDE_PURGEABLE_MEMORY_H #include /* bool */ -#include /* size_t */ +#include /* size_t */ #ifdef __cplusplus extern "C" { @@ -80,8 +80,7 @@ typedef bool (*OH_PurgeableMemory_ModifyFunc)(void *, size_t, void *); * @since 10 * @version 1.0 */ -OH_PurgeableMemory *OH_PurgeableMemory_Create( - size_t size, OH_PurgeableMemory_ModifyFunc func, void *funcPara); +OH_PurgeableMemory *OH_PurgeableMemory_Create(size_t size, OH_PurgeableMemory_ModifyFunc func, void *funcPara); /* * @brief: destroy a PurgMem obj. @@ -197,8 +196,7 @@ size_t OH_PurgeableMemory_ContentSize(OH_PurgeableMemory *purgObj); * @since 10 * @version 1.0 */ -bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj, - OH_PurgeableMemory_ModifyFunc func, void *funcPara); +bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj, OH_PurgeableMemory_ModifyFunc func, void *funcPara); #ifdef __cplusplus } diff --git a/libpurgeablemem/test/purgeable_c_test.cpp b/libpurgeablemem/test/purgeable_c_test.cpp index d46d177..c556620 100644 --- a/libpurgeablemem/test/purgeable_c_test.cpp +++ b/libpurgeablemem/test/purgeable_c_test.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include #include +#include #include #include "gtest/gtest.h" @@ -55,29 +55,21 @@ public: void TearDown(); }; -void PurgeableCTest::SetUpTestCase() -{ -} +void PurgeableCTest::SetUpTestCase() {} -void PurgeableCTest::TearDownTestCase() -{ -} +void PurgeableCTest::TearDownTestCase() {} -void PurgeableCTest::SetUp() -{ -} +void PurgeableCTest::SetUp() {} -void PurgeableCTest::TearDown() -{ -} +void PurgeableCTest::TearDown() {} HWTEST_F(PurgeableCTest, MultiObjCreateTest, TestSize.Level1) { const char alphabetFinal[] = "BBCDEFGHIJKLMNOPQRSTUVWXYZ\0"; - struct AlphabetInitParam initPara = {'A', 'Z'}; + struct AlphabetInitParam initPara = { 'A', 'Z' }; struct PurgMem *pobj1 = PurgMemCreate(27, InitAlphabet, &initPara); LoopPrintAlphabet(pobj1, 1); - struct AlphabetModifyParam a2b = {'A', 'B'}; + struct AlphabetModifyParam a2b = { 'A', 'B' }; ModifyPurgMemByFunc(pobj1, ModifyAlphabetX2Y, static_cast(&a2b)); LoopPrintAlphabet(pobj1, 1); LoopReclaimPurgeable(1); @@ -108,7 +100,7 @@ HWTEST_F(PurgeableCTest, MultiObjCreateTest, TestSize.Level1) HWTEST_F(PurgeableCTest, ReadTest, TestSize.Level1) { const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\0"; - struct AlphabetInitParam initPara = {'A', 'Z'}; + struct AlphabetInitParam initPara = { 'A', 'Z' }; struct PurgMem *pobj = PurgMemCreate(27, InitAlphabet, &initPara); LoopReclaimPurgeable(1); @@ -129,12 +121,12 @@ HWTEST_F(PurgeableCTest, ReadTest, TestSize.Level1) HWTEST_F(PurgeableCTest, WriteTest, TestSize.Level1) { const char alphabet[] = "CCCDEFGHIJKLMNOPQRSTUVWXYZ\0"; - struct AlphabetInitParam initPara = {'A', 'Z'}; + struct AlphabetInitParam initPara = { 'A', 'Z' }; struct PurgMem *pobj = PurgMemCreate(27, InitAlphabet, &initPara); LoopReclaimPurgeable(1); - struct AlphabetModifyParam a2b = {'A', 'B'}; - struct AlphabetModifyParam b2c = {'B', 'C'}; + struct AlphabetModifyParam a2b = { 'A', 'B' }; + struct AlphabetModifyParam b2c = { 'B', 'C' }; ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&a2b)); ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&b2c)); @@ -152,14 +144,14 @@ HWTEST_F(PurgeableCTest, WriteTest, TestSize.Level1) HWTEST_F(PurgeableCTest, ReadWriteTest, TestSize.Level1) { const char alphabet[] = "DDDDEFGHIJKLMNOPQRSTUVWXYZ\0"; - struct AlphabetInitParam initPara = {'A', 'Z'}; + struct AlphabetInitParam initPara = { 'A', 'Z' }; struct PurgMem *pobj = PurgMemCreate(27, InitAlphabet, &initPara); LoopReclaimPurgeable(1); LoopPrintAlphabet(pobj, 1); - struct AlphabetModifyParam a2b = {'A', 'B'}; - struct AlphabetModifyParam b2c = {'B', 'C'}; - struct AlphabetModifyParam c2d = {'C', 'D'}; + struct AlphabetModifyParam a2b = { 'A', 'B' }; + struct AlphabetModifyParam b2c = { 'B', 'C' }; + struct AlphabetModifyParam c2d = { 'C', 'D' }; ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&a2b)); ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&b2c)); ModifyPurgMemByFunc(pobj, ModifyAlphabetX2Y, static_cast(&c2d)); @@ -190,8 +182,8 @@ 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; + std::cout << "quit " << __func__ << ": " << para->start << "-" << para->end << ", data=[" << (char *)data << "]" + << ", ret=" << (ret ? "true" : "false") << std::endl; return ret; } @@ -211,11 +203,11 @@ bool ModifyData_(void *data, size_t size, char src, char dst) 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; + 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; + std::cout << "quit , data=[" << (char *)data << "]" << __func__ << ", ret=" << (ret ? "true" : "false") + << std::endl; return ret; } @@ -227,8 +219,7 @@ void LoopPrintAlphabet(struct PurgMem *pdata, unsigned int loopCount) std::cout << __func__ << ": " << i << ". ERROR! BeginRead failed." << std::endl; break; } - std::cout << __func__ << ": " << i << ". data=[" << - (char *)PurgMemGetContent(pdata) << "]" << std::endl; + std::cout << __func__ << ": " << i << ". data=[" << (char *)PurgMemGetContent(pdata) << "]" << std::endl; PurgMemEndRead(pdata); std::this_thread::sleep_for(std::chrono::seconds(PRINT_INTERVAL_SECONDS)); } @@ -275,7 +266,7 @@ void ModifyPurgMemByFunc(struct PurgMem *pdata, PurgMemModifyFunc Modfunc, void std::this_thread::sleep_for(std::chrono::seconds(MODIFY_INTERVAL_SECONDS)); std::cout << __func__ << " before mod data=[" << (char *)PurgMemGetContent(pdata) << "]" << std::endl; PurgMemAppendModify(pdata, Modfunc, param); - std::cout<< __func__ << " after mod data=[" << (char *)PurgMemGetContent(pdata) << "]" << std::endl; + std::cout << __func__ << " after mod data=[" << (char *)PurgMemGetContent(pdata) << "]" << std::endl; std::cout << __func__ << " data=[" << (char *)PurgMemGetContent(pdata) << "]" << std::endl; PurgMemEndWrite(pdata); diff --git a/libpurgeablemem/test/purgeable_cpp_test.cpp b/libpurgeablemem/test/purgeable_cpp_test.cpp index 20fbcc5..dfbea9a 100644 --- a/libpurgeablemem/test/purgeable_cpp_test.cpp +++ b/libpurgeablemem/test/purgeable_cpp_test.cpp @@ -14,9 +14,9 @@ */ #include -#include -#include /* unique_ptr */ #include +#include /* unique_ptr */ +#include #include "gtest/gtest.h" #include "purgeable_mem.h" @@ -52,8 +52,8 @@ public: str[len++] = ch; } str[size - 1] = 0; - std::cout << "rebuild addr("<< (unsigned long long)str <<") " << - start_ << "~" << end_ << ", data=[" << str << "]" << std::endl; + std::cout << "rebuild addr(" << (unsigned long long)str << ") " << start_ << "~" << end_ << ", data=[" << str + << "]" << std::endl; return true; } @@ -134,21 +134,13 @@ public: void TearDown(); }; -void PurgeableCppTest::SetUpTestCase() -{ -} +void PurgeableCppTest::SetUpTestCase() {} -void PurgeableCppTest::TearDownTestCase() -{ -} +void PurgeableCppTest::TearDownTestCase() {} -void PurgeableCppTest::SetUp() -{ -} +void PurgeableCppTest::SetUp() {} -void PurgeableCppTest::TearDown() -{ -} +void PurgeableCppTest::TearDown() {} HWTEST_F(PurgeableCppTest, MultiObjCreateTest, TestSize.Level1) { diff --git a/libpurgeablemem/test/purgeableashmem_test.cpp b/libpurgeablemem/test/purgeableashmem_test.cpp index 6bf930e..b060218 100644 --- a/libpurgeablemem/test/purgeableashmem_test.cpp +++ b/libpurgeablemem/test/purgeableashmem_test.cpp @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include #include @@ -59,8 +59,8 @@ public: str[len++] = ch; } str[size - 1] = 0; - std::cout << "rebuild addr("<< (unsigned long long)str <<") " << - start_ << "~" << end_ << ", data=[" << str << "]" << std::endl; + std::cout << "rebuild addr(" << (unsigned long long)str << ") " << start_ << "~" << end_ << ", data=[" << str + << "]" << std::endl; return true; } @@ -141,21 +141,13 @@ public: void TearDown(); }; -void PurgeableAshmemTest::SetUpTestCase() -{ -} +void PurgeableAshmemTest::SetUpTestCase() {} -void PurgeableAshmemTest::TearDownTestCase() -{ -} +void PurgeableAshmemTest::TearDownTestCase() {} -void PurgeableAshmemTest::SetUp() -{ -} +void PurgeableAshmemTest::SetUp() {} -void PurgeableAshmemTest::TearDown() -{ -} +void PurgeableAshmemTest::TearDown() {} HWTEST_F(PurgeableAshmemTest, KernelInterfaceTest, TestSize.Level1) { @@ -608,5 +600,5 @@ void ModifyPurgMemByBuilder(PurgeableAshMem *pdata, std::unique_ptrModifyContentByBuilder(std::move(mod)); pdata->EndWrite(); } -} /* namespace PurgeableAshMem */ +} // namespace PurgeableMem } /* namespace OHOS */ diff --git a/purgeable_builder/include/purgeable_pixelmap_builder.h b/purgeable_builder/include/purgeable_pixelmap_builder.h index 3a357e0..4a415c5 100644 --- a/purgeable_builder/include/purgeable_pixelmap_builder.h +++ b/purgeable_builder/include/purgeable_pixelmap_builder.h @@ -31,8 +31,8 @@ using namespace OHOS::Media; class PurgeablePixelMapBuilder : public PurgeableMem::PurgeableMemBuilder { public: - PurgeablePixelMapBuilder(uint32_t index, std::unique_ptr &imageSource, - DecodeOptions opts, PixelMap *pixelMap); + PurgeablePixelMapBuilder( + uint32_t index, std::unique_ptr &imageSource, DecodeOptions opts, PixelMap *pixelMap); bool Build(void *data, size_t size) override; @@ -46,12 +46,12 @@ private: }; // class PurgeablePixelMapBuilder bool GetSysForPurgeable(); -void SetBuilderToBePurgeable(std::unique_ptr &pixelMap, - std::unique_ptr &builder); +void SetBuilderToBePurgeable( + std::unique_ptr &pixelMap, std::unique_ptr &builder); void RemoveFromPurgeableResourceMgr(std::shared_ptr &pixelMap); void AddToPurgeableResourceMgr(std::unique_ptr &pixelMap); -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, - std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts); +bool MakePixelMapToBePurgeable( + std::unique_ptr &pixelMap, std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts); bool IfCanBePurgeable(DecodeOptions &decodeOpts); } // namespace PurgeableBuilder } // namespace OHOS diff --git a/purgeable_builder/src/purgeable_pixelmap_builder.cpp b/purgeable_builder/src/purgeable_pixelmap_builder.cpp index 8229bd1..aa04b36 100644 --- a/purgeable_builder/src/purgeable_pixelmap_builder.cpp +++ b/purgeable_builder/src/purgeable_pixelmap_builder.cpp @@ -15,8 +15,8 @@ #include "purgeable_pixelmap_builder.h" -#include "hitrace_meter.h" #include "hilog/log.h" +#include "hitrace_meter.h" #include "parameters.h" #include "purgeable_ashmem.h" #include "purgeable_mem_base.h" @@ -38,9 +38,10 @@ const std::string SYSTEM_PARAM_PURGEABLE_ENABLE = "persist.memmgr.purgeable.enab const std::string SYSTEM_PARAM_PIXELMAP_THRESHOLD_HEIGHT = "persist.memmgr.purgeable.pixelmap.threshold.height"; const std::string SYSTEM_PARAM_PIXELMAP_THRESHOLD_WIDGHT = "persist.memmgr.purgeable.pixelmap.threshold.widght"; -PurgeablePixelMapBuilder::PurgeablePixelMapBuilder(uint32_t index, std::unique_ptr &imageSource, - DecodeOptions opts, PixelMap *pixelMap) - : index_(index), opts_(opts), pixelMap_(pixelMap), imageSource_(move(imageSource)) {} +PurgeablePixelMapBuilder::PurgeablePixelMapBuilder( + uint32_t index, std::unique_ptr &imageSource, DecodeOptions opts, PixelMap *pixelMap) + : index_(index), opts_(opts), pixelMap_(pixelMap), imageSource_(move(imageSource)) +{} bool PurgeablePixelMapBuilder::Build(void *data, size_t size) { @@ -57,8 +58,8 @@ bool PurgeablePixelMapBuilder::Build(void *data, size_t size) return false; } - StartTrace(HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " + - std::to_string(size))); + StartTrace( + HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " + std::to_string(size))); memcpy_s((char *)pixelMap_->GetPixels(), size, (char *)pixelMap->GetPixels(), size); DoRebuildSuccessCallback(); @@ -74,11 +75,11 @@ bool GetSysForPurgeable() return system::GetBoolParameter(SYSTEM_PARAM_PURGEABLE_ENABLE, false); } -void SetBuilderToBePurgeable(std::unique_ptr &pixelMap, - std::unique_ptr &builder) +void SetBuilderToBePurgeable( + std::unique_ptr &pixelMap, std::unique_ptr &builder) { - HiviewDFX::HiLog::Debug(LABEL, "set builder for purgeable pixelmap. allocatorType = %{public}d.", - pixelMap->GetAllocatorType()); + HiviewDFX::HiLog::Debug( + LABEL, "set builder for purgeable pixelmap. allocatorType = %{public}d.", pixelMap->GetAllocatorType()); StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::SetBuilderToBePurgeable"); if (builder == nullptr) { FinishTrace(HITRACE_TAG_ZIMAGE); @@ -88,8 +89,8 @@ void SetBuilderToBePurgeable(std::unique_ptr &pixelMap, if (pixelMap->GetAllocatorType() == AllocatorType::SHARE_MEM_ALLOC) { std::shared_ptr tmpPtr = std::make_shared(std::move(builder)); - bool isChanged = tmpPtr->ChangeAshmemData(pixelMap->GetCapacity(), - *(static_cast(pixelMap->GetFd())), pixelMap->GetWritablePixels()); + bool isChanged = tmpPtr->ChangeAshmemData( + pixelMap->GetCapacity(), *(static_cast(pixelMap->GetFd())), pixelMap->GetWritablePixels()); if (isChanged) { pixelMap->SetPurgeableMemPtr(tmpPtr); pixelMap->GetPurgeableMemPtr()->BeginRead(); @@ -137,8 +138,8 @@ bool IfCanBePurgeable(DecodeOptions &decodeOpts) return true; } -bool MakePixelMapToBePurgeable(std::unique_ptr &pixelMap, std::unique_ptr &backupImgSrc4Rebuild, - DecodeOptions &decodeOpts) +bool MakePixelMapToBePurgeable( + std::unique_ptr &pixelMap, std::unique_ptr &backupImgSrc4Rebuild, DecodeOptions &decodeOpts) { StartTrace(HITRACE_TAG_ZIMAGE, "OHOS::PurgeableBuilder::MakePixelMapToBePurgeable"); HiviewDFX::HiLog::Debug(LABEL, "MakePixelMapToBePurgeable in."); -- Gitee From 5fec2eb041f241fbcb39615c80a9dea76b54f818 Mon Sep 17 00:00:00 2001 From: zhoumengjie Date: Mon, 19 Jun 2023 19:07:52 +0800 Subject: [PATCH 3/3] copyright Signed-off-by: zhoumengjie Change-Id: I1f3b55ae59b4415be79d44320776898e8fafa631 --- format.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/format.sh b/format.sh index e3c683d..dd2a4d6 100755 --- a/format.sh +++ b/format.sh @@ -1,8 +1,18 @@ -#!/bin/bash +# Copyright (c) 2023 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 -# clang-format -style=file -i code.cpp +# 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. -# echo `ls $1` + +#!/bin/bash read_dir(){ for file in `ls $1` -- Gitee