Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CyanLight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fxk8y
CyanLight
Commits
f8f27901
Commit
f8f27901
authored
3 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Adding functional task wrapper
parent
37d06b23
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CLC-qthing/SiliconTorch/LambdaTask.cpp
+52
-0
52 additions, 0 deletions
CLC-qthing/SiliconTorch/LambdaTask.cpp
CLC-qthing/SiliconTorch/LambdaTask.hpp
+37
-0
37 additions, 0 deletions
CLC-qthing/SiliconTorch/LambdaTask.hpp
with
89 additions
and
0 deletions
CLC-qthing/SiliconTorch/LambdaTask.cpp
0 → 100644
+
52
−
0
View file @
f8f27901
#include
"LambdaTask.hpp"
#include
"freertos/FreeRTOS.h"
#include
"freertos/task.h"
static
void
taskWrapper
(
void
*
body
)
{
std
::
function
<
void
()
>*
f
=
(
std
::
function
<
void
()
>
*
)
body
;
(
*
f
)();
}
static
uint16_t
taskID
=
0
;
static
uint16_t
nextID
()
{
return
taskID
++
;
// TODO: increment thread-safe!
}
SiliconTorch
::
Util
::
LambdaTask
::
LambdaTask
(
SiliconTorch
::
Util
::
Function0
body
)
:
body
(
body
)
{
char
taskName
[
32
];
sprintf
(
taskName
,
"LambdaTask[%d]"
,
nextID
());
// TODO: allow other niceness than one
// TODO: allow pinning to other cores than app CPU
uint8_t
priority
=
1
;
std
::
function
<
void
()
>
_body
=
[
&
]()
{
this
->
body
();
this
->
_running
=
false
;
// TODO: thread safe??? needed?
vTaskDelete
(
NULL
);
};
std
::
function
<
void
()
>*
__body
=
new
std
::
function
<
void
()
>
(
_body
);
xTaskCreatePinnedToCore
(
taskWrapper
,
taskName
,
8192
,
(
void
*
)
__body
,
priority
,
&
taskHandle
,
1
);
}
TaskHandle_t
SiliconTorch
::
Util
::
LambdaTask
::
getHandle
()
{
return
taskHandle
;
}
bool
SiliconTorch
::
Util
::
LambdaTask
::
running
()
{
return
_running
;
}
// TODO: thread safe??? needed?
void
SiliconTorch
::
Util
::
LambdaTask
::
kill
()
{
if
(
_running
)
vTaskDelete
(
getHandle
());
_running
=
false
;
}
This diff is collapsed.
Click to expand it.
CLC-qthing/SiliconTorch/LambdaTask.hpp
0 → 100644
+
37
−
0
View file @
f8f27901
#pragma once
// C++ system level
#include
<functional>
// ESP32 specific
#include
"freertos/FreeRTOS.h"
#include
"freertos/task.h"
namespace
SiliconTorch
{
namespace
Util
{
typedef
std
::
function
<
void
()
>
Function0
;
// TODO: add destructor which deletes the task!
class
LambdaTask
{
public:
LambdaTask
(
Function0
body
);
void
kill
();
bool
running
();
TaskHandle_t
getHandle
();
private:
bool
_running
=
true
;
Function0
body
;
TaskHandle_t
taskHandle
;
};
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment