diff --git a/native/jni/core/logging.cpp b/native/jni/core/logging.cpp index 75a49d11e..3075113e7 100644 --- a/native/jni/core/logging.cpp +++ b/native/jni/core/logging.cpp @@ -37,7 +37,9 @@ void setup_logfile(bool reset) { // Maximum message length for pipes to transfer atomically #define MAX_MSG_LEN (PIPE_BUF - sizeof(log_meta)) -static void logfile_writer(int pipefd) { +static void *logfile_writer(void *arg) { + int pipefd = (long) arg; + run_finally close_pipes([=] { // Close up all logging pipes when thread dies close(pipefd); @@ -62,7 +64,7 @@ static void logfile_writer(int pipefd) { for (;;) { // Read meta data if (read(pipefd, &meta, sizeof(meta)) != sizeof(meta)) - return; + return nullptr; if (meta.prio < 0) { if (!switched) { @@ -75,7 +77,7 @@ static void logfile_writer(int pipefd) { rename(LOGFILE, LOGFILE ".bak"); int fd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644); if (fd < 0) - return; + return nullptr; if (tmp.data) write(fd, tmp.data, tmp.len); @@ -87,7 +89,7 @@ static void logfile_writer(int pipefd) { // Read message if (read(pipefd, buf, meta.len) != meta.len) - return; + return nullptr; timeval tv; tm tm; @@ -186,6 +188,7 @@ void start_log_daemon() { int fds[2]; if (pipe2(fds, O_CLOEXEC) == 0) { logd_fd = fds[1]; - exec_task([fd = fds[0]] { logfile_writer(fd); }); + long fd = fds[0]; + new_daemon_thread(logfile_writer, (void *) fd); } } diff --git a/native/jni/core/thread.cpp b/native/jni/core/thread.cpp index fca12180a..667d66a7b 100644 --- a/native/jni/core/thread.cpp +++ b/native/jni/core/thread.cpp @@ -70,7 +70,7 @@ void exec_task(function &&task) { pending_task.swap(task); if (available_threads == 0) { ++active_threads; - long is_core_pool = active_threads > CORE_POOL_SIZE; + long is_core_pool = active_threads <= CORE_POOL_SIZE; new_daemon_thread(thread_pool_loop, (void *) is_core_pool); } else { pthread_cond_signal(&send_task);