summaryrefslogtreecommitdiff
path: root/plugins/Clist_modern
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-03-11 13:43:44 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-03-11 13:43:44 +0000
commit99b0796eb6cd0bcc7d7facdd1a1a6834cca588dd (patch)
treecda401c44fc86b6eeb73cab594d682150e5b5c94 /plugins/Clist_modern
parentf01a47f097c67d7636cda151e0681a4eb538aa32 (diff)
various mir_forkthread quirks
git-svn-id: http://svn.miranda-ng.org/main/trunk@3975 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Clist_modern')
-rw-r--r--plugins/Clist_modern/src/hdr/modern_commonprototypes.h8
-rw-r--r--plugins/Clist_modern/src/hdr/modern_static_clui.h9
-rw-r--r--plugins/Clist_modern/src/modern_aniavatars.cpp74
-rw-r--r--plugins/Clist_modern/src/modern_awaymsg.cpp29
-rw-r--r--plugins/Clist_modern/src/modern_clui.cpp111
-rw-r--r--plugins/Clist_modern/src/modern_gettextasync.cpp4
6 files changed, 101 insertions, 134 deletions
diff --git a/plugins/Clist_modern/src/hdr/modern_commonprototypes.h b/plugins/Clist_modern/src/hdr/modern_commonprototypes.h
index efbb035932..69516c1d5d 100644
--- a/plugins/Clist_modern/src/hdr/modern_commonprototypes.h
+++ b/plugins/Clist_modern/src/hdr/modern_commonprototypes.h
@@ -67,12 +67,8 @@ extern BOOL g_bTransparentFlag;
extern HINSTANCE g_hInst;
extern HIMAGELIST hCListImages;
extern BOOL g_mutex_bChangingMode;
-extern DWORD g_dwMainThreadID;
-extern DWORD g_dwAwayMsgThreadID;
-extern DWORD g_dwGetTextAsyncThreadID;
-extern DWORD g_dwSmoothAnimationThreadID;
-extern DWORD g_dwFillFontListThreadID;
-extern HWND g_hwndViewModeFrame;
+extern UINT g_dwMainThreadID, g_dwAwayMsgThreadID, g_dwGetTextAsyncThreadID, g_dwSmoothAnimationThreadID;
+extern HWND g_hwndViewModeFrame;
extern HANDLE hSmileyAddOptionsChangedHook,hAvatarChanged,hIconChangedHook;
extern BYTE gl_TrimText;
diff --git a/plugins/Clist_modern/src/hdr/modern_static_clui.h b/plugins/Clist_modern/src/hdr/modern_static_clui.h
index 7a7d205f14..22925fc4d2 100644
--- a/plugins/Clist_modern/src/hdr/modern_static_clui.h
+++ b/plugins/Clist_modern/src/hdr/modern_static_clui.h
@@ -105,11 +105,10 @@ int UnhookAll();
/* Global variables */
-DWORD g_dwMainThreadID=0,
- g_dwAwayMsgThreadID=0,
- g_dwGetTextAsyncThreadID=0,
- g_dwSmoothAnimationThreadID=0,
- g_dwFillFontListThreadID=0;
+UINT g_dwMainThreadID = 0,
+ g_dwAwayMsgThreadID = 0,
+ g_dwGetTextAsyncThreadID = 0,
+ g_dwSmoothAnimationThreadID = 0;
HMENU g_hMenuMain;
BOOL g_bTransparentFlag=FALSE;
diff --git a/plugins/Clist_modern/src/modern_aniavatars.cpp b/plugins/Clist_modern/src/modern_aniavatars.cpp
index ad35b6f3fd..7c92ae4b18 100644
--- a/plugins/Clist_modern/src/modern_aniavatars.cpp
+++ b/plugins/Clist_modern/src/modern_aniavatars.cpp
@@ -148,7 +148,7 @@ typedef struct _tagAniAva
int width;
int height;
SortedList * AniAvatarList;
- DWORD AnimationThreadID;
+ UINT AnimationThreadID;
HANDLE AnimationThreadHandle;
HANDLE hExitEvent;
//Objects
@@ -166,7 +166,6 @@ static void _AniAva_PausePainting();
static void _AniAva_ResumePainting();
static void _AniAva_LoadOptions();
static void _AniAva_ReduceAvatarImages(int startY, int dY, BOOL bDestroyWindow);
-static void _AniAva_AnimationTreadProc(HANDLE hExitEvent);
static void _AniAva_RemoveAniAvaDC(ANIAVA * pAniAva);
static void _AniAva_RealRemoveAvatar(DWORD UniqueID);
static int _AniAva_LoadAvatarFromImage(TCHAR * szFileName, int width, int height, ANIAVATARIMAGEINFO * pRetAII);
@@ -188,6 +187,36 @@ int _AniAva_OnModulesUnload(WPARAM wParam,LPARAM lParam)
return 0;
}
+static unsigned __stdcall _AniAva_AnimationTreadProc(HANDLE hExitEvent)
+{
+ //wait forever till hExitEvent signalled
+ DWORD rc;
+ HANDLE hThread = 0;
+ DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),GetCurrentProcess(),&hThread, 0, FALSE,DUPLICATE_SAME_ACCESS);
+ AniAva.AnimationThreadHandle = hThread;
+ SetThreadPriority(hThread,THREAD_PRIORITY_LOWEST);
+ for (;;) {
+ if ( fnMsgWaitForMultipleObjectsEx )
+ rc = fnMsgWaitForMultipleObjectsEx(1,&hExitEvent, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
+ else
+ rc = MsgWaitForMultipleObjects(1,&hExitEvent, FALSE, INFINITE, QS_ALLINPUT);
+
+ ResetEvent(hExitEvent);
+ if (rc == WAIT_OBJECT_0 + 1) {
+ MSG msg;
+ while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if ( IsDialogMessage(msg.hwnd, &msg)) continue;
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ else if ( rc == WAIT_OBJECT_0 )
+ break;
+ }
+ CloseHandle(AniAva.AnimationThreadHandle);
+ AniAva.AnimationThreadHandle = NULL;
+ return 0;
+}
// Init AniAva module
int AniAva_InitModule()
@@ -197,14 +226,11 @@ int AniAva_InitModule()
if ( !( db_get_b(NULL,"CList","AvatarsAnimated",( ServiceExists(MS_AV_GETAVATARBITMAP) && !g_CluiData.fGDIPlusFail))
&& db_get_b(NULL,"CList","AvatarsShow",SETTINGS_SHOWAVATARS_DEFAULT))) return 0;
{
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
+ WNDCLASSEX wc = { sizeof(wc) };
wc.lpszClassName = ANIAVAWINDOWCLASS;
wc.lpfnWndProc = _AniAva_WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.cbWndExtra = sizeof(ANIAVA_WINDOWINFO*);
- wc.hbrBackground = 0;
wc.style = CS_GLOBALCLASS;
RegisterClassEx(&wc);
}
@@ -214,7 +240,7 @@ int AniAva_InitModule()
AniAva.AniAvatarList->sortFunc = _AniAva_SortAvatarInfo;
AniAva.bModuleStarted = TRUE;
AniAva.hExitEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
- AniAva.AnimationThreadID = (DWORD)mir_forkthread(_AniAva_AnimationTreadProc, (void*)AniAva.hExitEvent);
+ mir_forkthreadex(_AniAva_AnimationTreadProc, AniAva.hExitEvent, &AniAva.AnimationThreadID);
HookEvent(ME_SYSTEM_PRESHUTDOWN, _AniAva_OnModulesUnload);
_AniAva_LoadOptions();
@@ -1029,40 +1055,6 @@ static void _AniAva_LoadOptions()
}
aaunlock;
}
-static void _AniAva_AnimationTreadProc(HANDLE hExitEvent)
-{
- //wait forever till hExitEvent signalled
- DWORD rc;
- HANDLE hThread = 0;
- DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),GetCurrentProcess(),&hThread, 0, FALSE,DUPLICATE_SAME_ACCESS);
- AniAva.AnimationThreadHandle = hThread;
- SetThreadPriority(hThread,THREAD_PRIORITY_LOWEST);
- for (;;)
- {
- if ( fnMsgWaitForMultipleObjectsEx )
- rc = fnMsgWaitForMultipleObjectsEx(1,&hExitEvent, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
- else
- rc = MsgWaitForMultipleObjects(1,&hExitEvent, FALSE, INFINITE, QS_ALLINPUT);
-
- ResetEvent(hExitEvent);
- if ( rc == WAIT_OBJECT_0 + 1 )
- {
- MSG msg;
- while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if ( IsDialogMessage(msg.hwnd, &msg)) continue;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- else if ( rc == WAIT_OBJECT_0 )
- {
- break;
- }
- }
- CloseHandle(AniAva.AnimationThreadHandle);
- AniAva.AnimationThreadHandle = NULL;
-}
static int _AniAva_SortAvatarInfo(void * first, void * last)
{
diff --git a/plugins/Clist_modern/src/modern_awaymsg.cpp b/plugins/Clist_modern/src/modern_awaymsg.cpp
index a03e61bec2..4c6241c18e 100644
--- a/plugins/Clist_modern/src/modern_awaymsg.cpp
+++ b/plugins/Clist_modern/src/modern_awaymsg.cpp
@@ -53,7 +53,6 @@ static DWORD amRequestTick = 0;
static int amAddHandleToChain(HANDLE hContact);
static HANDLE amGetCurrentChain();
-static int amThreadProc(HWND hwnd);
/*
* Add contact handle to requests queue
@@ -116,7 +115,7 @@ static HANDLE amGetCurrentChain()
/*
* Tread sub to ask protocol to retrieve away message
*/
-static int amThreadProc(HWND hwnd)
+static unsigned __stdcall amThreadProc(void *)
{
DWORD time;
HANDLE hContact;
@@ -127,14 +126,11 @@ static int amThreadProc(HWND hwnd)
while (!MirandaExiting())
{
hContact = amGetCurrentChain();
- while (hContact)
- {
+ while (hContact) {
time = GetTickCount();
- if ((time-amRequestTick) < AMASKPERIOD)
- {
+ if ((time-amRequestTick) < AMASKPERIOD) {
SleepEx(AMASKPERIOD-(time-amRequestTick)+10, TRUE);
- if (MirandaExiting())
- {
+ if (MirandaExiting()) {
g_dwAwayMsgThreadID = 0;
return 0;
}
@@ -144,8 +140,7 @@ static int amThreadProc(HWND hwnd)
Sync(CLUI_SyncGetPDNCE, (WPARAM) 0, (LPARAM)&dnce);
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)
- {
+ if ( !ACK) {
ACKDATA ack;
ack.hContact = hContact;
ack.type = ACKTYPE_AWAYMSG;
@@ -159,18 +154,16 @@ static int amThreadProc(HWND hwnd)
CListSettings_FreeCacheItemData(&dnce);
amRequestTick = time;
hContact = amGetCurrentChain();
- if (hContact)
- {
+ if (hContact) {
DWORD i=0;
- do
- {
+ do {
i++;
SleepEx(50, TRUE);
- } while (i < AMASKPERIOD/50 && !MirandaExiting());
+ }
+ while (i < AMASKPERIOD/50 && !MirandaExiting());
}
else break;
- if (MirandaExiting())
- {
+ if (MirandaExiting()) {
g_dwAwayMsgThreadID = 0;
return 0;
}
@@ -216,7 +209,7 @@ void InitAwayMsgModule()
{
InitializeCriticalSection(&amLockChain);
hamProcessEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
- g_dwAwayMsgThreadID = (DWORD)mir_forkthread((pThreadFunc)amThreadProc,0);
+ mir_forkthreadex(amThreadProc, 0, &g_dwAwayMsgThreadID);
}
void UninitAwayMsgModule()
diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp
index f1e57fa4fc..cb072264db 100644
--- a/plugins/Clist_modern/src/modern_clui.cpp
+++ b/plugins/Clist_modern/src/modern_clui.cpp
@@ -516,8 +516,7 @@ static BOOL CLUI_WaitThreadsCompletion(HWND hwnd)
g_CluiData.mutexPaintLock ||
g_dwAwayMsgThreadID ||
g_dwGetTextAsyncThreadID ||
- g_dwSmoothAnimationThreadID ||
- g_dwFillFontListThreadID) && !Miranda_Terminated())
+ g_dwSmoothAnimationThreadID) && !Miranda_Terminated())
{
TRACE("Waiting threads");
TRACEVAR("g_mutex_nCalcRowHeightLock: %x",g_mutex_nCalcRowHeightLock);
@@ -525,7 +524,7 @@ static BOOL CLUI_WaitThreadsCompletion(HWND hwnd)
TRACEVAR("g_dwAwayMsgThreadID: %x",g_dwAwayMsgThreadID);
TRACEVAR("g_dwGetTextAsyncThreadID: %x",g_dwGetTextAsyncThreadID);
TRACEVAR("g_dwSmoothAnimationThreadID: %x",g_dwSmoothAnimationThreadID);
- TRACEVAR("g_dwFillFontListThreadID: %x",g_dwFillFontListThreadID);
+
bEntersCount++;
SleepEx(10, TRUE);
return TRUE;
@@ -1293,11 +1292,6 @@ int CLUI_SyncGetShortData(WPARAM wParam, LPARAM lParam)
return ClcGetShortData(dat,(struct SHORTDATA *)lParam);
}
-int CLUI_SyncSmoothAnimation(WPARAM wParam, LPARAM lParam)
-{
- return CLUI_SmoothAlphaThreadTransition((HWND)lParam);
-}
-
int CLUI_IconsChanged(WPARAM wParam,LPARAM lParam)
{
if (MirandaExiting())
@@ -1451,33 +1445,37 @@ int CLUI_SizingOnBorder(POINT pt, int PerformSize)
}
return SCF_NONE;
}
-int CLUI_SyncSmoothAnimation(WPARAM wParam, LPARAM lParam);
-static void CLUI_SmoothAnimationThreadProc(HWND hwnd)
+
+static int CLUI_SyncSmoothAnimation(WPARAM wParam, LPARAM lParam)
{
- // return;
- if ( !mutex_bAnimationInProgress)
- {
+ return CLUI_SmoothAlphaThreadTransition((HWND)lParam);
+}
+
+static unsigned __stdcall CLUI_SmoothAnimationThreadProc(void *param)
+{
+ if ( !mutex_bAnimationInProgress) {
g_dwSmoothAnimationThreadID = 0;
- return; /// Should be some locked to avoid painting against contact deletion.
+ return 0; /// Should be some locked to avoid painting against contact deletion.
}
- do
- {
- if ( !g_mutex_bLockUpdating)
- {
+
+ do {
+ if ( !g_mutex_bLockUpdating) {
if ( !MirandaExiting())
- Sync(CLUI_SyncSmoothAnimation, 0, (LPARAM)hwnd );
+ Sync(CLUI_SyncSmoothAnimation, 0, (LPARAM)param);
+
SleepEx(20, TRUE);
- if (MirandaExiting())
- {
+ if (MirandaExiting()) {
g_dwSmoothAnimationThreadID = 0;
- return;
+ return 0;
}
}
else SleepEx(0, TRUE);
- } while (mutex_bAnimationInProgress);
+ }
+ while (mutex_bAnimationInProgress);
+
g_dwSmoothAnimationThreadID = 0;
- return;
+ return 0;
}
static int CLUI_SmoothAlphaThreadTransition(HWND hwnd)
@@ -1551,14 +1549,13 @@ int CLUI_SmoothAlphaTransition(HWND hwnd, BYTE GoalAlpha, BOOL wParam)
}
return 0;
}
- if (mutex_bShowHideCalledFromAnimation) return 0;
- if (wParam != 2) //not from timer
- {
+ if (mutex_bShowHideCalledFromAnimation)
+ return 0;
+
+ if (wParam != 2) { //not from timer
bAlphaEnd = GoalAlpha;
- if ( !mutex_bAnimationInProgress)
- {
- if ((!IsWindowVisible(hwnd) || g_CluiData.bCurrentAlpha == 0) && bAlphaEnd>0 )
- {
+ if ( !mutex_bAnimationInProgress) {
+ if ((!IsWindowVisible(hwnd) || g_CluiData.bCurrentAlpha == 0) && bAlphaEnd > 0) {
mutex_bShowHideCalledFromAnimation = 1;
CLUI_ShowWindowMod(pcli->hwndContactList,SW_SHOWNA);
Sync(CLUIFrames_OnShowHide, hwnd,SW_SHOW);
@@ -1566,47 +1563,37 @@ int CLUI_SmoothAlphaTransition(HWND hwnd, BYTE GoalAlpha, BOOL wParam)
g_CluiData.bCurrentAlpha = 1;
ske_UpdateWindowImage();
}
- if (IsWindowVisible(hwnd) && !g_dwSmoothAnimationThreadID)
- {
+ if (IsWindowVisible(hwnd) && !g_dwSmoothAnimationThreadID) {
mutex_bAnimationInProgress = 1;
if (g_CluiData.fSmoothAnimation)
- g_dwSmoothAnimationThreadID = (DWORD)mir_forkthread((pThreadFunc)CLUI_SmoothAnimationThreadProc,pcli->hwndContactList);
-
+ mir_forkthreadex(CLUI_SmoothAnimationThreadProc, pcli->hwndContactList, &g_dwSmoothAnimationThreadID);
}
}
}
- {
- int step;
- int a;
- step = (g_CluiData.bCurrentAlpha>bAlphaEnd)?-1*ANIMATION_STEP:ANIMATION_STEP;
- a = g_CluiData.bCurrentAlpha+step;
- if ((step >= 0 && a >= bAlphaEnd) || (step <= 0 && a <= bAlphaEnd) || g_CluiData.bCurrentAlpha == bAlphaEnd || !g_CluiData.fSmoothAnimation) //stop animation;
- {
- KillTimer(hwnd,TM_SMOTHALPHATRANSITION);
- mutex_bAnimationInProgress = 0;
- if (bAlphaEnd == 0)
- {
- g_CluiData.bCurrentAlpha = 1;
- ske_UpdateWindowImage();
- mutex_bShowHideCalledFromAnimation = 1;
- CLUI_ShowWindowMod(pcli->hwndContactList,0);
- Sync(CLUIFrames_OnShowHide, pcli->hwndContactList,0);
- mutex_bShowHideCalledFromAnimation = 0;
- g_CluiData.bCurrentAlpha = 0;
- }
- else
- {
- g_CluiData.bCurrentAlpha = bAlphaEnd;
- ske_UpdateWindowImage();
- }
+ int step = (g_CluiData.bCurrentAlpha>bAlphaEnd) ? -1*ANIMATION_STEP : ANIMATION_STEP;
+ int a = g_CluiData.bCurrentAlpha+step;
+ if ((step >= 0 && a >= bAlphaEnd) || (step <= 0 && a <= bAlphaEnd) || g_CluiData.bCurrentAlpha == bAlphaEnd || !g_CluiData.fSmoothAnimation) { //stop animation;
+ KillTimer(hwnd,TM_SMOTHALPHATRANSITION);
+ mutex_bAnimationInProgress = 0;
+ if (bAlphaEnd == 0) {
+ g_CluiData.bCurrentAlpha = 1;
+ ske_UpdateWindowImage();
+ mutex_bShowHideCalledFromAnimation = 1;
+ CLUI_ShowWindowMod(pcli->hwndContactList,0);
+ Sync(CLUIFrames_OnShowHide, pcli->hwndContactList,0);
+ mutex_bShowHideCalledFromAnimation = 0;
+ g_CluiData.bCurrentAlpha = 0;
}
- else
- {
- g_CluiData.bCurrentAlpha = a;
+ else {
+ g_CluiData.bCurrentAlpha = bAlphaEnd;
ske_UpdateWindowImage();
}
}
+ else {
+ g_CluiData.bCurrentAlpha = a;
+ ske_UpdateWindowImage();
+ }
return 0;
}
diff --git a/plugins/Clist_modern/src/modern_gettextasync.cpp b/plugins/Clist_modern/src/modern_gettextasync.cpp
index 7ec2ca1c3c..1244e8b49c 100644
--- a/plugins/Clist_modern/src/modern_gettextasync.cpp
+++ b/plugins/Clist_modern/src/modern_gettextasync.cpp
@@ -76,7 +76,7 @@ static BOOL gtaGetItem(GTACHAINITEM * mpChain)
return FALSE;
}
-static int gtaThreadProc(void * lpParam)
+static unsigned __stdcall gtaThreadProc(void * lpParam)
{
HWND hwnd = pcli->hwndContactList;
struct SHORTDATA data = {0};
@@ -178,7 +178,7 @@ void InitCacheAsync()
{
InitializeCriticalSection(&gtaCS);
hgtaWakeupEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
- g_dwGetTextAsyncThreadID = (DWORD)mir_forkthread((pThreadFunc)gtaThreadProc,0);
+ mir_forkthreadex(gtaThreadProc, 0, &g_dwGetTextAsyncThreadID);
HookEvent(ME_SYSTEM_PRESHUTDOWN, gtaOnModulesUnload);
}