summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-06-23 15:45:34 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-06-23 15:45:34 +0000
commitc93d3fe5ed2eeddbc67ec04217508fee545a9452 (patch)
tree7bb74d0f305a9d55a7293f84a22386878711e07d /plugins
parent17fe90759ceffe3566ef39e4d184409106b35609 (diff)
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
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Clist_modern/src/hdr/modern_sync.h3
-rw-r--r--plugins/Clist_modern/src/modern_sync.cpp129
2 files changed, 48 insertions, 84 deletions
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);
}