donot use quiting stage

This commit is contained in:
Vincent Wei
2020-02-22 19:35:11 +08:00
parent d36be5fb7f
commit 2b55d9d0e5
8 changed files with 82 additions and 100 deletions

View File

@@ -53,10 +53,6 @@
/* only for MiniGUI-Threads or MiniGUI-Standalone */
#include "desktop.c"
#ifdef _MGRM_THREADS
extern int __mg_enter_terminategui;
#endif
#if defined(_MGRM_THREADS) || defined(_MGRM_STANDALONE)
static LRESULT DesktopWinProc (HWND hWnd, UINT msg,
@@ -1894,7 +1890,7 @@ static int dskDesktopCommand (HMENU hDesktopMenu, int id)
&& (pWin->pHosting == NULL)
#endif
)
PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0);
}
}
@@ -1943,7 +1939,7 @@ static int dskDesktopCommand (HMENU hDesktopMenu, int id)
#endif /* deprecated code */
}
else if (id == IDM_ENDSESSION) {
PostMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
}
#ifdef _MGHAVE_MENU
else if (id >= IDM_FIRSTWINDOW) {
@@ -2212,6 +2208,8 @@ void GUIAPI DesktopUpdateAllWindow(void)
SendMessage(HWND_DESKTOP, MSG_PAINT, 0, 0);
}
#if 0 /* deprecated code */
/* Since 5.0.0, we donot use quiting stage */
#ifndef _MG_ENABLE_SCREENSAVER
# define HAS_NO_MAINWINDOW() \
((__mg_zorder_info->nr_normals + __mg_zorder_info->nr_topmosts) == 0)
@@ -2220,6 +2218,7 @@ void GUIAPI DesktopUpdateAllWindow(void)
# define HAS_NO_MAINWINDOW() \
((__mg_zorder_info->nr_normals + __mg_zorder_info->nr_topmosts) == 1)
#endif
#endif /* deprecated code */
static LRESULT DesktopWinProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
@@ -2356,32 +2355,27 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
break;
case MSG_ENDSESSION:
if (
HAS_NO_MAINWINDOW()
#ifdef _MGRM_THREADS
&& __mg_enter_terminategui
#endif
) {
__mg_screensaver_destroy();
__mg_screensaver_destroy ();
if (hDesktopDC)
ReleaseDC (hDesktopDC);
hDesktopDC = 0;
#ifdef _MGHAVE_VIRTUAL_WINDOW
post_quit_to_all_message_threads ();
#endif /* defined _MGHAVE_VIRTUAL_WINDOW */
if (hDesktopDC)
ReleaseDC (hDesktopDC);
hDesktopDC = 0;
#ifdef _MGHAVE_MENU
if (sg_DesktopMenu) {
DestroyMenu (sg_DesktopMenu);
sg_DesktopMenu = 0;
}
#endif
if(dsk_ops->deinit)
dsk_ops->deinit(dt_context);
PostQuitMessage (HWND_DESKTOP);
return 1;
if (sg_DesktopMenu) {
DestroyMenu (sg_DesktopMenu);
sg_DesktopMenu = 0;
}
break;
#endif
if (dsk_ops->deinit)
dsk_ops->deinit (dt_context);
PostQuitMessage (HWND_DESKTOP);
return 1;
case MSG_ERASEDESKTOP:
if (dsk_ops->paint_desktop)
@@ -2531,32 +2525,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
}
break;
#ifdef _MGRM_THREADS
if (__mg_quiting_stage < 0) {
post_quit_to_all_message_threads ();
if (__mg_quiting_stage > _MG_QUITING_STAGE_FORCE &&
__mg_quiting_stage <= _MG_QUITING_STAGE_START) {
__mg_quiting_stage--;
}
else if (__mg_quiting_stage <= _MG_QUITING_STAGE_FORCE) {
/* printf("force to quit !!!\n"); */
}
if (__mg_quiting_stage > _MG_QUITING_STAGE_DESKTOP
&& HAS_NO_MAINWINDOW()
&& __mg_enter_terminategui) {
/* Let Desktop wait for MiniGUIMain() */
__mg_quiting_stage = _MG_QUITING_STAGE_DESKTOP;
}
else if (__mg_quiting_stage <= _MG_QUITING_STAGE_DESKTOP) {
PostMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
}
}
#endif /* _MGRM_THREADS */
#if 0 /* use post_quit_to_all_message_threads instead */
#if 0 /* Since 5.0.0, we use post_quit_to_all_message_threads instead */
#ifndef _MGRM_THREADS
static DWORD sg_old_counter = 0;
@@ -2568,6 +2537,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
#else /* not defined _MGRM_THREADS */
if (__mg_quiting_stage < 0) {
extern int __mg_enter_terminategui;
int level, slot;
PMSGQUEUE pMsgQueue;
ZORDERNODE* nodes = GET_ZORDERNODE(__mg_zorder_info);

View File

@@ -4685,9 +4685,10 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
case MSG_BROADCASTMSG:
return dskBroadcastMessage ((PMSG)lParam);
case MSG_TIMER:
#if 0 /* deprecated code */
/* Since 5.0.0, the desktop only handles caret blinking in MSG_TIMER
message, and the interval for this MSG_TIMER changes to about 0.05s. */
case MSG_TIMER:
if (__mg_quiting_stage < 0) {
if (__mg_quiting_stage > _MG_QUITING_STAGE_FORCE &&
__mg_quiting_stage <= _MG_QUITING_STAGE_START) {
@@ -4707,6 +4708,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message,
PostMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
}
}
#endif /* deprecated code */
dskOnTimer ();
break;

View File

@@ -74,9 +74,6 @@
#include "devfont.h"
/******************************* global data *********************************/
/* system threads */
pthread_t __mg_desktop, __mg_parsor, __mg_timer;
/* pointer to desktop message queue */
PMSGQUEUE __mg_dsk_msg_queue;
@@ -195,8 +192,6 @@ void* __kernel_desktop_main (void* data)
mg_FreeMsgQueueForThisThread ();
__mg_dsk_msg_queue = NULL;
__mg_quiting_stage = _MG_QUITING_STAGE_EVENT;
return NULL;
}

View File

@@ -4841,6 +4841,7 @@ static inline int post_quit_to_all_message_threads (void)
list_for_each (l, &msg_queue_list) {
MSGQUEUE *msg_queue = (MSGQUEUE*)l;
dump_message_queue (msg_queue, __func__);
msg_queue->dwState |= QS_QUIT;
POST_MSGQ (msg_queue);
nr++;
}

View File

@@ -112,8 +112,6 @@ int InitGUI (int argc, const char* agr[])
char mode [LEN_VIDEO_MODE + 1];
int step = 1;
__mg_quiting_stage = _MG_QUITING_STAGE_RUNNING;
#ifndef __NOUNIX__
tcgetattr (0, &savedtermio);
#endif
@@ -260,7 +258,8 @@ failure:
return FALSE;
}
#define err_message(step, message) _ERR_PRINTF ("KERNEL>InitGUI (step %d): %s\n", step, message)
#define err_message(step, message) \
_ERR_PRINTF ("KERNEL>InitGUI (step %d): %s\n", step, message)
static void sig_handler (int v)
{
@@ -270,8 +269,8 @@ static void sig_handler (int v)
else if (v == SIGINT) {
_exit(1); /* force to quit */
}
else if (__mg_quiting_stage > 0) {
ExitGUISafely(-1);
else if (v == SIGTERM) {
ExitGUISafely (-1);
}
else {
exit(1); /* force to quit */
@@ -314,8 +313,6 @@ int InitGUI (int argc, const char* agr[])
char mode [LEN_VIDEO_MODE + 1];
int step = 1;
__mg_quiting_stage = _MG_QUITING_STAGE_RUNNING;
#ifdef _MGRM_PROCESSES
const char* name;

View File

@@ -81,10 +81,13 @@
#include "clipboard.h"
#include "license.h"
int __mg_quiting_stage;
#ifdef _MGRM_THREADS
int __mg_enter_terminategui;
// deprecated since 5.0.0
// int __mg_enter_terminategui;
static int _is_minigui_running;
static pthread_t _th_parsor;
/******************************* extern data *********************************/
extern void* __kernel_desktop_main (void* data);
@@ -195,7 +198,7 @@ static void* EventLoop (void* data)
sem_post ((sem_t*)data);
while (__mg_quiting_stage > _MG_QUITING_STAGE_EVENT) {
while (_is_minigui_running) {
EXTRA_INPUT_EVENT extra;
#if 0 /* deprecated code */
@@ -289,6 +292,7 @@ MSGQUEUE* mg_GetMsgQueueForThisThread (void)
/************************** System Initialization ****************************/
static BOOL SystemThreads(void)
{
pthread_t th;
sem_t wait;
sem_init (&wait, 0, 0);
@@ -305,11 +309,11 @@ static BOOL SystemThreads(void)
pthread_attr_t new_attr;
pthread_attr_init (&new_attr);
pthread_attr_setstacksize (&new_attr, 16 * 1024);
pthread_create (&__mg_desktop, &new_attr, __kernel_desktop_main, &wait);
pthread_create (&th, &new_attr, __kernel_desktop_main, &wait);
pthread_attr_destroy (&new_attr);
}
#else
pthread_create (&__mg_desktop, NULL, __kernel_desktop_main, &wait);
pthread_create (&th, NULL, __kernel_desktop_main, &wait);
#endif
sem_wait (&wait);
@@ -329,8 +333,8 @@ static BOOL SystemThreads(void)
// this thread also parse low level event and translate it to message,
// then post the message to the approriate message queue.
// this thread should also have a higher priority.
pthread_create (&__mg_parsor, NULL, EventLoop, &wait);
pthread_detach (__mg_parsor);
pthread_create (&_th_parsor, NULL, EventLoop, &wait);
pthread_detach (_th_parsor);
sem_wait (&wait);
sem_destroy (&wait);
@@ -358,7 +362,7 @@ static void sig_handler (int v)
else if (v == SIGINT) {
_exit(1); /* force to quit */
}
else if (__mg_quiting_stage > 0) {
else if (v == SIGTERM) {
ExitGUISafely(-1);
}
else {
@@ -400,10 +404,6 @@ int GUIAPI InitGUI (int args, const char *agr[])
char engine [LEN_ENGINE_NAME + 1];
char mode [LEN_VIDEO_MODE + 1];
int step = 0;
__mg_quiting_stage = _MG_QUITING_STAGE_RUNNING;
__mg_enter_terminategui = 0;
MSGQUEUE* msg_queue;
#ifdef HAVE_SETLOCALE
@@ -568,6 +568,8 @@ int GUIAPI InitGUI (int args, const char *agr[])
__mg_splash_delay();
_is_minigui_running = 1;
step++;
if (!SystemThreads()) {
_ERR_PRINTF ("KERNEL>InitGUI: failed to init system threads!\n");
@@ -600,7 +602,6 @@ int GUIAPI InitGUI (int args, const char *agr[])
SetCursorPos (g_rcScr.right >> 1, g_rcScr.bottom >> 1);
mg_TerminateMgEtc ();
return 0;
failure:
@@ -614,19 +615,16 @@ failure1:
void GUIAPI TerminateGUI (int not_used)
{
__mg_enter_terminategui = 1;
mg_TerminateTimer (FALSE);
/* Since 5.0.0 */
SendNotifyMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
__mg_join_all_message_threads ();
pthread_join (__mg_dsk_msg_queue->th, NULL);
__mg_quiting_stage = _MG_QUITING_STAGE_TIMER;
pthread_join (__mg_desktop, NULL);
/* DesktopProc() will set __mg_quiting_stage to _MG_QUITING_STAGE_EVENT */
pthread_join (__mg_parsor, NULL);
/* Tell event parsor quit */
_is_minigui_running = 0;
pthread_join (_th_parsor, NULL);
__mg_license_destroy();
@@ -674,19 +672,29 @@ void GUIAPI TerminateGUI (int not_used)
#endif /* _MGRM_THREADS */
/* XXX: We need a better policy to exit MiniGUI safely by giving a chance
for all windows to save data. */
void GUIAPI ExitGUISafely (int exitcode)
{
#ifdef _MGRM_PROCESSES
if (mgIsServer)
#endif
{
# define IDM_CLOSEALLWIN (MINID_RESERVED + 1) /* see src/kernel/desktop-*.c */
SendNotifyMessage(HWND_DESKTOP, MSG_COMMAND, IDM_CLOSEALLWIN, 0);
SendNotifyMessage(HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
/* see src/kernel/desktop-*.c */
# define IDM_CLOSEALLWIN (MINID_RESERVED + 1)
if (__mg_quiting_stage > 0) {
__mg_quiting_stage = _MG_QUITING_STAGE_START;
}
SendNotifyMessage (HWND_DESKTOP, MSG_COMMAND, IDM_CLOSEALLWIN, 0);
#ifdef _MGHAVE_VIRTUAL_WINDOW
__mg_join_all_message_threads ();
SendMessage (HWND_DESKTOP, MSG_ENDSESSION, 0, 0);
pthread_join (__mg_dsk_msg_queue->th, NULL);
# ifdef _MGRM_THREADS
/* Tell event parsor quit */
_is_minigui_running = 0;
pthread_join (_th_parsor, NULL);
# endif /* defined _MGRM_THREADS */
#endif /* defined _MGHAVE_VIRTUAL_WINDOW */
}
}

View File

@@ -84,6 +84,8 @@
/******************************************************************************/
#if 0 /* deprecated code */
/* since 5.0.0, we use post_quit_to_all_message_threads instead */
#ifdef _MGHAVE_VIRTUAL_WINDOW
#define SET_PADD(value) pMsg->pAdd = value
@@ -108,12 +110,13 @@
if (TEST_NEED_TO_QUIT(queue)) { \
LOCK_MSGQ (queue); \
if (!(queue->dwState & QS_QUIT)){ \
queue->loop_depth ++; \
queue->loop_depth++; \
queue->dwState |= QS_QUIT; \
UNLOCK_MSGQ (queue); \
if (IsDialog(hWnd)) { \
EndDialog (hWnd, IDCANCEL); \
} else { \
} \
else { \
DestroyMainWindow (hWnd); \
} \
} else { \
@@ -121,7 +124,15 @@
} \
} \
} while (0)
#endif /* deprecated code */
#ifdef _MGHAVE_VIRTUAL_WINDOW
# define SET_PADD(value) pMsg->pAdd = value
#else
# define SET_PADD(value)
#endif
#define TEST_IF_QUIT(queue, hWnd)
#define ERR_MSG_CANCELED ERR_QUEUE_FULL
/****************************** Message Allocation ****************************/

View File

@@ -340,9 +340,7 @@ void __mg_splash_delay (void)
{
int i;
for (i = 0;
__mg_quiting_stage > 0 && i < _MG_LICENSE_SPLASH_STEP;
i++) {
for (i = 0; i < _MG_LICENSE_SPLASH_STEP; i++) {
__mg_splash_progress();
__mg_os_time_delay (_MG_LICENSE_SPLASH_MSEC);
}