mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-02-07 02:52:42 +08:00
move timer slots to message queue and tune code. now we allocate timer slots per thread, and manage the time slots in message queue
This commit is contained in:
@@ -103,6 +103,11 @@ tab2space() {
|
||||
|
||||
# sed -i 's/\<GetMsgQueueThisThread\>/mg_GetMsgQueueForThisThread/g' `grep GetMsgQueueThisThread -rl src/`
|
||||
|
||||
sed -i 's/\<kernel_GetMsgQueue\>/getMsgQueue/g' `grep kernel_GetMsgQueue -rl src/`
|
||||
# sed -i 's/\<kernel_GetMsgQueue\>/getMsgQueue/g' `grep kernel_GetMsgQueue -rl src/`
|
||||
|
||||
# sed -i 's/\<BE_THIS_THREAD\>/isWindowInThisThread/g' `grep BE_THIS_THREAD -rl src/`
|
||||
|
||||
sed -i 's/\<SetMsgQueueTimerFlag\>/setMsgQueueTimerFlag/g' `grep SetMsgQueueTimerFlag -rl src/`
|
||||
sed -i 's/\<RemoveMsgQueueTimerFlag\>/removeMsgQueueTimerFlag/g' `grep RemoveMsgQueueTimerFlag -rl src/`
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -109,6 +109,9 @@ struct GAL_Surface;
|
||||
struct _MAINWIN;
|
||||
typedef struct _MAINWIN* PMAINWIN;
|
||||
|
||||
struct _TIMER;
|
||||
typedef struct _TIMER TIMER;
|
||||
|
||||
typedef struct _SCROLLWINDOWINFO
|
||||
{
|
||||
int iOffx;
|
||||
@@ -202,13 +205,17 @@ struct _MSGQUEUE
|
||||
#endif
|
||||
int nrWindows; // the number of main/virtual windows.
|
||||
|
||||
MSG* msg; // post message buffer
|
||||
/* buffer for post message */
|
||||
int len; // buffer length
|
||||
MSG* msg; // post message buffer
|
||||
int readpos, writepos; // positions for reading and writing
|
||||
|
||||
int loop_depth; // message loop depth, for dialog boxes
|
||||
|
||||
/* Since 4.2.0, MiniGUI provides support for timers per message thread */
|
||||
int FirstTimerSlot; // the first timer slot to be checked
|
||||
TIMER* timer_slots [DEF_NR_TIMERS];
|
||||
// slots for timer
|
||||
DWORD TimerMask; // timer slots mask
|
||||
};
|
||||
|
||||
@@ -604,20 +611,6 @@ static inline PMSGQUEUE getMsgQueue (HWND hWnd)
|
||||
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
|
||||
/* Be careful: does not check validity of hWnd */
|
||||
static inline BOOL BE_THIS_THREAD (HWND hWnd)
|
||||
{
|
||||
PMAINWIN pMainWin = getMainWindowPtr(hWnd);
|
||||
#ifdef WIN32
|
||||
if (pMainWin && pMainWin->pMsgQueue->th.p == pthread_self().p)
|
||||
#else
|
||||
if (pMainWin && pMainWin->pMsgQueue->th == pthread_self())
|
||||
#endif
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
MSGQUEUE* mg_AllocMsgQueueForThisThread (void);
|
||||
void mg_FreeMsgQueueForThisThread (void);
|
||||
MSGQUEUE* mg_GetMsgQueueForThisThread (BOOL alloc);
|
||||
@@ -636,6 +629,67 @@ static inline void deleteThreadInfoKey (void)
|
||||
pthread_key_delete (__mg_threadinfo_key);
|
||||
}
|
||||
|
||||
static inline MSGQUEUE* getMsgQueueForThisThread (void)
|
||||
{
|
||||
MSGQUEUE* pMsgQueue;
|
||||
|
||||
pMsgQueue = (MSGQUEUE*)pthread_getspecific (__mg_threadinfo_key);
|
||||
#ifdef __VXWORKS__
|
||||
if (pMsgQueue == (void *)-1) {
|
||||
pMsgQueue = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return pMsgQueue;
|
||||
}
|
||||
|
||||
static inline TIMER** getTimerSlotsForThisThread (void)
|
||||
{
|
||||
MSGQUEUE* pMsgQueue;
|
||||
|
||||
pMsgQueue = (MSGQUEUE*)pthread_getspecific (__mg_threadinfo_key);
|
||||
#ifdef __VXWORKS__
|
||||
if (pMsgQueue == (void *)-1) {
|
||||
pMsgQueue = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pMsgQueue)
|
||||
return pMsgQueue->timer_slots;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Be careful: does not check validity of hWnd */
|
||||
static inline BOOL isWindowInThisThread (HWND hWnd)
|
||||
{
|
||||
PMAINWIN pMainWin = getMainWindowPtr(hWnd);
|
||||
#ifdef WIN32
|
||||
if (pMainWin && pMainWin->pMsgQueue->th.p == pthread_self().p)
|
||||
#else
|
||||
if (pMainWin && pMainWin->pMsgQueue->th == pthread_self())
|
||||
#endif
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#else /* define _MGHAVE_VIRTUAL_WINDOW */
|
||||
|
||||
static inline MSGQUEUE* getMsgQueueForThisThread (void)
|
||||
{
|
||||
return __mg_dsk_msg_queue;
|
||||
}
|
||||
|
||||
static inline TIMER** getTimerSlotsForThisThread (void)
|
||||
{
|
||||
return __mg_dsk_msg_queue->timer_slots;
|
||||
}
|
||||
|
||||
static inline BOOL isWindowInThisThread (HWND hWnd)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* defined _MGHAVE_VIRTUAL_WINDOW */
|
||||
|
||||
#ifndef _MGRM_THREADS
|
||||
@@ -653,13 +707,13 @@ static inline void AlertDesktopTimerEvent (void)
|
||||
}
|
||||
#endif /* defined _MGRM_THREADS */
|
||||
|
||||
static inline void SetMsgQueueTimerFlag (PMSGQUEUE pMsgQueue, int slot)
|
||||
static inline void setMsgQueueTimerFlag (PMSGQUEUE pMsgQueue, int slot)
|
||||
{
|
||||
pMsgQueue->TimerMask |= (0x01 << slot);
|
||||
POST_MSGQ (pMsgQueue);
|
||||
}
|
||||
|
||||
static inline void RemoveMsgQueueTimerFlag (PMSGQUEUE pMsgQueue, int slot)
|
||||
static inline void removeMsgQueueTimerFlag (PMSGQUEUE pMsgQueue, int slot)
|
||||
{
|
||||
pMsgQueue->TimerMask &= ~(0x01 << slot);
|
||||
}
|
||||
|
||||
@@ -52,14 +52,10 @@
|
||||
#ifndef GUI_TIMER_H
|
||||
#define GUI_TIMER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define USEC_1S 1000000
|
||||
#define USEC_10MS 10000
|
||||
|
||||
typedef struct _timer {
|
||||
typedef struct _TIMER {
|
||||
HWND hWnd;
|
||||
LINT id;
|
||||
DWORD speed;
|
||||
@@ -67,26 +63,36 @@ typedef struct _timer {
|
||||
|
||||
TIMERPROC proc;
|
||||
UINT_PTR tick_count;
|
||||
PMSGQUEUE msg_queue;
|
||||
|
||||
// removed since 4.2.0
|
||||
// PMSGQUEUE msg_queue;
|
||||
} TIMER;
|
||||
typedef TIMER* PTIMER;
|
||||
|
||||
struct _MSGQUEUE;
|
||||
typedef struct _MSGQUEUE MSGQUEUE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
BOOL mg_InitTimer (void);
|
||||
void mg_TerminateTimer (void);
|
||||
void __mg_dispatch_timer_message (DWORD inter);
|
||||
void __mg_remove_timers_by_msg_queue (const MSGQUEUE* msg_que);
|
||||
void __mg_remove_timers_by_msg_queue (MSGQUEUE* msg_queue);
|
||||
void __mg_remove_timer (MSGQUEUE* msg_queue, int slot);
|
||||
|
||||
#if 0
|
||||
TIMER* __mg_get_timer (int slot);
|
||||
void __mg_remove_timer (TIMER* timer, int slot);
|
||||
|
||||
static inline HWND __mg_get_timer_hwnd (int slot)
|
||||
{
|
||||
TIMER* ptimer = __mg_get_timer (slot);
|
||||
if (ptimer)
|
||||
return ptimer->hWnd;
|
||||
TIMER* timer = __mg_get_timer (slot);
|
||||
if (timer)
|
||||
return timer->hWnd;
|
||||
|
||||
return HWND_NULL;
|
||||
}
|
||||
#endif /* deprecated code since 4.2.0 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -199,11 +199,6 @@ MSGQUEUE* mg_GetMsgQueueForThisThread (BOOL alloc)
|
||||
|
||||
if (pMsgQueue == NULL && alloc) {
|
||||
pMsgQueue = mg_AllocMsgQueueForThisThread ();
|
||||
#if 0
|
||||
if (pMsgQueue) {
|
||||
pthread_cleanup_push (mg_FreeMsgQueueForThisThread, (void*)pMsgQueue);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return pMsgQueue;
|
||||
@@ -352,7 +347,7 @@ ret:
|
||||
UNLOCK_MSGQ (msg_que);
|
||||
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if (!BE_THIS_THREAD (msg->hwnd))
|
||||
if (!isWindowInThisThread (msg->hwnd))
|
||||
POST_MSGQ (msg_que);
|
||||
#endif
|
||||
|
||||
@@ -764,7 +759,7 @@ checkagain:
|
||||
pMsgQueue->FirstTimerSlot ++;
|
||||
pMsgQueue->FirstTimerSlot %= DEF_NR_TIMERS;
|
||||
|
||||
if ((timer = __mg_get_timer (slot))) {
|
||||
if ((timer = pMsgQueue->timer_slots[slot])) {
|
||||
pMsgQueue->TimerMask &= ~(0x01UL << slot);
|
||||
|
||||
if (timer->proc) {
|
||||
@@ -782,7 +777,7 @@ checkagain:
|
||||
|
||||
if (!ret_timer_proc) {
|
||||
/* remove the timer */
|
||||
__mg_remove_timer (timer, slot);
|
||||
__mg_remove_timer (pMsgQueue, slot);
|
||||
}
|
||||
UNLOCK_MSGQ (pMsgQueue);
|
||||
goto checkagain;
|
||||
@@ -967,7 +962,7 @@ LRESULT GUIAPI SendMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
|
||||
MG_CHECK_RET (MG_IS_WINDOW(hWnd), -1);
|
||||
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if (!BE_THIS_THREAD(hWnd))
|
||||
if (!isWindowInThisThread(hWnd))
|
||||
return SendSyncMessage (hWnd, nMsg, wParam, lParam);
|
||||
#endif
|
||||
|
||||
@@ -1012,7 +1007,7 @@ LRESULT SendTopNotifyMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam
|
||||
|
||||
UNLOCK_MSGQ (pMsgQueue);
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if ( !BE_THIS_THREAD(hWnd) )
|
||||
if ( !isWindowInThisThread(hWnd) )
|
||||
POST_MSGQ(pMsgQueue);
|
||||
#endif
|
||||
|
||||
@@ -1052,7 +1047,7 @@ int GUIAPI SendNotifyMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam
|
||||
|
||||
UNLOCK_MSGQ (pMsgQueue);
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if ( !BE_THIS_THREAD(hWnd) )
|
||||
if ( !isWindowInThisThread(hWnd) )
|
||||
POST_MSGQ(pMsgQueue);
|
||||
#endif
|
||||
|
||||
@@ -1072,7 +1067,7 @@ int GUIAPI PostMessage (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
|
||||
pMsgQueue->dwState |= QS_PAINT;
|
||||
UNLOCK_MSGQ (pMsgQueue);
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if ( !BE_THIS_THREAD(hWnd) )
|
||||
if ( !isWindowInThisThread(hWnd) )
|
||||
POST_MSGQ(pMsgQueue);
|
||||
#endif
|
||||
return ERR_OK;
|
||||
@@ -1111,7 +1106,7 @@ int GUIAPI PostQuitMessage (HWND hWnd)
|
||||
UNLOCK_MSGQ (pMsgQueue);
|
||||
|
||||
#ifdef _MGHAVE_VIRTUAL_WINDOW
|
||||
if (!BE_THIS_THREAD (hWnd))
|
||||
if (!isWindowInThisThread (hWnd))
|
||||
POST_MSGQ (pMsgQueue);
|
||||
#endif
|
||||
|
||||
@@ -1298,11 +1293,11 @@ int GUIAPI ThrowAwayMessages (HWND hWnd)
|
||||
/* clear timer message flags of this window */
|
||||
for (slot = 0; slot < DEF_NR_TIMERS; slot++) {
|
||||
if (pMsgQueue->TimerMask & (0x01UL << slot)) {
|
||||
HWND timer_wnd = __mg_get_timer_hwnd (slot);
|
||||
HWND timer_wnd = pMsgQueue->timer_slots [slot]->hWnd;
|
||||
if (timer_wnd == hWnd
|
||||
|| (MG_IS_MAIN_WINDOW (hWnd) &&
|
||||
gui_GetMainWindowPtrOfControl (timer_wnd) == (PMAINWIN)hWnd)) {
|
||||
RemoveMsgQueueTimerFlag (pMsgQueue, slot);
|
||||
removeMsgQueueTimerFlag (pMsgQueue, slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1450,7 +1445,7 @@ LRESULT SendSyncMessage (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
LRESULT GUIAPI PostSyncMessage (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
MG_CHECK_RET (MG_IS_WINDOW(hWnd), -1);
|
||||
if (BE_THIS_THREAD(hWnd))
|
||||
if (isWindowInThisThread(hWnd))
|
||||
return -1;
|
||||
|
||||
return SendSyncMessage (hWnd, msg, wParam, lParam);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user