Skip to content

Commit

Permalink
[doc] add xmake compile mothed in COMPILE.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Jul 7, 2024
1 parent 7d06fad commit 1ca9486
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
30 changes: 18 additions & 12 deletions COMPILE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

* 本工程支持`MacOS``Linux``Windows``Android`系统,无任何第三方依赖。默认使用C++11版本,推荐使用C++17版本,暂不支持C++11以下的版本


* 使用`CLion`(推荐)作为IDE的开发者,打开`CMakeLists.txt`文件作为工程,即可编译通过。本项目已经获得 [Jetbrains 开源开发许可证](https://www.jetbrains.com/zh-cn/community/opensource/#support ),感谢 Jetbrains 提供优秀的IDE,和对项目的认可


* Windows环境中,使用`Visual Studio`(2013版或以上版本)作为IDE的开发者,安装cmake之后,输入以下指令,即可生成`CGraph.sln`文件
```shell
$ git clone https://github.com/ChunelFeng/CGraph.git
Expand All @@ -23,26 +21,34 @@
$ cmake .. -G Xcode # 在 build 文件夹下,生成对应的 CGraph.xcodeproj 文件
```

* Linux环境开发者,在命令行模式下,输入以下指令,即可编译通过
* Cmake编译方式(Linux/MacOS/Windows)
```shell
$ git clone https://github.com/ChunelFeng/CGraph.git
$ cd CGraph
$ cmake . -Bbuild
$ cd build
$ make -j8
$ cd build && make -j8
$ ./tutorial/T00-HelloCGraph # 运行 T00-HelloCGraph
```

* 提供online版本的编译调试环境,点击进入页面:[CGraph env online](https://gitpod.io/#/github.com/ChunelFeng/CGraph) ,通过github账号登录。进入后,输入以下指令,即可编译通过,并查看执行结果
* Bazel编译方式(Linux/MacOS/Windows)
```shell
$ sudo apt-get install cmake -y # 安装cmake
$ ./CGraph-build.sh # 编译CGraph工程,生成的内容在同级/build/文件夹中
$ ./build/tutorial/T00-HelloCGraph # 运行第一个实例程序,并且在终端输出 Hello, CGraph.
$ git clone https://github.com/ChunelFeng/CGraph.git
$ cd CGraph
$ bazel build //tutorial/... # 编译 tutorial路径下的所有targets
$ bazel run //tutorial:T00-HelloCGraph # 运行 T00-HelloCGraph
```

* Bazel编译方式(Linux/MacOS/Windows)
* Xmake编译方式(Linux/MacOS/Windows)
```shell
$ git clone https://github.com/ChunelFeng/CGraph.git
$ cd CGraph
$ bazel build //example/... # 编译example路径下的所有targets
$ bazel build //tutorial:T01-Simple -c dbg && bazel run //tutorial:T01-Simple # 编译并运行tutorial路径下的T01-Simple
$ xmake build # 编译 tutorial 中的所有项目
$ xmake run T00-HelloCGraph # 运行 T00-HelloCGraph
```

* 提供online版本的编译调试环境,点击进入页面:[CGraph env online](https://gitpod.io/#/github.com/ChunelFeng/CGraph) ,通过github账号登录。进入后,输入以下指令,即可编译通过,并查看执行结果
```shell
$ sudo apt-get install cmake -y # 安装cmake
$ ./CGraph-build.sh # 编译CGraph工程,生成的内容在同级/build/文件夹中
$ ./build/tutorial/T00-HelloCGraph # 运 行T00-HelloCGraph,并且在终端输出 Hello, CGraph.
```
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ CVoid GDynamicEngine::parallelRunAll() {
std::vector<std::future<CStatus>> futures;
futures.reserve(total_end_size_);
for (int i = 0; i < total_end_size_; i++) {
futures.emplace_back(std::move(thread_pool_->commit([this, i] {
futures.emplace_back(thread_pool_->commit([this, i] {
return total_element_arr_[i]->fatProcessor(CFunctionType::RUN);
}, calcIndex(total_element_arr_[i]))));
}, calcIndex(total_element_arr_[i])));
}

for (auto& fut : futures) {
Expand Down
6 changes: 3 additions & 3 deletions src/UtilsCtrl/ThreadPool/Thread/UThreadPrimary.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UThreadPrimary : public UThreadBase {
is_init_ = true;
metrics_.reset();
buildStealTargets();
thread_ = std::move(std::thread(&UThreadPrimary::run, this));
thread_ = std::thread(&UThreadPrimary::run, this);
setSchedParam();
setAffinity(index_);
CGRAPH_FUNCTION_END
Expand Down Expand Up @@ -217,8 +217,8 @@ class UThreadPrimary : public UThreadBase {
* steal 的时候,先从第二个队列里偷,从而降低触碰锁的概率
*/
if (likely((*pool_threads_)[target])
&& (((*pool_threads_)[target])->secondary_queue_.trySteal(task))
|| ((*pool_threads_)[target])->primary_queue_.trySteal(task)) {
&& (((*pool_threads_)[target])->secondary_queue_.trySteal(task)
|| ((*pool_threads_)[target])->primary_queue_.trySteal(task))) {
result = true;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UThreadSecondary : public UThreadBase {

cur_ttl_ = config_->secondary_thread_ttl_;
is_init_ = true;
thread_ = std::move(std::thread(&UThreadSecondary::run, this));
thread_ = std::thread(&UThreadSecondary::run, this);
setSchedParam();
CGRAPH_FUNCTION_END
}
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CStatus UThreadPool::init() {

if (config_.monitor_enable_) {
// 默认不开启监控线程
monitor_thread_ = std::move(std::thread(&UThreadPool::monitor, this));
monitor_thread_ = std::thread(&UThreadPool::monitor, this);
}
thread_record_map_.clear();
thread_record_map_[(CSize)std::hash<std::thread::id>{}(std::this_thread::get_id())] = CGRAPH_MAIN_THREAD_ID;
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/UtilsDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CGRAPH_INTERNAL_NAMESPACE_END
using CGRAPH_READ_LOCK = std::shared_lock<std::shared_mutex>;
using CGRAPH_WRITE_LOCK = std::unique_lock<std::shared_mutex>;
#else
using CGRAPH_READ_LOCK = CGRAPH_LOCK_GUARD; // C++14不支持读写锁,使用mutex替代
using CGRAPH_READ_LOCK = CGRAPH_LOCK_GUARD; // C++11和14不支持读写锁,使用mutex替代
using CGRAPH_WRITE_LOCK = CGRAPH_LOCK_GUARD;
#endif

Expand Down
6 changes: 3 additions & 3 deletions tutorial/T07-MultiPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void tutorial_multi_pipeline() {
* 经过上述的设置,pipeline1 和 pipeline2 共享同一个线程池,去调度其中的dag逻辑
* pipeline3 没有设定,故使用自带的默认线程池完成自己的调度逻辑
*/
std::thread thd1 = std::move(std::thread(tutorial_pipeline_1, pipeline_1));
std::thread thd2 = std::move(std::thread(tutorial_pipeline_2, pipeline_2));
std::thread thd3 = std::move(std::thread(tutorial_pipeline_3, pipeline_3));
std::thread thd1 = std::thread(tutorial_pipeline_1, pipeline_1);
std::thread thd2 = std::thread(tutorial_pipeline_2, pipeline_2);
std::thread thd3 = std::thread(tutorial_pipeline_3, pipeline_3);

thd1.join();
thd2.join();
Expand Down

0 comments on commit 1ca9486

Please sign in to comment.