diff --git a/cleanup-code.sh b/cleanup-code.sh index 22a48298..f7cb1ba2 100755 --- a/cleanup-code.sh +++ b/cleanup-code.sh @@ -96,6 +96,13 @@ tab2space() { # sed -i 's/\/pMsgQueue/g' `grep pMessages -rl src/` -sed -i 's/\/mg_AllocMsgQueueThisThread/g' `grep mg_InitMsgQueueThisThread -rl include/ src/` +# sed -i 's/\/mg_AllocMsgQueueThisThread/g' `grep mg_InitMsgQueueThisThread -rl include/ src/` + +# sed -i 's/\/mg_AllocMsgQueueForThisThread/g' `grep mg_AllocMsgQueueThisThread -rl src/` +# sed -i 's/\/mg_FreeMsgQueueForThisThread/g' `grep mg_FreeMsgQueueThisThread -rl src/` + +# sed -i 's/\/mg_GetMsgQueueForThisThread/g' `grep GetMsgQueueThisThread -rl src/` + +sed -i 's/\/getMsgQueue/g' `grep kernel_GetMsgQueue -rl src/` exit 0 diff --git a/src/include/internals.h b/src/include/internals.h index a0f5249a..2e3df0f7 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -508,9 +508,6 @@ PMAINWIN gui_CheckAndGetMainWindowPtr (HWND hWnd); PMAINWIN gui_GetMainWindowPtrUnderPoint (int x, int y); -/* return message queue of window. */ -PMSGQUEUE kernel_GetMsgQueue (HWND hWnd); - /* return the next window need to repaint. */ HWND kernel_CheckInvalidRegion (PMAINWIN pWin); @@ -594,6 +591,17 @@ static inline PMAINWIN getMainWindowPtr (HWND hWnd) return pWin->pMainWin; } +/* Get message queue by window handle. + Note that hWnd may belong to a different thread. */ +static inline PMSGQUEUE getMsgQueue (HWND hWnd) +{ + PMAINWIN pWin; + pWin = getMainWindowPtr (hWnd); + if (pWin) + return pWin->pMsgQueue; + return NULL; +} + #ifdef _MGHAVE_VIRTUAL_WINDOW /* Be careful: does not check validity of hWnd */ @@ -610,8 +618,9 @@ static inline BOOL BE_THIS_THREAD (HWND hWnd) return FALSE; } -MSGQUEUE* mg_AllocMsgQueueThisThread (void); -void mg_FreeMsgQueueThisThread (void); +MSGQUEUE* mg_AllocMsgQueueForThisThread (void); +void mg_FreeMsgQueueForThisThread (void); +MSGQUEUE* mg_GetMsgQueueForThisThread (BOOL alloc); extern pthread_key_t __mg_threadinfo_key; @@ -627,21 +636,7 @@ static inline void deleteThreadInfoKey (void) pthread_key_delete (__mg_threadinfo_key); } -static inline MSGQUEUE* getMsgQueueThisThread (void) -{ - MSGQUEUE* pMsgQueue; - - pMsgQueue = (MSGQUEUE*)pthread_getspecific (__mg_threadinfo_key); -#ifdef __VXWORKS__ - if (pMsgQueue == (void *)-1) { - return NULL; - } -#endif - - return pMsgQueue; -} - -#endif /* defined _MGRM_THREADS */ +#endif /* defined _MGHAVE_VIRTUAL_WINDOW */ #ifndef _MGRM_THREADS static inline void SetDesktopTimerFlag (void) diff --git a/src/kernel/desktop-comm.c b/src/kernel/desktop-comm.c index 706f0044..444e6f77 100644 --- a/src/kernel/desktop-comm.c +++ b/src/kernel/desktop-comm.c @@ -2457,7 +2457,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message, pWin = (PMAINWIN)(nodes[fixed_slots[slot]].hwnd); if (pWin && (pWin->WinType != TYPE_CONTROL) && (pWin->pHosting == NULL)) { - if ((pMsgQueue = kernel_GetMsgQueue((HWND)pWin))) { + if ((pMsgQueue = getMsgQueue((HWND)pWin))) { POST_MSGQ(pMsgQueue); } } @@ -2469,7 +2469,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message, pWin = (PMAINWIN)(nodes[slot].hwnd); if (pWin && (pWin->WinType != TYPE_CONTROL) && (pWin->pHosting == NULL)) { - if ((pMsgQueue = kernel_GetMsgQueue((HWND)pWin))) { + if ((pMsgQueue = getMsgQueue((HWND)pWin))) { POST_MSGQ(pMsgQueue); } } @@ -2480,7 +2480,7 @@ static LRESULT DesktopWinProc (HWND hWnd, UINT message, pWin = (PMAINWIN)(nodes[slot].hwnd); if (pWin && (pWin->WinType == TYPE_MAINWIN) && (pWin->pHosting == NULL)){ - if ((pMsgQueue = kernel_GetMsgQueue((HWND)pWin))) { + if ((pMsgQueue = getMsgQueue((HWND)pWin))) { POST_MSGQ(pMsgQueue); } } diff --git a/src/kernel/desktop-ths.c b/src/kernel/desktop-ths.c index a1b4ac75..8dcdb12f 100644 --- a/src/kernel/desktop-ths.c +++ b/src/kernel/desktop-ths.c @@ -145,8 +145,8 @@ void* __kernel_desktop_main (void* data) MSG Msg; /* init message queue of desktop thread */ - if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueThisThread ()) ) { - _WRN_PRINTF ("KERNEL>Desktop: mg_AllocMsgQueueThisThread failure!\n"); + if (!(__mg_dsk_msg_queue = mg_AllocMsgQueueForThisThread ()) ) { + _WRN_PRINTF ("KERNEL>Desktop: mg_AllocMsgQueueForThisThread failure!\n"); return NULL; } diff --git a/src/kernel/init.c b/src/kernel/init.c index 19a2294d..fd9d5664 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -257,7 +257,7 @@ ndef __USE_TIMER_THREAD return NULL; } -/* The following function is moved to src/include/internals.h as inline functions. +/* The following functions were moved to src/include/internals.h as inline. static inline BOOL createThreadInfoKey (void) { if (pthread_key_create (&__mg_threadinfo_key, NULL)) @@ -270,7 +270,7 @@ static inline void deleteThreadInfoKey (void) pthread_key_delete (__mg_threadinfo_key); } -MSGQUEUE* GetMsgQueueThisThread (void) +MSGQUEUE* mg_GetMsgQueueForThisThread (void) { return (MSGQUEUE*) pthread_getspecific (__mg_threadinfo_key); }