diff --git a/thirdparty/threadpool/HPKBUILD b/thirdparty/threadpool/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..0a8dd4e9f6bf8ded224a9064b873fe67f7236ed0 --- /dev/null +++ b/thirdparty/threadpool/HPKBUILD @@ -0,0 +1,101 @@ +# 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 +# +# 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. + +# Contributor: Jeff Han , Sunjiamei<939650669@qq.com> +# Maintainer: Jeff Han + + +pkgname=threadpool +pkgver=master +pkgrel=0 +pkgdesc="A simple C++11 Thread Pool implementation." +url="https://github.com/progschj/threadpool" +archs=("armeabi-v7a" "arm64-v8a") +license=("zlib License") +depends=() +makedepends=() + +source="https://github.com/progschj/$pkgname/archive/refs/heads/$pkgver.zip" + +autounpack=true +downloadpackage=true +buildtools="make" + +builddir=$pkgname-${pkgver} +packagename=$builddir.zip + +ar= +cXX= +source envset.sh +patchflag=true + +# threadpool 采用makefile编译构建,为了保留构建环境(方便测试)。因此同一份源码在解压后分为两份,各自编译互不干扰 +prepare() { + if [ $patchflag == true ] + then + cd $builddir + patch -p1 < `pwd`/../threadpool_oh_pkg.patch > $publicbuildlog 2>&1 + patchflag=false + cd $OLDPWD + fi + + cp -rf $builddir $builddir-$ARCH-build + if [ $ARCH == "armeabi-v7a" ] + then + cXX=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang++ + ar=${OHOS_SDK}/native/llvm/bin/llvm-ar + fi + if [ $ARCH == "arm64-v8a" ] + then + cXX=${OHOS_SDK}/native/llvm/bin/aarch64-linux-ohos-clang++ + ar=${OHOS_SDK}/native/llvm/bin/llvm-ar + fi +} + +# ThreadPool库仅有.h文件 +build() { + echo "ThreadPool the library has only one .h file!" +} + +package() { + install_dir=${LYCIUM_ROOT}/usr/${pkgname}/${ARCH} + cd $builddir-$ARCH-build/ + mkdir -p ${install_dir}/include + cp -arf ./ThreadPool.h ${install_dir}/include + cd ${OLDPWD} +} + +check() { + if [ $ARCH == "armeabi-v7a" ]; then + # 拷贝shared库到测试程序运行目录 + cp $OHOS_SDK/native/llvm/lib/arm-linux-ohos/libc++_shared.so $builddir-$ARCH-build + elif [ $ARCH == "arm64-v8a" ]; then + # 拷贝shared库到测试程序运行目录 + cp $OHOS_SDK/native/llvm/lib/aarch64-linux-ohos/libc++_shared.so $builddir-$ARCH-build + else + echo "Not support ${ARCH} yet" + return -1 + fi + cd $builddir-$ARCH-build/ + $MAKE LIB="$ar cr" CXX="$cXX" > $buildlog 2>&1 + ret=$? + cd $OLDPWD + unset ar + unset cXX + echo "The test must be on an OpenHarmony device!" + return $ret +} + +cleanbuild() { + rm -rf ${PWD}/$builddir $builddir-armeabi-v7a-build $builddir-arm64-v8a-build +} diff --git a/thirdparty/threadpool/HPKCHECK b/thirdparty/threadpool/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..b722472e213bc3801d651f96f280aff986b60c91 --- /dev/null +++ b/thirdparty/threadpool/HPKCHECK @@ -0,0 +1,36 @@ +# 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 +# +# 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. + +# Contributor: Jeff Han , Sunjiamei<939650669@qq.com> +# Maintainer: Jeff Han + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir-$ARCH-build/ + # 添加libc++_shared.so库,到LDLIBRARY_PATH环境变量 + export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH + echo "total test 1" > ${logfile} 2>&1 + ./example >> ${logfile} 2>&1 + res=$? + if [$res -ne 0];then + echo "test error" >> ${logfile} 2>&1 + cd $OLDPWD + return $res + fi + echo "test pass" >> ${logfile} 2>&1 + cd $OLDPWD + return $res +} diff --git a/thirdparty/threadpool/OAT.xml b/thirdparty/threadpool/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..211b81fb607ad0792b29636251094bacd2736f2d --- /dev/null +++ b/thirdparty/threadpool/OAT.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/thirdparty/threadpool/README.OpenSource b/thirdparty/threadpool/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..1aa78988bebe33d276234585bc6cdf03a1f4c353 --- /dev/null +++ b/thirdparty/threadpool/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "threadpool", + "License": "Copyright (c) 2012 Jakob Progsch, Václav Zeman", + "License File": "COPYING", + "Version Number": "master", + "Owner": "huangminzhong2@huawei.com", + "Upstream URL": "https://github.com/progschj/threadpool", + "Description": "Threadpool is A simple C++11 Thread Pool implementation." + } +] diff --git a/thirdparty/threadpool/README_zh.md b/thirdparty/threadpool/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..33c264c134ff84f47b8f2e71c3c60acd0b6839f3 --- /dev/null +++ b/thirdparty/threadpool/README_zh.md @@ -0,0 +1,10 @@ +# threadpool 三方库说明 +## 功能简介 +threadpool是一个简单的c++线程池实现。 +## 使用约束 +- IDE版本:DevEco Studio 4.1 Release +- SDK版本:sdk-linux-5.0.3.100 +- 三方库版本:master + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/threadpool/SHA512SUM b/thirdparty/threadpool/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..d19fc12cb41aca73edbe9130db876028dd9f407d --- /dev/null +++ b/thirdparty/threadpool/SHA512SUM @@ -0,0 +1 @@ +5361dbd58d308f06ac1ed6ab84a3d753fe337ee15c6248c2545ec05a578cf5f54a53aa01b625811e45d2c7af637a9a8567a430f9720ae0a9ccb818bd3f2be6e3 threadpool-master.zip diff --git a/thirdparty/threadpool/docs/hap_integrate.md b/thirdparty/threadpool/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..f3cb8b560046e5d402352d4356ee273ada882eb1 --- /dev/null +++ b/thirdparty/threadpool/docs/hap_integrate.md @@ -0,0 +1,81 @@ +# threadpool集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +* 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +* 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/threadpool #三方库threadpool的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #测试脚本 + ├── OAT.xml #扫描结果文件 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库简介 + ├── threadpool_oh_pkg.patch #用于threadpool库编译的补丁 + ``` + +* 在lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd lycium + ./build.sh threadpool + ``` + +* 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + threadpool/arm64-v8a threadpool/armeabi-v7a + ``` + +* [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的头文件拷贝到该目录下,如下图所示: + + ![thirdparty_install_dir](pic/threadpool-dev.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```cmake + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/threadpool/${OHOS_ARCH}/include) + ``` + + +## 测试三方库 + +- 编译出可执行的文件进行测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +- 进入到构建目录运行测试用例(注意arm64-v8a为构建64位的目录,armeabi-v7a为构建32位的目录),执行结果如图所示 +``` + cd /data/tpc_c_cplusplus/thirdparty/threadpool/threadpool-master-armeabi-v7a-build + ./example +``` + + ![libice_test](pic/test-cmd-ret.png) + +## 参考资料 + +* [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +* [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +* [threadpool三方库地址](https://github.com/progschj/threadpool) + diff --git a/thirdparty/threadpool/docs/pic/test-cmd-ret.png b/thirdparty/threadpool/docs/pic/test-cmd-ret.png new file mode 100644 index 0000000000000000000000000000000000000000..06ddebd0316ef4044d473bb9e55c08699e94db18 Binary files /dev/null and b/thirdparty/threadpool/docs/pic/test-cmd-ret.png differ diff --git a/thirdparty/threadpool/docs/pic/threadpool-dev.png b/thirdparty/threadpool/docs/pic/threadpool-dev.png new file mode 100644 index 0000000000000000000000000000000000000000..2a94efce700b90decf0d7f25d4bb8c026c1999e9 Binary files /dev/null and b/thirdparty/threadpool/docs/pic/threadpool-dev.png differ diff --git a/thirdparty/threadpool/threadpool_oh_pkg.patch b/thirdparty/threadpool/threadpool_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..7c6be58ffc109e6597f0e0e62c07e194619cbe3d --- /dev/null +++ b/thirdparty/threadpool/threadpool_oh_pkg.patch @@ -0,0 +1,28 @@ +diff -Naur threadpool-master/Makefile threadpool-master-new/Makefile +--- threadpool-master/Makefile 1970-01-01 08:00:00.000000000 +0800 ++++ threadpool-master-new/Makefile 2024-06-07 17:53:08.453349200 +0800 +@@ -0,0 +1,19 @@ ++# Makefile ++ ++CXX = g++ ++CFLAGS = -g -Wall ++ ++EXAMPLE = example ++SRCS:=$(wildcard *.cpp) ++OBJS:=$(patsubst %.cpp,%.o, $(SRCS)) ++ ++$(EXAMPLE): $(OBJS) ++ @echo "[CXX] $@" ++ @$(CXX) $(OBJS) -o $(EXAMPLE) ++ ++%.o: %.cpp ++ @echo "[CXX] $< $@" ++ @$(CXX) $(CFLAGS) -c $< -o $@ ++ ++clean: ++ rm -f $(OBJS) $(EXAMPLE) +diff -Naur threadpool-master/last_error threadpool-master-new/last_error +--- threadpool-master/last_error 1970-01-01 08:00:00.000000000 +0800 ++++ threadpool-master-new/last_error 2024-06-07 18:52:58.280582300 +0800 +@@ -0,0 +1 @@ ++ERROR during : check: 2