From 666aeea11509de1b7908182e0ce761556c25c93a Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Wed, 11 Mar 2020 19:22:34 +0800 Subject: [PATCH] tune implementation of MSG_ENDSESSION for THS runmode --- cleanup-code.sh | 5 +- src/kernel/desktop-comm.c | 241 ++++---------------------------------- src/kernel/desktop.c | 11 +- src/kernel/init.c | 6 - 4 files changed, 33 insertions(+), 230 deletions(-) diff --git a/cleanup-code.sh b/cleanup-code.sh index dd368f3d..840c71f7 100755 --- a/cleanup-code.sh +++ b/cleanup-code.sh @@ -169,7 +169,8 @@ tab2space() { # sed -i 's/\/GetDCInSecondarySurface/g' `grep '\' -rl include/ src/` -sed -i 's/\/checkAndGetMainWinIfMainWin/g' `grep '\' -rl include/ src/` -sed -i 's/\/checkAndGetMainWinIfWindow/g' `grep '\' -rl include/ src/` +# sed -i 's/\/checkAndGetMainWinIfMainWin/g' `grep '\' -rl include/ src/` +# sed -i 's/\/checkAndGetMainWinIfWindow/g' `grep '\' -rl include/ src/` +sed -i 's/\/getMsgQueueForThisThread/g' `grep '\' -rl include/ src/` exit 0 diff --git a/src/kernel/desktop-comm.c b/src/kernel/desktop-comm.c index 286f182b..93f58cfe 100644 --- a/src/kernel/desktop-comm.c +++ b/src/kernel/desktop-comm.c @@ -1105,32 +1105,6 @@ static void unlock_zorder_info (void) pthread_mutex_unlock (&pWin->pGCRInfo->lock); } } - -#if 0 /* deprecated code */ - static int fixed_slots [] = { ZNIDX_SCREENLOCK, ZNIDX_DOCKER, - ZNIDX_LAUNCHER }; - - /* Since 5.0.0 */ - for (slot = 0; slot < TABLESIZE(fixed_slots); slot++) { - pWin = (PMAINWIN)(nodes[fixed_slots[slot]].hwnd); - if (pWin) - pthread_mutex_unlock (&pWin->pGCRInfo->lock); - } - - slot = __mg_zorder_info->first_topmost; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin) - pthread_mutex_unlock (&pWin->pGCRInfo->lock); - } - - slot = __mg_zorder_info->first_normal; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin) - pthread_mutex_unlock (&pWin->pGCRInfo->lock); - } -#endif /* deprecated code */ } #endif /* define _MGRM_THREADS */ @@ -1612,136 +1586,6 @@ static void dskUpdateDesktopMenu (HMENU hDesktopMenu) } } -#if 0 /* deprecated code */ - /* Since 5.0.0 */ - slot = ZNIDX_SCREENLOCK; - if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) && - pWin->WinType == TYPE_MAINWIN) { - if (pWin->dwStyle & WS_VISIBLE) - mii.state = MFS_ENABLED; - else - mii.state = MFS_DISABLED; - - mii.id = id; - mii.typedata = (DWORD)pWin->spCaption; - mii.itemdata = (DWORD)pWin; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - - id++; - iPos++; - } - - /* Since 5.0.0 */ - slot = ZNIDX_DOCKER; - if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) && - pWin->WinType == TYPE_MAINWIN) { - if (pWin->dwStyle & WS_VISIBLE) - mii.state = MFS_ENABLED; - else - mii.state = MFS_DISABLED; - - mii.id = id; - mii.typedata = (DWORD)pWin->spCaption; - mii.itemdata = (DWORD)pWin; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - - id++; - iPos++; - } - - if (iPos != 0) { - mii.type = MFT_SEPARATOR; - mii.state = 0; - mii.id = 0; - mii.typedata = 0; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - iPos ++; - mii.type = MFT_STRING; - } - - slot = __mg_zorder_info->first_topmost; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin && pWin->WinType == TYPE_MAINWIN && - !(nodes[slot].flags & ZOF_IF_ALWAYSTOP)) { - if (pWin->dwStyle & WS_VISIBLE) - mii.state = MFS_ENABLED; - else - mii.state = MFS_DISABLED; - } - else { - continue; - } - - mii.id = id; - mii.typedata = (DWORD)pWin->spCaption; - mii.itemdata = (DWORD)pWin; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - - id++; - iPos++; - } - - if (iPos != 0) { - mii.type = MFT_SEPARATOR; - mii.state = 0; - mii.id = 0; - mii.typedata = 0; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - iPos ++; - mii.type = MFT_STRING; - } - - slot = __mg_zorder_info->first_normal; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin && pWin->WinType == TYPE_MAINWIN) { - if (pWin->dwStyle & WS_VISIBLE) - mii.state = MFS_ENABLED; - else - mii.state = MFS_DISABLED; - } - else { - continue; - } - - mii.id = id; - mii.typedata = (DWORD)pWin->spCaption; - mii.itemdata = (DWORD)pWin; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - - id++; - iPos++; - } - - /* Since 5.0.0 */ - slot = ZNIDX_LAUNCHER; - if ((pWin = (PMAINWIN)(nodes[slot].hwnd)) && - pWin->WinType == TYPE_MAINWIN) { - - mii.type = MFT_SEPARATOR; - mii.state = 0; - mii.id = 0; - mii.typedata = 0; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - iPos ++; - mii.type = MFT_STRING; - - if (pWin->dwStyle & WS_VISIBLE) - mii.state = MFS_ENABLED; - else - mii.state = MFS_DISABLED; - - mii.id = id; - mii.typedata = (DWORD)pWin->spCaption; - mii.itemdata = (DWORD)pWin; - InsertMenuItem(hWinMenu, iPos, TRUE, &mii); - - id++; - iPos++; - } -#endif /* deprecated code */ - nCount = GetMenuItemCount (hDesktopMenu); for (iPos = nCount; iPos > 5; iPos --) DeleteMenu (hDesktopMenu, iPos - 1, MF_BYPOSITION); @@ -1750,77 +1594,36 @@ static void dskUpdateDesktopMenu (HMENU hDesktopMenu) } #endif -static int dskDesktopCommand (HMENU hDesktopMenu, int id) +static void close_all_main_window (void) { int level, slot; + PMAINWIN pWin; ZORDERNODE* nodes = GET_ZORDERNODE(__mg_zorder_info); + for (level = 0; level < NR_ZORDER_LEVELS; level++) { + slot = __mg_zorder_info->first_in_levels[level]; + for (; slot > 0; slot = nodes[slot].next) { + pWin = (PMAINWIN)(nodes[slot].hwnd); + if (pWin && (pWin->WinType == TYPE_MAINWIN)) + SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0); + } + } +} + +static int dskDesktopCommand (HMENU hDesktopMenu, int id) +{ if (id == IDM_REDRAWBG) SendMessage (HWND_DESKTOP, MSG_ERASEDESKTOP, 0, 0); else if (id == IDM_CLOSEALLWIN) { - PMAINWIN pWin; - - for (level = 0; level < NR_ZORDER_LEVELS; level++) { - slot = __mg_zorder_info->first_in_levels[level]; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin && (pWin->WinType == TYPE_MAINWIN) -#ifndef _MGRM_THREADS - && (pWin->pHosting == __mg_dsk_win) -#else - && (pWin->pHosting == NULL) -#endif - ) - SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0); - } - } - -#if 0 /* deprecated code */ - static int fixed_slots [] = { ZNIDX_SCREENLOCK, ZNIDX_DOCKER, - ZNIDX_LAUNCHER }; - - /* Since 5.0.0 */ - for (slot = 0; slot < TABLESIZE(fixed_slots); slot++) { - pWin = (PMAINWIN)(nodes[fixed_slots[slot]].hwnd); - if (pWin && (pWin->WinType != TYPE_CONTROL) -#ifndef _MGRM_THREADS - && (pWin->pHosting == __mg_dsk_win) -#else - && (pWin->pHosting == NULL) -#endif - ) - PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0); - } - - slot = __mg_zorder_info->first_topmost; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin && (pWin->WinType != TYPE_CONTROL) -#ifndef _MGRM_THREADS - && (pWin->pHosting == __mg_dsk_win) -#else - && (pWin->pHosting == NULL) -#endif - ) - PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0); - } - - slot = __mg_zorder_info->first_normal; - for (; slot > 0; slot = nodes[slot].next) { - pWin = (PMAINWIN)(nodes[slot].hwnd); - if (pWin && (pWin->WinType == TYPE_MAINWIN) -#ifndef _MGRM_THREADS - && (pWin->pHosting == __mg_dsk_win) -#else - && (pWin->pHosting == NULL) -#endif - ) - PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0); - } -#endif /* deprecated code */ + close_all_main_window (); } else if (id == IDM_ENDSESSION) { +#ifdef _MGHAVE_VIRTUAL_WINDOW + //close_all_main_window (); + post_quit_to_all_message_threads (TRUE); +#else SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0); +#endif /* defined _MGHAVE_VIRTUAL_WINDOW */ } #ifdef _MGHAVE_MENU else if (id >= IDM_FIRSTWINDOW) { @@ -2221,10 +2024,6 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message, case MSG_ENDSESSION: __mg_screensaver_destroy (); -#ifdef _MGHAVE_VIRTUAL_WINDOW - post_quit_to_all_message_threads (); -#endif /* defined _MGHAVE_VIRTUAL_WINDOW */ - if (hDesktopDC) ReleaseDC (hDesktopDC); hDesktopDC = 0; diff --git a/src/kernel/desktop.c b/src/kernel/desktop.c index fa6424f2..52444dd6 100644 --- a/src/kernel/desktop.c +++ b/src/kernel/desktop.c @@ -4247,6 +4247,7 @@ int __mg_join_all_message_threads (void) int nr = 0; struct list_head *l, *tmp; void* res; + pthread_t th = pthread_self(); list_for_each (l, &msg_queue_list) { MSGQUEUE *msg_queue = (MSGQUEUE*)l; @@ -4256,6 +4257,9 @@ int __mg_join_all_message_threads (void) list_for_each_safe (l, tmp, &msg_queue_list) { MSGQUEUE *msg_queue = (MSGQUEUE*)l; + if (th == msg_queue->th) { + continue; + } pthread_join (msg_queue->th, &res); if (res == PTHREAD_CANCELED) { list_del (&msg_queue->list); @@ -4268,14 +4272,19 @@ int __mg_join_all_message_threads (void) return nr; } -static inline int post_quit_to_all_message_threads (void) +static inline int post_quit_to_all_message_threads (BOOL no_self) { int nr = 0; struct list_head *l; + pthread_t th = pthread_self(); list_for_each (l, &msg_queue_list) { MSGQUEUE *msg_queue = (MSGQUEUE*)l; dump_message_queue (msg_queue, __func__); + if (no_self && th == msg_queue->th) { + continue; + } + msg_queue->dwState |= QS_QUIT; POST_MSGQ (msg_queue); nr++; diff --git a/src/kernel/init.c b/src/kernel/init.c index 21a98128..a95a9cdd 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -283,11 +283,6 @@ static inline void deleteThreadInfoKey (void) { pthread_key_delete (__mg_threadinfo_key); } - -MSGQUEUE* mg_GetMsgQueueForThisThread (void) -{ - return (MSGQUEUE*) pthread_getspecific (__mg_threadinfo_key); -} */ /************************** System Initialization ****************************/ @@ -624,7 +619,6 @@ void GUIAPI TerminateGUI (int not_used) /* Since 5.0.0 */ SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0); - __mg_join_all_message_threads (); pthread_join (__mg_dsk_msg_queue->th, NULL); /* Tell event parsor quit */