From 6aeafa47b02b966067d3ff83453c9ae8f9b0fc70 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 11 Mar 2013 15:11:36 +0000 Subject: only a few real mir_forkthreadex survived git-svn-id: http://svn.miranda-ng.org/main/trunk@3977 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../Clist_modern/src/hdr/modern_commonprototypes.h | 12 +++++- plugins/Clist_modern/src/hdr/modern_static_clui.h | 14 +------ plugins/Clist_modern/src/modern_awaymsg.cpp | 47 +++++++++------------ plugins/Clist_modern/src/modern_clui.cpp | 48 ++++++++++------------ plugins/Clist_modern/src/modern_gettextasync.cpp | 26 +++++------- 5 files changed, 64 insertions(+), 83 deletions(-) (limited to 'plugins/Clist_modern/src') diff --git a/plugins/Clist_modern/src/hdr/modern_commonprototypes.h b/plugins/Clist_modern/src/hdr/modern_commonprototypes.h index 69516c1d5d..8e71682180 100644 --- a/plugins/Clist_modern/src/hdr/modern_commonprototypes.h +++ b/plugins/Clist_modern/src/hdr/modern_commonprototypes.h @@ -67,7 +67,8 @@ extern BOOL g_bTransparentFlag; extern HINSTANCE g_hInst; extern HIMAGELIST hCListImages; extern BOOL g_mutex_bChangingMode; -extern UINT g_dwMainThreadID, g_dwAwayMsgThreadID, g_dwGetTextAsyncThreadID, g_dwSmoothAnimationThreadID; +extern UINT g_dwMainThreadID; +extern HANDLE g_hAwayMsgThread, g_hGetTextAsyncThread, g_hSmoothAnimationThread; extern HWND g_hwndViewModeFrame; extern HANDLE hSmileyAddOptionsChangedHook,hAvatarChanged,hIconChangedHook; extern BYTE gl_TrimText; @@ -76,6 +77,15 @@ extern BYTE gl_TrimText; /* TYPE DEFS */ /************************************************************************/ +class thread_catcher +{ + HANDLE &m_ptr; + +public: + __forceinline thread_catcher(HANDLE ¶m) : m_ptr(param) {} + __forceinline ~thread_catcher() { m_ptr = 0; } +}; + typedef INT_PTR (*PSYNCCALLBACKPROC)(WPARAM,LPARAM); /************************************************************************/ diff --git a/plugins/Clist_modern/src/hdr/modern_static_clui.h b/plugins/Clist_modern/src/hdr/modern_static_clui.h index 22925fc4d2..fb15b1e25a 100644 --- a/plugins/Clist_modern/src/hdr/modern_static_clui.h +++ b/plugins/Clist_modern/src/hdr/modern_static_clui.h @@ -41,9 +41,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TM_WINDOWUPDATE 100 #define TM_STATUSBARUPDATE 200 - - - #define MS_CLUI_SHOWMAINMENU "CList/ShowMainMenu" #define MS_CLUI_SHOWSTATUSMENU "CList/ShowStatusMenu" @@ -98,17 +95,10 @@ void RowHeight_InitModernRow(); int UnhookAll(); - -/* External variables */ - - /* Global variables */ - -UINT g_dwMainThreadID = 0, - g_dwAwayMsgThreadID = 0, - g_dwGetTextAsyncThreadID = 0, - g_dwSmoothAnimationThreadID = 0; +UINT g_dwMainThreadID = 0; +HANDLE g_hAwayMsgThread = 0, g_hGetTextAsyncThread = 0, g_hSmoothAnimationThread = 0; HMENU g_hMenuMain; BOOL g_bTransparentFlag=FALSE; diff --git a/plugins/Clist_modern/src/modern_awaymsg.cpp b/plugins/Clist_modern/src/modern_awaymsg.cpp index 4c6241c18e..09506e02cc 100644 --- a/plugins/Clist_modern/src/modern_awaymsg.cpp +++ b/plugins/Clist_modern/src/modern_awaymsg.cpp @@ -115,29 +115,27 @@ static HANDLE amGetCurrentChain() /* * Tread sub to ask protocol to retrieve away message */ -static unsigned __stdcall amThreadProc(void *) +static void amThreadProc(void *) { - DWORD time; - HANDLE hContact; - HANDLE ACK = 0; + thread_catcher lck(g_hAwayMsgThread); + ClcCacheEntry dnce; - memset( &dnce, 0, sizeof(dnce)); + memset(&dnce, 0, sizeof(dnce)); - while (!MirandaExiting()) - { - hContact = amGetCurrentChain(); + while (!MirandaExiting()) { + HANDLE hContact = amGetCurrentChain(); while (hContact) { - time = GetTickCount(); + DWORD time = GetTickCount(); if ((time-amRequestTick) < AMASKPERIOD) { SleepEx(AMASKPERIOD-(time-amRequestTick)+10, TRUE); - if (MirandaExiting()) { - g_dwAwayMsgThreadID = 0; - return 0; - } + if ( MirandaExiting()) + return; } CListSettings_FreeCacheItemData(&dnce); dnce.hContact = (HANDLE)hContact; - Sync(CLUI_SyncGetPDNCE, (WPARAM) 0, (LPARAM)&dnce); + Sync(CLUI_SyncGetPDNCE, (WPARAM) 0, (LPARAM)&dnce); + + HANDLE ACK = 0; if (dnce.ApparentMode != ID_STATUS_OFFLINE) //don't ask if contact is always invisible (should be done with protocol) ACK = (HANDLE)CallContactService(hContact,PSS_GETAWAYMSG, 0, 0); if ( !ACK) { @@ -163,26 +161,19 @@ static unsigned __stdcall amThreadProc(void *) while (i < AMASKPERIOD/50 && !MirandaExiting()); } else break; - if (MirandaExiting()) { - g_dwAwayMsgThreadID = 0; - return 0; - } + if ( MirandaExiting()) + return; } WaitForSingleObjectEx(hamProcessEvent, INFINITE, TRUE); ResetEvent(hamProcessEvent); - if (MirandaExiting()) - { - g_dwAwayMsgThreadID = 0; - return 0; - } + if ( MirandaExiting()) + break; } - g_dwAwayMsgThreadID = 0; - return 1; } BOOL amWakeThread() { - if (hamProcessEvent && g_dwAwayMsgThreadID) { + if (hamProcessEvent && g_hAwayMsgThread) { SetEvent(hamProcessEvent); return TRUE; } @@ -209,14 +200,14 @@ void InitAwayMsgModule() { InitializeCriticalSection(&amLockChain); hamProcessEvent = CreateEvent(NULL,FALSE,FALSE,NULL); - mir_forkthreadex(amThreadProc, 0, &g_dwAwayMsgThreadID); + g_hAwayMsgThread = mir_forkthread(amThreadProc, 0); } void UninitAwayMsgModule() { SetEvent(hamProcessEvent); - while (g_dwAwayMsgThreadID) + while (g_hAwayMsgThread) SleepEx(50, TRUE); CloseHandle(hamProcessEvent); diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp index cb072264db..a457d7f17f 100644 --- a/plugins/Clist_modern/src/modern_clui.cpp +++ b/plugins/Clist_modern/src/modern_clui.cpp @@ -514,16 +514,16 @@ static BOOL CLUI_WaitThreadsCompletion(HWND hwnd) if (bEntersCount < bcMAX_AWAITING_RETRY && ( g_mutex_nCalcRowHeightLock || g_CluiData.mutexPaintLock || - g_dwAwayMsgThreadID || - g_dwGetTextAsyncThreadID || - g_dwSmoothAnimationThreadID) && !Miranda_Terminated()) + g_hAwayMsgThread || + g_hGetTextAsyncThread || + g_hSmoothAnimationThread) && !Miranda_Terminated()) { TRACE("Waiting threads"); TRACEVAR("g_mutex_nCalcRowHeightLock: %x",g_mutex_nCalcRowHeightLock); TRACEVAR("g_CluiData.mutexPaintLock: %x",g_CluiData.mutexPaintLock); - TRACEVAR("g_dwAwayMsgThreadID: %x",g_dwAwayMsgThreadID); - TRACEVAR("g_dwGetTextAsyncThreadID: %x",g_dwGetTextAsyncThreadID); - TRACEVAR("g_dwSmoothAnimationThreadID: %x",g_dwSmoothAnimationThreadID); + TRACEVAR("g_hAwayMsgThread: %x",g_hAwayMsgThread); + TRACEVAR("g_hGetTextAsyncThread: %x",g_hGetTextAsyncThread); + TRACEVAR("g_hSmoothAnimationThread: %x",g_hSmoothAnimationThread); bEntersCount++; SleepEx(10, TRUE); @@ -1451,31 +1451,25 @@ static int CLUI_SyncSmoothAnimation(WPARAM wParam, LPARAM lParam) return CLUI_SmoothAlphaThreadTransition((HWND)lParam); } -static unsigned __stdcall CLUI_SmoothAnimationThreadProc(void *param) +static void CLUI_SmoothAnimationThreadProc(void *param) { - if ( !mutex_bAnimationInProgress) { - g_dwSmoothAnimationThreadID = 0; - return 0; /// Should be some locked to avoid painting against contact deletion. - } + thread_catcher lck(g_hSmoothAnimationThread); - do { - if ( !g_mutex_bLockUpdating) { - if ( !MirandaExiting()) - Sync(CLUI_SyncSmoothAnimation, 0, (LPARAM)param); + if (mutex_bAnimationInProgress) { + do { + if ( !g_mutex_bLockUpdating) { + if ( MirandaExiting()) + return; - SleepEx(20, TRUE); - if (MirandaExiting()) { - g_dwSmoothAnimationThreadID = 0; - return 0; + Sync(CLUI_SyncSmoothAnimation, 0, (LPARAM)param); + SleepEx(20, TRUE); + if ( MirandaExiting()) + return; } + else SleepEx(0, TRUE); } - else SleepEx(0, TRUE); - + while (mutex_bAnimationInProgress); } - while (mutex_bAnimationInProgress); - - g_dwSmoothAnimationThreadID = 0; - return 0; } static int CLUI_SmoothAlphaThreadTransition(HWND hwnd) @@ -1563,10 +1557,10 @@ int CLUI_SmoothAlphaTransition(HWND hwnd, BYTE GoalAlpha, BOOL wParam) g_CluiData.bCurrentAlpha = 1; ske_UpdateWindowImage(); } - if (IsWindowVisible(hwnd) && !g_dwSmoothAnimationThreadID) { + if (IsWindowVisible(hwnd) && !g_hSmoothAnimationThread) { mutex_bAnimationInProgress = 1; if (g_CluiData.fSmoothAnimation) - mir_forkthreadex(CLUI_SmoothAnimationThreadProc, pcli->hwndContactList, &g_dwSmoothAnimationThreadID); + g_hSmoothAnimationThread = mir_forkthread(CLUI_SmoothAnimationThreadProc, pcli->hwndContactList); } } } diff --git a/plugins/Clist_modern/src/modern_gettextasync.cpp b/plugins/Clist_modern/src/modern_gettextasync.cpp index 1244e8b49c..4c4bbe5b89 100644 --- a/plugins/Clist_modern/src/modern_gettextasync.cpp +++ b/plugins/Clist_modern/src/modern_gettextasync.cpp @@ -76,18 +76,18 @@ static BOOL gtaGetItem(GTACHAINITEM * mpChain) return FALSE; } -static unsigned __stdcall gtaThreadProc(void * lpParam) +static void gtaThreadProc(void *lpParam) { + thread_catcher lck(g_hGetTextAsyncThread); HWND hwnd = pcli->hwndContactList; - struct SHORTDATA data = {0}; + SHORTDATA data = {0}; while (!MirandaExiting()) { Sync(CLUI_SyncGetShortData,(WPARAM)pcli->hwndContactTree,(LPARAM)&data); while (true) { - if (MirandaExiting()) { - g_dwGetTextAsyncThreadID = 0; - return 0; - } + if ( MirandaExiting()) + return; + SleepEx(0, TRUE); //1000 contacts per second GTACHAINITEM mpChain = {0}; @@ -102,10 +102,8 @@ static unsigned __stdcall gtaThreadProc(void * lpParam) Sync(CLUI_SyncGetShortData,(WPARAM)mpChain.dat->hWnd,(LPARAM)&dat2); dat = &dat2; } - if ( MirandaExiting()) { - g_dwGetTextAsyncThreadID = 0; - return 0; - } + if ( MirandaExiting()) + return; ClcCacheEntry cacheEntry; memset(&cacheEntry, 0, sizeof(cacheEntry)); @@ -124,13 +122,11 @@ static unsigned __stdcall gtaThreadProc(void * lpParam) WaitForSingleObjectEx(hgtaWakeupEvent, INFINITE, TRUE); ResetEvent(hgtaWakeupEvent); } - g_dwGetTextAsyncThreadID = 0; - return 1; } BOOL gtaWakeThread() { - if (hgtaWakeupEvent && g_dwGetTextAsyncThreadID) { + if (hgtaWakeupEvent && g_hGetTextAsyncThread) { SetEvent(hgtaWakeupEvent); return TRUE; } @@ -178,14 +174,14 @@ void InitCacheAsync() { InitializeCriticalSection(>aCS); hgtaWakeupEvent = CreateEvent(NULL,FALSE,FALSE,NULL); - mir_forkthreadex(gtaThreadProc, 0, &g_dwGetTextAsyncThreadID); + g_hGetTextAsyncThread = mir_forkthread(gtaThreadProc, 0); HookEvent(ME_SYSTEM_PRESHUTDOWN, gtaOnModulesUnload); } void UninitCacheAsync() { SetEvent(hgtaWakeupEvent); - while(g_dwGetTextAsyncThreadID) + while(g_hGetTextAsyncThread) SleepEx(50, TRUE); CloseHandle(hgtaWakeupEvent); -- cgit v1.2.3