Thread and Timer converted to class (#81)
This commit is contained in:
committed by
GitHub
parent
85e26636a3
commit
854fefa1a1
@@ -37,7 +37,7 @@ Gui* gui_alloc() {
|
||||
auto* instance = static_cast<Gui*>(malloc(sizeof(Gui)));
|
||||
memset(instance, 0, sizeof(Gui));
|
||||
tt_check(instance != NULL);
|
||||
instance->thread = thread_alloc_ex(
|
||||
instance->thread = new Thread(
|
||||
"gui",
|
||||
4096, // Last known minimum was 2800 for launching desktop
|
||||
&gui_main,
|
||||
@@ -56,7 +56,7 @@ Gui* gui_alloc() {
|
||||
|
||||
void gui_free(Gui* instance) {
|
||||
tt_assert(instance != nullptr);
|
||||
thread_free(instance->thread);
|
||||
delete instance->thread;
|
||||
tt_mutex_free(instance->mutex);
|
||||
|
||||
tt_check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
@@ -80,7 +80,7 @@ void unlock() {
|
||||
|
||||
void request_draw() {
|
||||
tt_assert(gui);
|
||||
ThreadId thread_id = thread_get_id(gui->thread);
|
||||
ThreadId thread_id = gui->thread->getId();
|
||||
thread_flags_set(thread_id, GUI_THREAD_FLAG_DRAW);
|
||||
}
|
||||
|
||||
@@ -138,17 +138,17 @@ static int32_t gui_main(TT_UNUSED void* p) {
|
||||
static void start(TT_UNUSED Service& service) {
|
||||
gui = gui_alloc();
|
||||
|
||||
thread_set_priority(gui->thread, THREAD_PRIORITY_SERVICE);
|
||||
thread_start(gui->thread);
|
||||
gui->thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
gui->thread->start();
|
||||
}
|
||||
|
||||
static void stop(TT_UNUSED Service& service) {
|
||||
lock();
|
||||
|
||||
ThreadId thread_id = thread_get_id(gui->thread);
|
||||
ThreadId thread_id = gui->thread->getId();
|
||||
thread_flags_set(thread_id, GUI_THREAD_FLAG_EXIT);
|
||||
thread_join(gui->thread);
|
||||
thread_free(gui->thread);
|
||||
gui->thread->join();
|
||||
delete gui->thread;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static Loader* loader_alloc() {
|
||||
loader_singleton = new Loader();
|
||||
loader_singleton->pubsub_internal = tt_pubsub_alloc();
|
||||
loader_singleton->pubsub_external = tt_pubsub_alloc();
|
||||
loader_singleton->thread = thread_alloc_ex(
|
||||
loader_singleton->thread = new Thread(
|
||||
"loader",
|
||||
4096, // Last known minimum was 2400 for starting Hello World app
|
||||
&loader_main,
|
||||
@@ -45,7 +45,7 @@ static Loader* loader_alloc() {
|
||||
|
||||
static void loader_free() {
|
||||
tt_assert(loader_singleton != nullptr);
|
||||
thread_free(loader_singleton->thread);
|
||||
delete loader_singleton->thread;
|
||||
tt_pubsub_free(loader_singleton->pubsub_internal);
|
||||
tt_pubsub_free(loader_singleton->pubsub_external);
|
||||
tt_mutex_free(loader_singleton->mutex);
|
||||
@@ -334,18 +334,21 @@ static void loader_start(TT_UNUSED Service& service) {
|
||||
tt_check(loader_singleton == nullptr);
|
||||
loader_singleton = loader_alloc();
|
||||
|
||||
thread_set_priority(loader_singleton->thread, THREAD_PRIORITY_SERVICE);
|
||||
thread_start(loader_singleton->thread);
|
||||
loader_singleton->thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
loader_singleton->thread->start();
|
||||
}
|
||||
|
||||
static void loader_stop(TT_UNUSED Service& service) {
|
||||
tt_check(loader_singleton != nullptr);
|
||||
|
||||
// Send stop signal to thread and wait for thread to finish
|
||||
loader_lock();
|
||||
LoaderMessage message(LoaderMessageTypeServiceStop);
|
||||
loader_singleton->queue.put(&message, TtWaitForever);
|
||||
thread_join(loader_singleton->thread);
|
||||
thread_free(loader_singleton->thread);
|
||||
loader_unlock();
|
||||
|
||||
loader_singleton->thread->join();
|
||||
delete loader_singleton->thread;
|
||||
|
||||
loader_free();
|
||||
loader_singleton = nullptr;
|
||||
|
||||
@@ -126,13 +126,13 @@ static int32_t screenshot_task(void* context) {
|
||||
static void task_start(ScreenshotTaskData* data) {
|
||||
task_lock(data);
|
||||
tt_check(data->thread == NULL);
|
||||
data->thread = thread_alloc_ex(
|
||||
data->thread = new Thread(
|
||||
"screenshot",
|
||||
8192,
|
||||
&screenshot_task,
|
||||
data
|
||||
);
|
||||
thread_start(data->thread);
|
||||
data->thread->start();
|
||||
task_unlock(data);
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ void task_stop(ScreenshotTask* task) {
|
||||
data->interrupted = true;
|
||||
task_unlock(data);
|
||||
|
||||
thread_join(data->thread);
|
||||
data->thread->join();
|
||||
|
||||
task_lock(data);
|
||||
thread_free(data->thread);
|
||||
delete data->thread;
|
||||
data->thread = nullptr;
|
||||
task_unlock(data);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static ServiceData* service_data_alloc() {
|
||||
auto* data = static_cast<ServiceData*>(malloc(sizeof(ServiceData)));
|
||||
*data = (ServiceData) {
|
||||
.mutex = tt_mutex_alloc(MutexTypeNormal),
|
||||
.thread = thread_alloc(),
|
||||
.thread = new Thread(),
|
||||
.service_interrupted = false,
|
||||
.wifi_icon_id = lvgl::statusbar_icon_add(nullptr),
|
||||
.wifi_last_icon = nullptr,
|
||||
@@ -156,7 +156,7 @@ static ServiceData* service_data_alloc() {
|
||||
|
||||
static void service_data_free(ServiceData* data) {
|
||||
tt_mutex_free(data->mutex);
|
||||
thread_free(data->thread);
|
||||
delete data->thread;
|
||||
lvgl::statusbar_icon_remove(data->wifi_icon_id);
|
||||
lvgl::statusbar_icon_remove(data->sdcard_icon_id);
|
||||
lvgl::statusbar_icon_remove(data->power_icon_id);
|
||||
@@ -188,11 +188,10 @@ static void on_start(Service& service) {
|
||||
ServiceData* data = service_data_alloc();
|
||||
service.setData(data);
|
||||
|
||||
thread_set_callback(data->thread, service_main);
|
||||
thread_set_current_priority(ThreadPriorityLow);
|
||||
thread_set_stack_size(data->thread, 3000);
|
||||
thread_set_context(data->thread, data);
|
||||
thread_start(data->thread);
|
||||
data->thread->setCallback(service_main, data);
|
||||
data->thread->setPriority(Thread::PriorityLow);
|
||||
data->thread->setStackSize(3000);
|
||||
data->thread->start();
|
||||
}
|
||||
|
||||
static void on_stop(Service& service) {
|
||||
@@ -203,7 +202,7 @@ static void on_stop(Service& service) {
|
||||
data->service_interrupted = true;
|
||||
service_data_unlock(data);
|
||||
tt_mutex_release(data->mutex);
|
||||
thread_join(data->thread);
|
||||
data->thread->join();
|
||||
|
||||
service_data_free(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user