improve main loop destroy

This commit is contained in:
lixianjing 2024-07-17 10:20:12 +08:00
parent 79b88ad629
commit 6b2cd36b0e
3 changed files with 35 additions and 30 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
2024/07/17
* 设置main_loop默认销毁函数(感谢兆坤提供补丁)
2024/07/12
* 触发 EVT\_POINTER\_DOWN\_ABORT 事件可能会闪回去的问题(感谢颖健提供补丁)

View File

@ -127,6 +127,21 @@ static event_source_manager_t* main_loop_console_get_event_source_manager(main_l
return loop->event_source_manager;
}
ret_t main_loop_console_reset(main_loop_console_t* loop) {
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
event_source_manager_destroy(loop->event_source_manager);
event_queue_destroy(loop->queue);
if (loop->mutex != NULL) {
tk_mutex_destroy(loop->mutex);
}
memset(loop, 0x00, sizeof(main_loop_console_t));
return RET_OK;
}
main_loop_console_t* main_loop_console_init(void) {
event_source_t* idle_source = NULL;
event_source_t* timer_source = NULL;
@ -140,6 +155,7 @@ main_loop_console_t* main_loop_console_init(void) {
loop->base.run = main_loop_console_run;
loop->base.step = main_loop_console_step;
loop->base.destroy = (main_loop_destroy_t*)main_loop_console_reset;
loop->mutex = tk_mutex_create();
return_value_if_fail(loop->mutex != NULL, NULL);
@ -161,18 +177,3 @@ main_loop_console_t* main_loop_console_init(void) {
return loop;
}
ret_t main_loop_console_reset(main_loop_console_t* loop) {
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
event_source_manager_destroy(loop->event_source_manager);
event_queue_destroy(loop->queue);
if (loop->mutex != NULL) {
tk_mutex_destroy(loop->mutex);
}
memset(loop, 0x00, sizeof(main_loop_console_t));
return RET_OK;
}

View File

@ -262,6 +262,21 @@ static event_source_manager_t* main_loop_simple_get_event_source_manager(main_lo
return loop->event_source_manager;
}
ret_t main_loop_simple_reset(main_loop_simple_t* loop) {
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
event_source_manager_destroy(loop->event_source_manager);
event_queue_destroy(loop->queue);
if (loop->mutex != NULL) {
tk_mutex_destroy(loop->mutex);
}
memset(loop, 0x00, sizeof(main_loop_simple_t));
return RET_OK;
}
main_loop_simple_t* main_loop_simple_init(int w, int h, main_loop_queue_event_t queue_event,
main_loop_recv_event_t recv_event) {
event_source_t* idle_source = NULL;
@ -281,6 +296,7 @@ main_loop_simple_t* main_loop_simple_init(int w, int h, main_loop_queue_event_t
loop->base.run = main_loop_simple_run;
loop->base.step = main_loop_simple_step;
loop->base.destroy = (main_loop_destroy_t*)main_loop_simple_reset;
if (recv_event != NULL && queue_event != NULL) {
loop->base.recv_event = recv_event;
@ -308,18 +324,3 @@ main_loop_simple_t* main_loop_simple_init(int w, int h, main_loop_queue_event_t
return loop;
}
ret_t main_loop_simple_reset(main_loop_simple_t* loop) {
return_value_if_fail(loop != NULL, RET_BAD_PARAMS);
event_source_manager_destroy(loop->event_source_manager);
event_queue_destroy(loop->queue);
if (loop->mutex != NULL) {
tk_mutex_destroy(loop->mutex);
}
memset(loop, 0x00, sizeof(main_loop_simple_t));
return RET_OK;
}