Skip to content

Commit c6ff36d

Browse files
committed
rename killTask to stopTask
1 parent 220e569 commit c6ff36d

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int runTask(const T* instance, void (T::*task)(U arg), unsigned stackSize = 128
8686
```
8787
The first declaration is for function tasks - it takes a pointer to a void function taking argument of type T. The second declaration is for method tasks - it takes a class instance and a pointer to the method.
8888

89-
Returns `int` - created task id. Use this with `killTask()` to stop a task. The main `loop()` task has id 0 and cannot be stopped.
89+
Returns `int` - created task id. Use this with `stopTask()` to stop a task. The main `loop()` task has id 0 and cannot be stopped.
9090

9191
`arg` - argument to pass to the task.
9292

@@ -137,12 +137,19 @@ void loop() {
137137
```
138138
Internally the implementation of `delay()` calls `yield()` which initiates task switching, so a task that is waiting in a `delay()` is not using the CPU. You can call `yield()` whenever you want to initiate a task switch, typically when a task does something and then waits for the next cycle.
139139

140-
## killTask()
141-
If you want to stop a task use `killTask()` function which takes task id as a parameter.
140+
## stopTask()
141+
If you want to stop a task use `stopTask()` function which takes task id as a parameter.
142142
```
143-
void killTask(int id);
143+
void stopTask(int id);
144+
```
145+
A task can stop other tasks or can stop itself. In case a running task calls `stopTask()` with its own `id` the task will be removed from the list during the next task switch. When a task is stopped by using `stopTask()` or by naturally exiting the task function or method the task memory, including the stack, is freed but the task list does not shrink.
146+
147+
## currentTask()
148+
Use `currentTask()` to get the id of currenly executing task. Technically the id is the tasks's position in the list of tasks. Main `loop()` task id is 0.
149+
150+
```
151+
int currentTask()
144152
```
145-
A task can stop other tasks or can stop itself. In case a running task calls `killTask()` with its own `id` the task will be removed from the list during the next task switch. When a task is stopped by using `killTask()` or by naturally exiting the task function or method the task memory, including the stack, is freed but the task list does not shrink.
146153

147154
## SyncVar<>
148155
When two tasks access a global(shared) variable, access needs to be synchronized, meaning a task cannot be interrupted when modifying or reading the global variable value. To simplify writing code that accesses global variables use `SyncVar<>` class that wraps all operations in `noInterrupts()`/`interrupts()`.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Taskfun
2-
version=0.1.2
2+
version=0.1.3
33
author=Eugene Pistrak
44
maintainer=Eugene Pistrak
55
sentence=Preemptive multitasking for Arduino AVR and SAMD21

src/BTaskSwitcher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ void BTaskSwitcher::initialize(int tasks, int slice) {
166166

167167
using namespace Buratino;
168168

169-
void killTask(int id) {
169+
void stopTask(int id) {
170170
BTaskSwitcher::kill_task(id);
171171
}
172172

173+
int currentTask() {
174+
return BTaskSwitcher::current_task_id();
175+
}
176+
173177
void setupTasks(int numTasks, int msSlice) {
174178
BTaskSwitcher::initialize(numTasks, msSlice);
175179
}

src/BTaskSwitcher.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ template<typename T>
1818
int runTask(void (*task)(T arg), T arg, unsigned stackSize = 128 * sizeof(int), uint8_t priority = 1);
1919
template<typename T, typename U>
2020
int runTask(const T* instance, void (T::*task)(U arg), unsigned stackSize = 128 * sizeof(int), uint8_t priority = 1);
21-
void killTask(int id);
21+
void stopTask(int id);
22+
int currentTask();
2223
void setupTasks(int numTasks = 3, int msSlice = 1);
2324

2425
extern "C" void yield();
@@ -139,7 +140,8 @@ class BTaskSwitcher {
139140
friend int ::runTask(void (*task)(T arg), T arg, unsigned, uint8_t);
140141
template<typename T, typename U>
141142
friend int ::runTask(const T* instance, void (T::*task)(U arg), U arg, unsigned stackSize, uint8_t priority);
142-
friend void ::killTask(int);
143+
friend void ::stopTask(int);
144+
friend int ::currentTask();
143145
friend void ::setupTasks(int, int);
144146
friend void ::yield();
145147
template<typename T>

0 commit comments

Comments
 (0)