Skip to content

Commit 5bcaeda

Browse files
Merge pull request #7 from Awesome-Embedded-Learning-Studio/feat/vol9-open-source-code-notes
feat: vol9 enabled for chrome code design first try: OnceCallback
2 parents dc7e3ee + 580b865 commit 5bcaeda

44 files changed

Lines changed: 7191 additions & 21 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-examples.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,25 @@ jobs:
2727
- name: Install build tools
2828
run: |
2929
sudo apt-get update
30-
sudo apt-get install -y cmake g++ ninja-build
30+
sudo apt-get install -y cmake g++-14 ninja-build ccache
31+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
32+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
33+
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-14 100
34+
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-14 100
35+
36+
- name: Cache ccache
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.cache/ccache
40+
key: ccache-host-${{ github.run_id }}
41+
restore-keys: |
42+
ccache-host-
3143
3244
- name: Build host examples
33-
run: python3 scripts/build_examples.py --host
45+
run: |
46+
export CCACHE_DIR="$HOME/.cache/ccache"
47+
mkdir -p "$CCACHE_DIR"
48+
python3 scripts/build_examples.py --host
3449
3550
build-stm32:
3651
name: STM32 Examples
@@ -45,7 +60,18 @@ jobs:
4560
- name: Install build tools
4661
run: |
4762
sudo apt-get update
48-
sudo apt-get install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi ninja-build
63+
sudo apt-get install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi ninja-build ccache
64+
65+
- name: Cache ccache
66+
uses: actions/cache@v4
67+
with:
68+
path: ~/.cache/ccache
69+
key: ccache-stm32-${{ github.run_id }}
70+
restore-keys: |
71+
ccache-stm32-
4972
5073
- name: Build STM32 examples
51-
run: python3 scripts/build_examples.py --stm32
74+
run: |
75+
export CCACHE_DIR="$HOME/.cache/ccache"
76+
mkdir -p "$CCACHE_DIR"
77+
python3 scripts/build_examples.py --stm32

.gitignore

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ build/
77
**/build/
88
*.build/
99

10-
# CMake
11-
CMakeCache.txt
12-
CMakeFiles/
13-
cmake_install.cmake
14-
Makefile
15-
*.cmake
16-
!CMakeLists.txt
17-
18-
# Compiled binaries
19-
*.o
20-
*.a
21-
*.so
22-
*.exe
23-
*.out
24-
2510
# MkDocs build output
2611
site/
2712

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
## 特色亮点
1818

19-
- **系统化学习路径** -- 8 卷从入门到高级,每卷有明确前置知识,循序渐进
19+
- **系统化学习路径** -- 9 卷从入门到高级,每卷有明确前置知识,循序渐进
2020
- **实战驱动** -- 每个概念配合可编译的 CMake 项目,而非孤立代码片段
2121
- **多平台覆盖** -- STM32 / ESP32 / RP2040 嵌入式实战,不止于桌面端
2222
- **标签导航** -- 按主题、C++ 标准、难度、平台等维度检索文章
@@ -32,6 +32,8 @@ graph LR
3232
V2 --> V3["卷三 标准库"] & V4["卷四 高级"] & V5["卷五 并发"] & V6["卷六 性能"] & V7["卷七 工程"]
3333
V2 --> V8["卷八 领域应用"]
3434
V8 --> E["嵌入式"] & N["网络"] & G["GUI"] & D["数据"] & A["算法"]
35+
V2 --> V9["卷九 开源项目学习"]
36+
V9 --> OC["Chrome 代码研读"] & OS["其他开源项目"]
3537
```
3638

3739
### 教程结构
@@ -46,6 +48,7 @@ graph LR
4648
|| [性能优化](documents/vol6-performance/) -- CPU 缓存、SIMD、汇编阅读、基准测试 | 18-22 | advanced | 规划中 |
4749
|| [软件工程实践](documents/vol7-engineering/) -- CMake、测试、静态分析、DevOps | 30-35 | intermediate | 规划中 |
4850
|| [领域应用](documents/vol8-domains/) -- 嵌入式 / 网络 / GUI / 数据存储 / 算法 | 80-100 | intermediate | 编写中 |
51+
|| [开源项目学习](documents/vol9-open-source-project-learn/) -- 开源项目代码研读 | 13+ | intermediate | 编写中 |
4952
| - | [编译与链接深入](documents/compilation/) -- 预处理、汇编、链接、调试符号 | 10+ | intermediate | 已完成 |
5053
| - | [贯穿式实战项目](documents/projects/) -- 手写 STL、迷你 HTTP 服务器、嵌入式 OS | - | advanced | 规划中 |
5154

@@ -151,6 +154,7 @@ Tutorial_AwesomeModernCPP/
151154
│ │ ├── gui-graphics/ # GUI 与图形
152155
│ │ ├── data-storage/ # 数据存储
153156
│ │ └── algorithms/ # 算法与数据结构
157+
│ ├── vol9-open-source-project-learn/ # 卷九:开源项目学习
154158
│ ├── compilation/ # 编译与链接深入
155159
│ ├── projects/ # 贯穿式实战项目
156160
│ └── index.md # 教程首页
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(ChromeBase LANGUAGES CXX)
4+
set(CMAKE_CXX_STANDARD 23)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
7+
include(cmake/CPM.cmake)
8+
9+
message("Processing the OnceCallback")
10+
add_subdirectory(once_callback)
11+
12+
# Tests
13+
enable_testing()
14+
add_subdirectory(test)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
#include <atomic>
3+
#include <memory>
4+
5+
namespace tamcpp::chrome {
6+
class CancelableToken {
7+
struct Flag {
8+
std::atomic<bool> valid{true};
9+
};
10+
// All token should share a simple flags
11+
std::shared_ptr<Flag> flag_;
12+
13+
public:
14+
CancelableToken() : flag_(std::make_shared<Flag>()) {}
15+
void invalidate() { flag_->valid.store(false, std::memory_order_release); }
16+
bool is_valid() const { return flag_->valid.load(std::memory_order_acquire); }
17+
};
18+
} // namespace tamcpp::chrome

0 commit comments

Comments
 (0)