diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-23 19:16:57 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-23 19:16:57 +0000 |
commit | dcb6bcdd69443e229f1ead5ee4a6c2a4622890f5 (patch) | |
tree | 295ec22cdd4e216087c29d6fbab6ba8921f007b0 /src/mir_core/modules.cpp | |
parent | 5c794a21c8e0c943e69b08a9ba52064149d663a6 (diff) |
more correct variant of tls
git-svn-id: http://svn.miranda-ng.org/main/trunk@1135 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core/modules.cpp')
-rw-r--r-- | src/mir_core/modules.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/mir_core/modules.cpp b/src/mir_core/modules.cpp index 8372e966c3..794af53e74 100644 --- a/src/mir_core/modules.cpp +++ b/src/mir_core/modules.cpp @@ -82,6 +82,16 @@ static THook *pLastHook = NULL; /////////////////////////////////////////////////////////////////////////////////////////
+__forceinline HANDLE getThreadEvent()
+{
+ HANDLE pData = (HANDLE)TlsGetValue(mir_tls);
+ if (pData == NULL) {
+ pData = CreateEvent(NULL, FALSE, FALSE, NULL);
+ TlsSetValue(mir_tls, pData);
+ }
+ return pData;
+}
+
static int QueueMainThread(PAPCFUNC pFunc, void* pParam, HANDLE hDoneEvent)
{
int result = QueueUserAPC(pFunc, hMainThread, (ULONG_PTR)pParam);
@@ -256,12 +266,8 @@ MIR_CORE_DLL(int) NotifyEventHooks(HANDLE hEvent, WPARAM wParam, LPARAM lParam) if ( GetCurrentThreadId() == mainThreadId)
return CallHookSubscribers((THook*)hEvent, wParam, lParam);
- MThreadData* pData = (MThreadData*)TlsGetValue(mir_tls);
- if (pData == NULL)
- return -1;
-
mir_ptr<THookToMainThreadItem> item;
- item->hDoneEvent = pData->m_hEvent;
+ item->hDoneEvent = getThreadEvent();
item->hook = (THook*)hEvent;
item->wParam = wParam;
item->lParam = lParam;
@@ -530,15 +536,11 @@ MIR_CORE_DLL(INT_PTR) CallServiceSync(const char *name, WPARAM wParam, LPARAM lP if (GetCurrentThreadId() == mainThreadId)
return CallService(name, wParam, lParam);
- MThreadData* pData = (MThreadData*)TlsGetValue(mir_tls);
- if (pData == NULL)
- return CALLSERVICE_NOTFOUND;
-
mir_ptr<TServiceToMainThreadItem> item;
item->wParam = wParam;
item->lParam = lParam;
item->name = name;
- item->hDoneEvent = pData->m_hEvent;
+ item->hDoneEvent = getThreadEvent();
QueueMainThread(CallServiceToMainAPCFunc, item, item->hDoneEvent);
return item->result;
}
|