diff --git a/src/include/internals.h b/src/include/internals.h index 19e8caa7..09e830e4 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -777,12 +777,24 @@ int __mg_throw_away_messages (PMSGQUEUE pMsgQueue, HWND hWnd); #ifdef _MGHAVE_VIRTUAL_WINDOW +extern pthread_key_t __mg_threadinfo_key; + #define TEST_CANCEL pthread_testcancel() int __mg_join_all_message_threads (void); -MSGQUEUE* mg_GetMsgQueueForThisThread (BOOL alloc); +static inline MSGQUEUE* getMsgQueueForThisThread (void) +{ + MSGQUEUE* pMsgQueue; -extern pthread_key_t __mg_threadinfo_key; + pMsgQueue = (MSGQUEUE*)pthread_getspecific (__mg_threadinfo_key); +#ifdef __VXWORKS__ + if (pMsgQueue == (void *)-1) { + pMsgQueue = NULL; + } +#endif + + return pMsgQueue; +} static inline BOOL createThreadInfoKey (void) { diff --git a/src/kernel/message.c b/src/kernel/message.c index d345b214..7999b5c9 100644 --- a/src/kernel/message.c +++ b/src/kernel/message.c @@ -176,6 +176,10 @@ MSGQUEUE* mg_AllocMsgQueueForThisThread (void) pMsgQueue->th = pthread_self(); pthread_setspecific (__mg_threadinfo_key, pMsgQueue); #endif + + // register this new message queue + SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, + MSGTHREAD_SIGNIN, (LPARAM)pMsgQueue); return pMsgQueue; } @@ -206,29 +210,6 @@ void mg_FreeMsgQueueForThisThread (void) } } -#ifdef _MGHAVE_VIRTUAL_WINDOW -/* no use function */ -MSGQUEUE* mg_GetMsgQueueForThisThread (BOOL alloc) -{ - MSGQUEUE* pMsgQueue; - - pMsgQueue = (MSGQUEUE*)pthread_getspecific (__mg_threadinfo_key); -#ifdef __VXWORKS__ - if (pMsgQueue == (void *)-1) { - pMsgQueue = NULL; - } -#endif - - if (pMsgQueue == NULL && alloc) { - pMsgQueue = mg_AllocMsgQueueForThisThread (); - SendMessage (HWND_DESKTOP, MSG_MANAGE_MSGTHREAD, - MSGTHREAD_SIGNIN, (LPARAM)pMsgQueue); - } - - return pMsgQueue; -} -#endif /* defined _MGHAVE_VIRTUAL_WINDOW */ - static int handle_idle_message (MSGQUEUE* msg_queue) { int n = 0; @@ -555,7 +536,7 @@ BOOL GUIAPI HavePendingMessageEx (HWND hWnd, BOOL bNoDeskTimer) if (hWnd == HWND_NULL) { #ifdef _MGHAVE_VIRTUAL_WINDOW - if (!(pMsgQueue = mg_GetMsgQueueForThisThread (FALSE))) + if (!(pMsgQueue = getMsgQueueForThisThread ())) return FALSE; #else pMsgQueue = __mg_dsk_msg_queue; @@ -748,7 +729,7 @@ BOOL PeekMessageEx (PMSG pMsg, HWND hWnd, return FALSE; #ifdef _MGHAVE_VIRTUAL_WINDOW - if (!(pMsgQueue = mg_GetMsgQueueForThisThread (FALSE))) { + if (!(pMsgQueue = getMsgQueueForThisThread ())) { _WRN_PRINTF ("not a message thread.\n"); return FALSE; } @@ -1676,7 +1657,7 @@ LRESULT SendSyncMessage (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) #define _SYNC_NEED_REENTERABLE #ifndef _SYNC_NEED_REENTERABLE - if ((thinfo = mg_GetMsgQueueForThisThread (FALSE))) { + if ((thinfo = getMsgQueueForThisThread ())) { /* avoid to create a new semaphore object, Note: it's not reenterable.*/ SyncMsg.sem_handle = &thinfo->sync_msg; } @@ -1688,7 +1669,7 @@ LRESULT SendSyncMessage (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) #else /* not defined _SYNC_NEED_REENTERABLE */ /* For reentrantable implementation, we use a unique semaphore which is created in the stack. */ - thinfo = mg_GetMsgQueueForThisThread (FALSE); + thinfo = getMsgQueueForThisThread (); sem_init (&sync_msg, 0, 0); SyncMsg.sem_handle = &sync_msg; #endif /* defined _SYNC_NEED_REENTERABLE */