Skip to content

Commit 42a9af3

Browse files
committed
Internal - Main thread now waits for servers threads
1 parent fbf4f7c commit 42a9af3

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

src/webui.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#define WEBUI_COOKIES_LEN (32) // Authentification cookies len
108108
#define WEBUI_COOKIES_BUF (64) // Authentification cookies buffer size
109109
#define WEBUI_NATIVE_BROWSER (99) // Internal ID used to avoid terminating the user's native browser on exit
110+
#define WEBUI_SYS_CMD_TIMEOUT (1500) // Max time to wait for a system command to run
110111

111112
#ifdef WEBUI_TLS
112113
#define WEBUI_SECURE "TLS-Encryption"
@@ -471,16 +472,6 @@ typedef struct _webui_core_t {
471472
}
472473
_webui_core_t;
473474

474-
typedef struct _webui_cb_arg_t {
475-
// Event
476-
_webui_window_t* window;
477-
size_t event_type;
478-
char* element;
479-
char* data;
480-
size_t event_number;
481-
}
482-
_webui_cb_arg_t;
483-
484475
typedef struct _webui_recv_arg_t {
485476
_webui_window_t* win;
486477
void * ptr;
@@ -492,12 +483,6 @@ typedef struct _webui_recv_arg_t {
492483
}
493484
_webui_recv_arg_t;
494485

495-
typedef struct _webui_cmd_async_t {
496-
_webui_window_t* win;
497-
char* cmd;
498-
}
499-
_webui_cmd_async_t;
500-
501486
// -- Definitions ---------------------
502487
#ifdef _WIN32
503488
static const char* os_sep = "\\";
@@ -3395,7 +3380,13 @@ void webui_exit(void) {
33953380

33963381
// Let's give other threads more time to
33973382
// safely exit and finish cleaning up.
3398-
_webui_sleep(500);
3383+
for (size_t i = 0; i < 4; i++) {
3384+
_webui_sleep(500);
3385+
if (_webui.servers < 1) { // TODO: Add mutex here
3386+
// No more server threads are running
3387+
break;
3388+
}
3389+
}
33993390

34003391
// Fire the mutex condition for wait()
34013392
_webui_condition_signal(&_webui.condition_wait);
@@ -10996,7 +10987,7 @@ static int _webui_system_win32_out(const char* cmd, char ** output, bool show) {
1099610987
CloseHandle(stdout_write);
1099710988

1099810989
SetFocus(pi.hProcess);
10999-
WaitForSingleObject(pi.hProcess, INFINITE);
10990+
WaitForSingleObject(pi.hProcess, WEBUI_SYS_CMD_TIMEOUT);
1100010991
GetExitCodeProcess(pi.hProcess,&Return);
1100110992

1100210993
DWORD bytes_read;
@@ -11121,7 +11112,7 @@ static int _webui_system_win32(_webui_window_t* win, char* cmd, bool show) {
1112111112
SetFocus(pi.hProcess);
1112211113
// EnumWindows(_webui_enum_windows_proc_win32, (LPARAM)(pi.dwProcessId));
1112311114
// AssignProcessToJobObject(JobObject, pi.hProcess);
11124-
WaitForSingleObject(pi.hProcess, INFINITE);
11115+
WaitForSingleObject(pi.hProcess, WEBUI_SYS_CMD_TIMEOUT);
1112511116
GetExitCodeProcess(pi.hProcess,&Return);
1112611117
CloseHandle(pi.hProcess);
1112711118
CloseHandle(pi.hThread);

0 commit comments

Comments
 (0)