Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ jobs:
target: esp32
- path: 'components/thermistor/example'
target: esp32
- path: 'components/thread_pool/example'
target: esp32
- path: 'components/timer/example'
target: esp32
- path: 'components/touch/example'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/upload_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
components/tabulate
components/task
components/thermistor
components/thread_pool
components/timer
Comment thread
guo-max marked this conversation as resolved.
components/touch
components/tla2528
Expand Down
4 changes: 4 additions & 0 deletions components/thread_pool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES base_component task)
Comment thread
guo-max marked this conversation as resolved.
16 changes: 16 additions & 0 deletions components/thread_pool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Thread Pool Component

[![Badge](https://components.espressif.com/components/espp/thread_pool/badge.svg)](https://components.espressif.com/components/espp/thread_pool)

The `ThreadPool` component provides a reusable pool of worker tasks for executing queued jobs asynchronously.

It is implemented with `espp::Task` workers and `std::condition_variable` synchronization.

## Features

- Configurable worker count
- Bounded or unbounded queue
- Optional blocking submit mode for backpressure
- Manual `start()` / `stop()` control; `start()` returns `true` if all workers launched successfully (or the pool was already running), `false` if any worker failed to start and the pool was rolled back to stopped state
- Graceful stop (stops workers; queued jobs may not be executed)
Comment thread
guo-max marked this conversation as resolved.
- Thread-safe stats for submitted / executed / rejected jobs
22 changes: 22 additions & 0 deletions components/thread_pool/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.20)

set(CMAKE_CXX_STANDARD 20)

set(ENV{IDF_COMPONENT_MANAGER} "0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# add the component directories that we want to use
set(EXTRA_COMPONENT_DIRS
"../../../components/"
)

set(
COMPONENTS
"main esptool_py thread_pool"
CACHE STRING
"List of components to include"
)

project(thread_pool_example)
42 changes: 42 additions & 0 deletions components/thread_pool/example/README.md
Comment thread
guo-max marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Thread Pool Example

This example is a self-contained test suite that exercises the full public API
of `espp::ThreadPool` across a range of usage patterns, from basic single-pool
operation to more advanced concurrent and multi-pool scenarios.

| # | Test | APIs covered |
|---|---|---|
| 1 | Lifecycle | `start()`, `stop()`, `is_running()`, `worker_count()` |
| 2 | Normal dispatch | `submit()`, `queue_size()`, `stats()` |
| 3 | Bounded-queue rejection | `try_submit()` with deterministic barrier |
| 4 | Blocking submit | `submit()` with `block_on_submit_when_full` |
| 5 | Post-stop rejection | `submit()` after `stop()` |
| 6 | Concurrent lifecycle | multi-thread `start()` / `stop()` stress |
| 7 | Concurrent submission | multi-thread `submit()` + `try_submit()` |
| 8 | Chained pools | a job in `pool_a` submitting work into `pool_b` |
| 9 | Self-submit | a running job submitting back to its own pool |

Each test logs individual `PASS` / `FAIL` results inline. At the end of the run
a summary is printed:

```
==================== Results ====================
PASS lifecycle: start/stop/is_running/worker_count
PASS submit: normal dispatch + queue_size + stats
...
=================================================
9/9 tests passed
All tests passed!
```

The final summary line (`N/N tests passed` / `N test(s) FAILED`) is the key
indicator of overall correctness and is suitable for CI log parsing.

## Build

From this directory, run:

```bash
idf.py set-target esp32
idf.py build flash monitor
```
2 changes: 2 additions & 0 deletions components/thread_pool/example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS ".")
Loading
Loading