Skip to content

Commit b201a37

Browse files
committed
update example and logging
1 parent c46cdca commit b201a37

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

components/runqueue/example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
2323

2424
## Example Output
2525

26-
![CleanShot 2025-03-07 at 21 55 15@2x](https://github.com/user-attachments/assets/d339b4ab-0cf6-4b90-85c3-4c228e913a92)
26+
![CleanShot 2025-03-07 at 22 13 10@2x](https://github.com/user-attachments/assets/dedff19e-c40f-4451-a0e1-94e2b4a8835f)
2727

components/runqueue/example/main/runqueue_example.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,25 @@ extern "C" void app_main(void) {
7777

7878
// check the API for removing an invalid id
7979
if (runqueue.remove_function(espp::RunQueue::INVALID_ID)) {
80-
logger.error("Removed invalid id!");
80+
logger.error("Incorrectly Removed invalid id!");
8181
} else {
8282
logger.info("Correctly failed to remove invalid id!");
8383
}
8484

8585
// check the api for removing a valid but non-existent id
8686
if (runqueue.remove_function(999)) {
87-
logger.error("Removed non-existent id!");
87+
logger.error("Incorrectly Removed non-existent id!");
8888
} else {
8989
logger.info("Correctly failed to remove non-existent id!");
9090
}
9191

92+
// check the api for removing the currently running id (which should fail)
93+
if (runqueue.remove_function(runqueue.get_running_id().value())) {
94+
logger.error("Incorrectly Removed currently running id!");
95+
} else {
96+
logger.info("Correctly failed to remove currently running id!");
97+
}
98+
9299
// NOTE: in the next example (below) we'll check removing a valid ID
93100

94101
// check the API for get_queued_ids(bool include_running)

components/runqueue/src/runqueue.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ RunQueue::Id RunQueue::add_function(const Function &function, Priority priority)
5454
bool RunQueue::remove_function(RunQueue::Id id) {
5555
// return false if the id is invalid
5656
if (id == INVALID_ID) {
57+
logger_.debug("Cannot remove function with id: {}, it is invalid", id);
5758
return false;
5859
}
5960
// return false if the function is the one currently running, as we cannot
6061
// remove the running function
6162
if (id == running_id_) {
63+
logger_.debug("Cannot remove function with id: {}, it is running", id);
6264
return false;
6365
}
6466
logger_.debug("Removing function from queue with id: {}", id);
@@ -69,6 +71,7 @@ bool RunQueue::remove_function(RunQueue::Id id) {
6971
priority_function_queue_.erase(it);
7072
return true;
7173
}
74+
logger_.debug("Function with id: {} not found in queue", id);
7275
return false;
7376
}
7477

0 commit comments

Comments
 (0)