source code repository of yamy
Revision | bacf1d7174ab8d977805698c3879543954a311e2 (tree) |
---|---|
Time | 2009-09-16 08:31:02 |
Author | U-i7\gimy <gimy@user...> |
Commiter | U-i7\gimy |
post WM_NULL to attached threads on yamy exit to unmap mayu{32,64}.dll
@@ -38,7 +38,7 @@ restart: | ||
38 | 38 | |
39 | 39 | // erase dead thread |
40 | 40 | if (!m_detachedThreadIds.empty()) { |
41 | - for (DetachedThreadIds::iterator i = m_detachedThreadIds.begin(); | |
41 | + for (ThreadIds::iterator i = m_detachedThreadIds.begin(); | |
42 | 42 | i != m_detachedThreadIds.end(); i ++) { |
43 | 43 | FocusOfThreads::iterator j = m_focusOfThreads.find((*i)); |
44 | 44 | if (j != m_focusOfThreads.end()) { |
@@ -1282,6 +1282,11 @@ void Engine::stop() { | ||
1282 | 1282 | |
1283 | 1283 | CHECK_TRUE( CloseHandle(m_readEvent) ); |
1284 | 1284 | m_readEvent = NULL; |
1285 | + | |
1286 | + for (ThreadIds::iterator i = m_attachedThreadIds.begin(); | |
1287 | + i != m_attachedThreadIds.end(); i++) { | |
1288 | + PostThreadMessage(*i, WM_NULL, 0, 0); | |
1289 | + } | |
1285 | 1290 | } |
1286 | 1291 | |
1287 | 1292 |
@@ -1478,7 +1483,7 @@ bool Engine::setFocus(HWND i_hwndFocus, DWORD i_threadId, | ||
1478 | 1483 | |
1479 | 1484 | // remove newly created thread's id from m_detachedThreadIds |
1480 | 1485 | if (!m_detachedThreadIds.empty()) { |
1481 | - DetachedThreadIds::iterator i; | |
1486 | + ThreadIds::iterator i; | |
1482 | 1487 | bool retry; |
1483 | 1488 | do { |
1484 | 1489 | retry = false; |
@@ -1580,10 +1585,20 @@ bool Engine::syncNotify() { | ||
1580 | 1585 | } |
1581 | 1586 | |
1582 | 1587 | |
1588 | +// thread attach notify | |
1589 | +bool Engine::threadAttachNotify(DWORD i_threadId) { | |
1590 | + Acquire a(&m_cs); | |
1591 | + m_attachedThreadIds.push_back(i_threadId); | |
1592 | + return true; | |
1593 | +} | |
1594 | + | |
1595 | + | |
1583 | 1596 | // thread detach notify |
1584 | 1597 | bool Engine::threadDetachNotify(DWORD i_threadId) { |
1585 | 1598 | Acquire a(&m_cs); |
1586 | 1599 | m_detachedThreadIds.push_back(i_threadId); |
1600 | + m_attachedThreadIds.erase(remove(m_attachedThreadIds.begin(), m_attachedThreadIds.end(), i_threadId), | |
1601 | + m_attachedThreadIds.end()); | |
1587 | 1602 | return true; |
1588 | 1603 | } |
1589 | 1604 |
@@ -59,7 +59,7 @@ private: | ||
59 | 59 | }; |
60 | 60 | typedef std::map<DWORD /*ThreadId*/, FocusOfThread> FocusOfThreads; /// |
61 | 61 | |
62 | - typedef std::list<DWORD /*ThreadId*/> DetachedThreadIds; /// | |
62 | + typedef std::list<DWORD /*ThreadId*/> ThreadIds; /// | |
63 | 63 | |
64 | 64 | /// current status in generateKeyboardEvents |
65 | 65 | class Current |
@@ -235,7 +235,8 @@ private: | ||
235 | 235 | FocusOfThread * volatile m_currentFocusOfThread; /// |
236 | 236 | FocusOfThread m_globalFocus; /// |
237 | 237 | HWND m_hwndFocus; /// current focus window |
238 | - DetachedThreadIds m_detachedThreadIds; /// | |
238 | + ThreadIds m_attachedThreadIds; /// | |
239 | + ThreadIds m_detachedThreadIds; /// | |
239 | 240 | |
240 | 241 | // for functions |
241 | 242 | KeymapPtrList m_keymapPrefixHistory; /// for &KeymapPrevPrefix |
@@ -594,6 +595,9 @@ public: | ||
594 | 595 | /// sync |
595 | 596 | bool syncNotify(); |
596 | 597 | |
598 | + /// thread attach notify | |
599 | + bool threadAttachNotify(DWORD i_threadId); | |
600 | + | |
597 | 601 | /// thread detach notify |
598 | 602 | bool threadDetachNotify(DWORD i_threadId); |
599 | 603 |
@@ -100,6 +100,7 @@ static void notifyLog(_TCHAR *i_msg); | ||
100 | 100 | static bool mapHookData(bool i_isYamy); |
101 | 101 | static void unmapHookData(); |
102 | 102 | static bool initialize(bool i_isYamy); |
103 | +static bool notify(void *i_data, size_t i_dataSize); | |
103 | 104 | |
104 | 105 | |
105 | 106 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
@@ -160,6 +161,12 @@ bool initialize(bool i_isYamy) | ||
160 | 161 | g.m_WM_MAYU_MESSAGE = |
161 | 162 | RegisterWindowMessage(addSessionId(WM_MAYU_MESSAGE_NAME).c_str()); |
162 | 163 | g.m_hwndTaskTray = g_hookData->m_hwndTaskTray; |
164 | + if (!i_isYamy) { | |
165 | + NotifyThreadAttach ntd; | |
166 | + ntd.m_type = Notify::Type_threadAttach; | |
167 | + ntd.m_threadId = GetCurrentThreadId(); | |
168 | + notify(&ntd, sizeof(ntd)); | |
169 | + } | |
163 | 170 | g.m_isInitialized = true; |
164 | 171 | return true; |
165 | 172 | } |
@@ -252,7 +259,7 @@ static void unmapHookData() | ||
252 | 259 | |
253 | 260 | |
254 | 261 | /// notify |
255 | -DllExport bool notify(void *i_data, size_t i_dataSize) | |
262 | +bool notify(void *i_data, size_t i_dataSize) | |
256 | 263 | { |
257 | 264 | COPYDATASTRUCT cd; |
258 | 265 | #ifdef MAYU64 |
@@ -35,6 +35,7 @@ struct Notify { | ||
35 | 35 | Type_name, /// NotifySetFocus |
36 | 36 | Type_lockState, /// NotifyLockState |
37 | 37 | Type_sync, /// Notify |
38 | + Type_threadAttach, /// NotifyThreadAttach | |
38 | 39 | Type_threadDetach, /// NotifyThreadDetach |
39 | 40 | Type_command64, /// NotifyCommand64 |
40 | 41 | Type_command32, /// NotifyCommand32 |
@@ -67,6 +68,12 @@ struct NotifyLockState : public Notify { | ||
67 | 68 | |
68 | 69 | |
69 | 70 | /// |
71 | +struct NotifyThreadAttach : public Notify { | |
72 | + DWORD m_threadId; /// | |
73 | +}; | |
74 | + | |
75 | + | |
76 | +/// | |
70 | 77 | struct NotifyThreadDetach : public Notify { |
71 | 78 | DWORD m_threadId; /// |
72 | 79 | }; |
@@ -224,6 +224,12 @@ private: | ||
224 | 224 | break; |
225 | 225 | } |
226 | 226 | |
227 | + case Notify::Type_threadAttach: { | |
228 | + NotifyThreadAttach *n = (NotifyThreadAttach *)cd->lpData; | |
229 | + m_engine.threadAttachNotify(n->m_threadId); | |
230 | + break; | |
231 | + } | |
232 | + | |
227 | 233 | case Notify::Type_threadDetach: { |
228 | 234 | NotifyThreadDetach *n = (NotifyThreadDetach *)cd->lpData; |
229 | 235 | m_engine.threadDetachNotify(n->m_threadId); |
@@ -1177,18 +1183,6 @@ public: | ||
1177 | 1183 | |
1178 | 1184 | /// |
1179 | 1185 | ~Mayu() { |
1180 | - CancelIo(m_hNotifyMailslot); | |
1181 | - SleepEx(0, TRUE); | |
1182 | - CloseHandle(m_hNotifyMailslot); | |
1183 | - CloseHandle(m_hNotifyEvent); | |
1184 | - ReleaseMutex(m_mutex); | |
1185 | - WaitForSingleObject(m_mutex, INFINITE); | |
1186 | - // first, detach log from edit control to avoid deadlock | |
1187 | - m_log.detach(); | |
1188 | -#ifdef LOG_TO_FILE | |
1189 | - m_logFile.close(); | |
1190 | -#endif // LOG_TO_FILE | |
1191 | - | |
1192 | 1186 | // stop notify from mayu.dll |
1193 | 1187 | g_hookData->m_hwndTaskTray = NULL; |
1194 | 1188 | CHECK_FALSE( uninstallMessageHook() ); |
@@ -1201,10 +1195,18 @@ public: | ||
1201 | 1195 | } |
1202 | 1196 | CloseHandle(m_hMutexYamyd); |
1203 | 1197 | #endif // _WIN64 |
1204 | - if (!(m_sessionState & SESSION_END_QUERIED)) { | |
1205 | - DWORD_PTR result; | |
1206 | - SendMessageTimeout(HWND_BROADCAST, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 3000, &result); | |
1207 | - } | |
1198 | + | |
1199 | + CancelIo(m_hNotifyMailslot); | |
1200 | + SleepEx(0, TRUE); | |
1201 | + CloseHandle(m_hNotifyMailslot); | |
1202 | + CloseHandle(m_hNotifyEvent); | |
1203 | + ReleaseMutex(m_mutex); | |
1204 | + WaitForSingleObject(m_mutex, INFINITE); | |
1205 | + // first, detach log from edit control to avoid deadlock | |
1206 | + m_log.detach(); | |
1207 | +#ifdef LOG_TO_FILE | |
1208 | + m_logFile.close(); | |
1209 | +#endif // LOG_TO_FILE | |
1208 | 1210 | |
1209 | 1211 | // destroy windows |
1210 | 1212 | CHECK_TRUE( DestroyWindow(m_hwndVersion) ); |
@@ -1223,6 +1225,11 @@ public: | ||
1223 | 1225 | // stop keyboard handler thread |
1224 | 1226 | m_engine.stop(); |
1225 | 1227 | |
1228 | + if (!(m_sessionState & SESSION_END_QUERIED)) { | |
1229 | + DWORD_PTR result; | |
1230 | + SendMessageTimeout(HWND_BROADCAST, WM_NULL, 0, 0, 0, 3000, &result); | |
1231 | + } | |
1232 | + | |
1226 | 1233 | // remove setting; |
1227 | 1234 | delete m_setting; |
1228 | 1235 | } |
@@ -14,9 +14,8 @@ int WINAPI _tWinMain(HINSTANCE /* i_hInstance */, HINSTANCE /* i_hPrevInstance * | ||
14 | 14 | |
15 | 15 | // wait for master process exit |
16 | 16 | WaitForSingleObject(mutex, INFINITE); |
17 | - ReleaseMutex(mutex); | |
18 | - | |
19 | 17 | CHECK_FALSE( uninstallMessageHook() ); |
18 | + ReleaseMutex(mutex); | |
20 | 19 | } |
21 | 20 | |
22 | 21 | return 0; |