From c93d3fe5ed2eeddbc67ec04217508fee545a9452 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 23 Jun 2013 15:45:34 +0000 Subject: end of experimental hand-made APC perversions in clist_modern git-svn-id: http://svn.miranda-ng.org/main/trunk@5099 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/src/hdr/modern_sync.h | 3 - plugins/Clist_modern/src/modern_sync.cpp | 129 +++++++++++------------------ 2 files changed, 48 insertions(+), 84 deletions(-) (limited to 'plugins') diff --git a/plugins/Clist_modern/src/hdr/modern_sync.h b/plugins/Clist_modern/src/hdr/modern_sync.h index 4f7010ae08..4f871b6ed4 100644 --- a/plugins/Clist_modern/src/hdr/modern_sync.h +++ b/plugins/Clist_modern/src/hdr/modern_sync.h @@ -7,9 +7,6 @@ typedef INT_PTR (*PSYNCCALLBACKPROC)(WPARAM,LPARAM); int SyncCall(void * vproc, int count, ... ); -int SyncCallProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, CRITICAL_SECTION * cs = NULL ); -HRESULT SyncCallWinProcProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, int& nReturn ); -HRESULT SyncCallAPCProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, int& hReturn ); LRESULT SyncOnWndProcCall(WPARAM wParam ); diff --git a/plugins/Clist_modern/src/modern_sync.cpp b/plugins/Clist_modern/src/modern_sync.cpp index 35fe8d64f3..5f6901fe18 100644 --- a/plugins/Clist_modern/src/modern_sync.cpp +++ b/plugins/Clist_modern/src/modern_sync.cpp @@ -1,22 +1,6 @@ #include "hdr/modern_commonheaders.h" #include "hdr/modern_sync.h" -struct SYNCCALLITEM -{ - WPARAM wParam; - LPARAM lParam; - int nResult; - HANDLE hDoneEvent; - PSYNCCALLBACKPROC pfnProc; -}; - -static void CALLBACK _SyncCallerUserAPCProc(void* param) -{ - SYNCCALLITEM* item = (SYNCCALLITEM*)param; - item->nResult = item->pfnProc(item->wParam, item->lParam); - SetEvent(item->hDoneEvent); -} - static INT_PTR SyncCaller(WPARAM proc, LPARAM lParam) { typedef int (*P0PARAMFUNC)(); @@ -46,51 +30,18 @@ static INT_PTR SyncCaller(WPARAM proc, LPARAM lParam) return 0; } -int SyncCall(void * vproc, int count, ... ) -{ - LPARAM params[5]; - va_list va; - int i; - params[0] = (LPARAM)count; - va_start(va, count); - for (i=0; i < count && i < SIZEOF(params)-1; i++) - params[i+1] = va_arg(va,LPARAM); - - va_end(va); - return SyncCallProxy(SyncCaller, (WPARAM)vproc, (LPARAM) params); -} +///////////////////////////////////////////////////////////////////////////////////////// -int SyncCallProxy(PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, CRITICAL_SECTION * cs /*= NULL */) -{ - SYNCCALLITEM item = {0}; - - int nReturn = 0; - - if ( cs != NULL ) { - if ( !fnTryEnterCriticalSection ) { // for poor OSes like Win98 - EnterCriticalSection( cs ); - int result = pfnProc( wParam, lParam); - LeaveCriticalSection( cs ); - return result; - } - - if ( fnTryEnterCriticalSection( cs )) { //simple call (Fastest) - int result = pfnProc(wParam,lParam); - LeaveCriticalSection( cs ); - return result; - } - else { //Window SendMessage Call(Middle) - if ( SyncCallWinProcProxy( pfnProc, wParam, lParam, nReturn ) == S_OK) - return nReturn; - } - } - if ( SyncCallAPCProxy( pfnProc, wParam, lParam, nReturn ) == S_OK) - return nReturn; - - return NULL; -} +struct SYNCCALLITEM +{ + WPARAM wParam; + LPARAM lParam; + int nResult; + HANDLE hDoneEvent; + PSYNCCALLBACKPROC pfnProc; +}; -HRESULT SyncCallWinProcProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, int& nReturn ) +static HRESULT SyncCallWinProcProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, int& nReturn ) { nReturn = 0; if (pcli->hwndContactList == NULL ) @@ -104,35 +55,37 @@ HRESULT SyncCallWinProcProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM l return S_OK; } -HRESULT SyncCallAPCProxy( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam, int& hReturn ) +static void CALLBACK _SyncCallerUserAPCProc(void* param) { - hReturn = 0; + SYNCCALLITEM* item = (SYNCCALLITEM*)param; + item->nResult = item->pfnProc(item->wParam, item->lParam); + SetEvent(item->hDoneEvent); +} +static int SyncCallAPCProxy(PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam) +{ if (pfnProc == NULL) - return E_FAIL; + return 0; - if (GetCurrentThreadId() != g_dwMainThreadID) { - SYNCCALLITEM item = {0}; - item.wParam = wParam; - item.lParam = lParam; - item.pfnProc = pfnProc; - item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - - CallFunctionAsync(_SyncCallerUserAPCProc, &item); - - WaitForSingleObject(item.hDoneEvent, INFINITE); - CloseHandle(item.hDoneEvent); + if (GetCurrentThreadId() == g_dwMainThreadID) + return pfnProc(wParam, lParam); - hReturn = item.nResult; - - return S_OK; - } - /* else */ + SYNCCALLITEM item; + item.wParam = wParam; + item.lParam = lParam; + item.pfnProc = pfnProc; + item.nResult = 0; + item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - hReturn = pfnProc(wParam, lParam); - return S_OK; + CallFunctionAsync(_SyncCallerUserAPCProc, &item); + + WaitForSingleObject(item.hDoneEvent, INFINITE); + CloseHandle(item.hDoneEvent); + return item.nResult; } +///////////////////////////////////////////////////////////////////////////////////////// + LRESULT SyncOnWndProcCall(WPARAM wParam ) { SYNCCALLITEM *psci = (SYNCCALLITEM *)wParam; @@ -143,5 +96,19 @@ LRESULT SyncOnWndProcCall(WPARAM wParam ) int DoCall( PSYNCCALLBACKPROC pfnProc, WPARAM wParam, LPARAM lParam) { - return SyncCallProxy( pfnProc, 0, lParam); + return SyncCallAPCProxy(pfnProc, 0, lParam); +} + +int SyncCall(void * vproc, int count, ... ) +{ + LPARAM params[5]; + va_list va; + int i; + params[0] = (LPARAM)count; + va_start(va, count); + for (i=0; i < count && i < SIZEOF(params)-1; i++) + params[i+1] = va_arg(va,LPARAM); + + va_end(va); + return SyncCallAPCProxy(SyncCaller, (WPARAM)vproc, (LPARAM) params); } -- cgit v1.2.3