47 lines
918 B
C
47 lines
918 B
C
//
|
|
// Created by xajhu on 2021/7/1 0001.
|
|
//
|
|
|
|
#include "task_manager.h"
|
|
#include "misc.h"
|
|
|
|
static uv_loop_t *g_pMainTaskLoop = NULL;
|
|
static int g_taskManagerExit = FALSE;
|
|
|
|
uv_loop_t *get_task_manager(void) {
|
|
if (g_pMainTaskLoop == NULL) {
|
|
g_pMainTaskLoop = uv_default_loop();
|
|
}
|
|
|
|
return g_pMainTaskLoop;
|
|
}
|
|
|
|
void task_manager_exit() {
|
|
g_taskManagerExit = TRUE;
|
|
}
|
|
|
|
static int is_task_exit() {
|
|
return (g_taskManagerExit == TRUE);
|
|
}
|
|
|
|
void task_manager_run() {
|
|
int more;
|
|
|
|
if (g_pMainTaskLoop == NULL) {
|
|
g_pMainTaskLoop = uv_default_loop();
|
|
}
|
|
|
|
while (!is_task_exit()) {
|
|
more = uv_run(g_pMainTaskLoop, UV_RUN_ONCE);
|
|
|
|
if (more == FALSE) {
|
|
more = uv_loop_alive(g_pMainTaskLoop);
|
|
|
|
if (uv_run(g_pMainTaskLoop, UV_RUN_NOWAIT) != 0) {
|
|
more = TRUE;
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("exit..............\n");
|
|
} |