diff --git a/concurrentqueue/BUILD.gn b/concurrentqueue/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7d588b441b3e211fd098d5ea2898113e1a49f0b0 --- /dev/null +++ b/concurrentqueue/BUILD.gn @@ -0,0 +1,83 @@ +import("//build/ohos.gni") + +declare_args() { + enable_queue_test = false +} + +config("config") { + cflags = [ + "-fPIC", + "-Wall", + "-frtti", + "-fexceptions", + "-Wno-error=unused-variable", + "-Wno-error=self-move", + ] + + cflags_cc = cflags +} + +##生成可执行文件 +ohos_executable("unittests") { + sources = [ + "//third_party/concurrentqueue/tests/common/simplethread.cpp", + "//third_party/concurrentqueue/tests/common/systemtime.cpp", + "//third_party/concurrentqueue/tests/unittests/unittests.cpp", + ] + include_dirs = [ + "//third_party/concurrentqueue", + "//third_party/concurrentqueue/c_api", + "//third_party/concurrentqueue/tests/common", + "//third_party/concurrentqueue/tests/unittests", + ] + + configs = [ ":config" ] + + deps = [ "//third_party/concurrentqueue:concurrentqueue" ] + subsystem_name = "thirdparty" + part_name = "concurrentqueue" +} + +##生成可执行文件 +ohos_executable("fuzztests") { + sources = [ + "//third_party/concurrentqueue/tests/common/simplethread.cpp", + "//third_party/concurrentqueue/tests/common/systemtime.cpp", + "//third_party/concurrentqueue/tests/fuzztests/fuzztests.cpp", + ] + include_dirs = [ + "//third_party/concurrentqueue", + "//third_party/concurrentqueue/c_api", + "//third_party/concurrentqueue/tests/common", + "//third_party/concurrentqueue/tests/fuzztests", + ] + + configs = [ ":config" ] + deps = [ "//third_party/concurrentqueue:concurrentqueue" ] + subsystem_name = "thirdparty" + part_name = "concurrentqueue" +} + +ohos_shared_library("concurrentqueue") { + sources = [ + "//third_party/concurrentqueue/c_api/blockingconcurrentqueue.cpp", + "//third_party/concurrentqueue/c_api/concurrentqueue.cpp", + ] + + include_dirs = [ + "//third_party/concurrentqueue", + "//third_party/concurrentqueue/c_api", + ] + subsystem_name = "thirdparty" + part_name = "concurrentqueue" +} + +group("concurrentqueues") { + deps = [ ":concurrentqueue" ] + if (enable_queue_test) { + deps += [ + ":fuzztests", + ":unittests", + ] + } +} diff --git a/concurrentqueue/CHANGELOG.md b/concurrentqueue/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..4963dc7546e7cc84baf8e836c544ddf43f554025 --- /dev/null +++ b/concurrentqueue/CHANGELOG.md @@ -0,0 +1,3 @@ +# 1.0.0 + +添加BUILD.gn和cmake,适配在ohos上的编译 diff --git a/concurrentqueue/CMakeLists.txt b/concurrentqueue/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9fa2bdaa905eaee7ad96ef390260de0ced18bcb1 --- /dev/null +++ b/concurrentqueue/CMakeLists.txt @@ -0,0 +1,22 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(ConcurrentQueue) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/concurrentqueue) + + +add_library(concurrentqueue SHARED concurrentqueue/c_api/concurrentqueue.cpp concurrentqueue/c_api/concurrentqueue.cpp) + +add_executable(unittests concurrentqueue/tests/unittests/unittests.cpp concurrentqueue/tests/common/simplethread.cpp concurrentqueue/tests/common/systemtime.cpp) +add_executable(fuzztests concurrentqueue/tests/fuzztests/fuzztests.cpp concurrentqueue/tests/common/simplethread.cpp concurrentqueue/tests/common/systemtime.cpp) + +target_include_directories(concurrentqueue PRIVATE ${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/concurrentqueue/tests/common + ${NATIVERENDER_ROOT_PATH}/concurrentqueue/tests/unittests + ${NATIVERENDER_ROOT_PATH}/concurrentqueue/tests/fuzztests + ${NATIVERENDER_ROOT_PATH}/concurrentqueue/tests/c_api) + +target_link_libraries(unittests PUBLIC concurrentqueue) \ No newline at end of file diff --git a/concurrentqueue/README.OpenSource b/concurrentqueue/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..d8736fb5f8d4572496efc6dc313275dba7f477bf --- /dev/null +++ b/concurrentqueue/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "concurrentqueue", + "License": "BSD License", + "License File": "LICENSE", + "Version Number": "v1.0.3", + "Owner" : "wangyingjun5@huawei.com", + "Upstream URL": "https://github.com/cameron314/concurrentqueue", + "Description": "A fast multi-producer, multi-consumer lock-free concurrent queue for C++11" + } +] diff --git a/concurrentqueue/README_zh.md b/concurrentqueue/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..5fa3a8992e050b7c307fcba83af8b46a922bd115 --- /dev/null +++ b/concurrentqueue/README_zh.md @@ -0,0 +1,17 @@ +# concurrentqueue 三方库说明 + +## 功能简介 + +concurrentqueue是一个高效的线程安全的队列的库。 + +## 使用约束 + +- Rom版本:OpenHarmony3.2 beta2 +- 三方库版本:v1.0.3 +- 当前适配的功能:入队与出队 +- License:[BSD License](https://github.com/cameron314/concurrentqueue/blob/master/LICENSE.md) + +## 集成方式 + +- [系统Rom包集成](./docs/rom_integrate.md) ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/concurrentqueue/bundle.json b/concurrentqueue/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..431fcde7bb8c790cb2f773643a22b7865322e7db --- /dev/null +++ b/concurrentqueue/bundle.json @@ -0,0 +1,35 @@ +{ + "name": "@ohos/concurrentqueue", + "description": "A fast multi-producer, multi-consumer lock-free concurrent queue for C++11", + "version": "v1.0.3", + "license": "BSD License", + "publishAs": "", + "segment": { + "destPath": "third_party/concurrentqueue" + }, + "dirs": {}, + "scripts": {}, + "readmePath": { + "en": "README" + }, + "component": { + "name": "concurrentqueue", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": ["standard"], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [ + "//third_party/concurrentqueue:concurrentqueues" + ], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/concurrentqueue/docs/hap_integrate.md b/concurrentqueue/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..6cf2db88bb141b6a3c29670fa928dc68c04e9295 --- /dev/null +++ b/concurrentqueue/docs/hap_integrate.md @@ -0,0 +1,46 @@ +# concurrentqueue如何集成到应用hap +## 准备应用工程 +本库是基于DevEco Studio 3.1 Beta1版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +### 准备应用开发环境 +开发环境的准备参考:[开发环境准备](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) +### 增加构建脚本及配置文件 +- 下载本仓库,并解压 +- 三方库目录结构 + ``` + tpc_c_cplusplus/concurrentqueue #三方库concurrentqueue的目录结构如下 + ├── docs #存放三方库相关文档的文件夹 + ├── CmakeLists.txt #构建脚本,支持hap包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将concurrentqueue拷贝至工程xxxx/entry/src/main/cpp/thirdparty目录下 +### 准备三方库源码 +- 三方库下载地址:[concurrentqueue](https://github.com/cameron314/concurrentqueue), 版本:v1.0.3 + 解压后修改库文件名为concurrentqueue,拷贝至工程xxxx/entry/src/main/cpp/thirdparty/concurrentqueue目录下 +## 应用中使用三方库 +- 将三方库加入工程中,目录结构如下 + ``` + demo/entry/src/main/cpp + ├── thirdparty #三方库存放目录 + │ ├──concurrentqueue #三方库concurrentqueue + ├── CMakeLists.txt #工程目录的构建脚本 + ├── ..... #工程目录的其他文件 + ``` +- 在工程顶级CMakeLists.txt中引入三方库,增加如下代码 + ``` + include_directories(thirdparty/concurrentqueue/include) + add_subdirectory(thirdparty/concurrentqueue) #引入子目录下的CMakeLists.txt + target_link_libraries(工程库名 PUBLIC concurrentqueue) #工程依赖三方库concurrentqueue + ``` +## 编译工程 +编译工程,安装应用可以参考 [应用的安装和运行](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#%E5%AE%89%E8%A3%85%E8%B0%83%E8%AF%95) +## 运行效果 +- 在 [concurrentqueue](https://gitee.com/openharmony-tpc/openharmony_tpc_samples/tree/master/concurrentqueue)中,运行效果如下图 +  ![演示](pic/hap.jpeg) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md#https://gitee.com/openharmony-sig/knowledge/tree/master) + diff --git a/concurrentqueue/docs/pic/hap.jpeg b/concurrentqueue/docs/pic/hap.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..32fcbddc60505c1241df6114cf6ac12a985906ff Binary files /dev/null and b/concurrentqueue/docs/pic/hap.jpeg differ diff --git a/concurrentqueue/docs/pic/result.PNG b/concurrentqueue/docs/pic/result.PNG new file mode 100644 index 0000000000000000000000000000000000000000..bfef8c6146cba53c51cf85da984b5a1b0af75916 Binary files /dev/null and b/concurrentqueue/docs/pic/result.PNG differ diff --git a/concurrentqueue/docs/rom_integrate.md b/concurrentqueue/docs/rom_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..7a5f15fddeec23ec1f56c0fd676f011c44757259 --- /dev/null +++ b/concurrentqueue/docs/rom_integrate.md @@ -0,0 +1,107 @@ +# concurrentqueue如何集成到系统Rom +## 准备源码工程 +本库是基于OpenHarmony-v3.2-Beta2版本,在RK3568开发板上验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +### 准备系统Rom源码 +系统源码获取请参考:[OpenHarmony源码下载](https://gitee.com/openharmony/docs/blob/OpenHarmony-v3.2-Beta3/zh-cn/release-notes/OpenHarmony-v3.2-beta2.md) +### 增加构建脚本及配置文件 +- 下载本仓库代码 + ``` + cd ~ + git clone git@gitee.com:openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` +- 三方库目录结构 + ``` + tpc_c_cplusplus/concurrentqueue #三方库concurrentqueue的目录结构如下 + ├── docs #存放三方库相关文档的文件夹 + ├── BUILD.gn #构建脚本,支持rom包集成 + ├── bundle.json #三方库组件定义文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` +- 将三方库拷贝到OpenHarmony源码的third_party目录下 + ``` + cp ~/tpc_c_cplusplus/concurrentqueue ~/openharmony/third_party -rf + ``` +### 准备三方库源码 +``` +cd ~/openharmony/third_party/concurrentqueue #进入三方库目录 +git clone https://github.com/cameron314/concurrentqueue.git #下载三方库源码 +``` +## 系统Rom中引入三方库 +准备完三方库代码后,我们需要将三方库加入到编译构建体系中。标准系统编译构建可以参考文档[标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) 我们默认三方库是属于OpenHarmony的thirdparty子系统,如果需要自己定义子系统参考文档[如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) 新增需要编译的组件,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件中,新增需要编译的组件,如下代码段所示,在thirdparty子系统下面新增concurrentqueue组件 +``` + { + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "concurrentqueue", + "features": [] + } + ] + } +``` + +## 系统Rom中引入三方库测试程序 +concurrentqueue原生库提供了测试用例,如需要引入测试程序,在OpenHarmony源码的vendor/hihope/rk3568/config.json文件,对应组件的features中打开编译选项: +``` +{ + "subsystem": "thirdparty", + "components": [ + { + "component": "musl", + "features": [] + }, + { + "component": "concurrentqueue", + "features": [ "enable_queue_test=true" ] + } + ] +} +``` +## 编译工程 +在OpenHarmony源码根目录下 +``` +cd ~/openharmony +``` +- 执行编译 + ``` + ./build.sh --product-name rk3568 --ccache + ``` +- 生成文件的路径 + 可执行文件和库生成在out/rk3568/thirdparty/concurrentqueue +## 运行效果 +将编译生成的库和测试文件放到板子上运行,为避免每次将文件推入设备都烧录整个镜像,我们使用hdc_std工具将文件推到开发板上 +- 首先将hdc_std工具编译出来 工具编译出来所在路径out/sdk/ohos-sdk/windows/toolchains/hdc_std.exe + ``` + hb set #源码根目录下使用hb set 选择产品ohos-sdk + hb build #然后编译 + ``` +- 将工具拷贝到Windows,可以为工具目录配置环境变量,也可以在工具所在目录打开windows命令行 +- 将编译生成的unittests和fuzztests可执行文件准备好 +- 将准备好的文件推送到开发板,在windows命令行进行如下操作 + ``` + hdc_std shell mount -o remount,rw / #修改系统权限为可读写 + hdc_std file send unittests /data #将可执行文件推入开发板data目录 + hdc_std file send fuzztests /data #将可执行文件推入开发板data目录 + hdc_std file send libconcurrentqueue.z.so /system/lib64 + hdc_std file send libconcurrentqueue.z.so /system/lib + hdc_std shell #进入开发板 + chmod 777 /data/unittests #添加权限 + chmod 777 /data/fuzztests #添加权限 + cd data #进入测试文件目录 + ./unittests #执行测试文件 + ./fuzztests #执行测试文件 + ``` +- 运行测试程序 效果如下图 +- ![result](pic/result.PNG) +## 参考资料 +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [如何为三方库组件中添加一个三方库](https://gitee.com/openharmony-sig/knowledge/blob/master/docs/openharmony_getstarted/port_thirdparty/README.md) +- [标准系统编译构建指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/device-dev/subsystems/subsys-build-standard-large.md) +