• R/O
  • HTTP
  • SSH
  • HTTPS

yamy: コミット

source code repository of yamy


コミットメタ情報

リビジョンbacf1d7174ab8d977805698c3879543954a311e2 (tree)
日時2009-09-16 08:31:02
作者U-i7\gimy <gimy@user...>
コミッターU-i7\gimy

ログメッセージ

post WM_NULL to attached threads on yamy exit to unmap mayu{32,64}.dll

変更サマリ

差分

--- a/engine.cpp
+++ b/engine.cpp
@@ -38,7 +38,7 @@ restart:
3838
3939 // erase dead thread
4040 if (!m_detachedThreadIds.empty()) {
41- for (DetachedThreadIds::iterator i = m_detachedThreadIds.begin();
41+ for (ThreadIds::iterator i = m_detachedThreadIds.begin();
4242 i != m_detachedThreadIds.end(); i ++) {
4343 FocusOfThreads::iterator j = m_focusOfThreads.find((*i));
4444 if (j != m_focusOfThreads.end()) {
@@ -1282,6 +1282,11 @@ void Engine::stop() {
12821282
12831283 CHECK_TRUE( CloseHandle(m_readEvent) );
12841284 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+ }
12851290 }
12861291
12871292
@@ -1478,7 +1483,7 @@ bool Engine::setFocus(HWND i_hwndFocus, DWORD i_threadId,
14781483
14791484 // remove newly created thread's id from m_detachedThreadIds
14801485 if (!m_detachedThreadIds.empty()) {
1481- DetachedThreadIds::iterator i;
1486+ ThreadIds::iterator i;
14821487 bool retry;
14831488 do {
14841489 retry = false;
@@ -1580,10 +1585,20 @@ bool Engine::syncNotify() {
15801585 }
15811586
15821587
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+
15831596 // thread detach notify
15841597 bool Engine::threadDetachNotify(DWORD i_threadId) {
15851598 Acquire a(&m_cs);
15861599 m_detachedThreadIds.push_back(i_threadId);
1600+ m_attachedThreadIds.erase(remove(m_attachedThreadIds.begin(), m_attachedThreadIds.end(), i_threadId),
1601+ m_attachedThreadIds.end());
15871602 return true;
15881603 }
15891604
--- a/engine.h
+++ b/engine.h
@@ -59,7 +59,7 @@ private:
5959 };
6060 typedef std::map<DWORD /*ThreadId*/, FocusOfThread> FocusOfThreads; ///
6161
62- typedef std::list<DWORD /*ThreadId*/> DetachedThreadIds; ///
62+ typedef std::list<DWORD /*ThreadId*/> ThreadIds; ///
6363
6464 /// current status in generateKeyboardEvents
6565 class Current
@@ -235,7 +235,8 @@ private:
235235 FocusOfThread * volatile m_currentFocusOfThread; ///
236236 FocusOfThread m_globalFocus; ///
237237 HWND m_hwndFocus; /// current focus window
238- DetachedThreadIds m_detachedThreadIds; ///
238+ ThreadIds m_attachedThreadIds; ///
239+ ThreadIds m_detachedThreadIds; ///
239240
240241 // for functions
241242 KeymapPtrList m_keymapPrefixHistory; /// for &amp;KeymapPrevPrefix
@@ -594,6 +595,9 @@ public:
594595 /// sync
595596 bool syncNotify();
596597
598+ /// thread attach notify
599+ bool threadAttachNotify(DWORD i_threadId);
600+
597601 /// thread detach notify
598602 bool threadDetachNotify(DWORD i_threadId);
599603
--- a/hook.cpp
+++ b/hook.cpp
@@ -100,6 +100,7 @@ static void notifyLog(_TCHAR *i_msg);
100100 static bool mapHookData(bool i_isYamy);
101101 static void unmapHookData();
102102 static bool initialize(bool i_isYamy);
103+static bool notify(void *i_data, size_t i_dataSize);
103104
104105
105106 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -160,6 +161,12 @@ bool initialize(bool i_isYamy)
160161 g.m_WM_MAYU_MESSAGE =
161162 RegisterWindowMessage(addSessionId(WM_MAYU_MESSAGE_NAME).c_str());
162163 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+ }
163170 g.m_isInitialized = true;
164171 return true;
165172 }
@@ -252,7 +259,7 @@ static void unmapHookData()
252259
253260
254261 /// notify
255-DllExport bool notify(void *i_data, size_t i_dataSize)
262+bool notify(void *i_data, size_t i_dataSize)
256263 {
257264 COPYDATASTRUCT cd;
258265 #ifdef MAYU64
--- a/hook.h
+++ b/hook.h
@@ -35,6 +35,7 @@ struct Notify {
3535 Type_name, /// NotifySetFocus
3636 Type_lockState, /// NotifyLockState
3737 Type_sync, /// Notify
38+ Type_threadAttach, /// NotifyThreadAttach
3839 Type_threadDetach, /// NotifyThreadDetach
3940 Type_command64, /// NotifyCommand64
4041 Type_command32, /// NotifyCommand32
@@ -67,6 +68,12 @@ struct NotifyLockState : public Notify {
6768
6869
6970 ///
71+struct NotifyThreadAttach : public Notify {
72+ DWORD m_threadId; ///
73+};
74+
75+
76+///
7077 struct NotifyThreadDetach : public Notify {
7178 DWORD m_threadId; ///
7279 };
--- a/mayu.cpp
+++ b/mayu.cpp
@@ -224,6 +224,12 @@ private:
224224 break;
225225 }
226226
227+ case Notify::Type_threadAttach: {
228+ NotifyThreadAttach *n = (NotifyThreadAttach *)cd->lpData;
229+ m_engine.threadAttachNotify(n->m_threadId);
230+ break;
231+ }
232+
227233 case Notify::Type_threadDetach: {
228234 NotifyThreadDetach *n = (NotifyThreadDetach *)cd->lpData;
229235 m_engine.threadDetachNotify(n->m_threadId);
@@ -1177,18 +1183,6 @@ public:
11771183
11781184 ///
11791185 ~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-
11921186 // stop notify from mayu.dll
11931187 g_hookData->m_hwndTaskTray = NULL;
11941188 CHECK_FALSE( uninstallMessageHook() );
@@ -1201,10 +1195,18 @@ public:
12011195 }
12021196 CloseHandle(m_hMutexYamyd);
12031197 #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
12081210
12091211 // destroy windows
12101212 CHECK_TRUE( DestroyWindow(m_hwndVersion) );
@@ -1223,6 +1225,11 @@ public:
12231225 // stop keyboard handler thread
12241226 m_engine.stop();
12251227
1228+ if (!(m_sessionState & SESSION_END_QUERIED)) {
1229+ DWORD_PTR result;
1230+ SendMessageTimeout(HWND_BROADCAST, WM_NULL, 0, 0, 0, 3000, &result);
1231+ }
1232+
12261233 // remove setting;
12271234 delete m_setting;
12281235 }
--- a/yamyd.cpp
+++ b/yamyd.cpp
@@ -14,9 +14,8 @@ int WINAPI _tWinMain(HINSTANCE /* i_hInstance */, HINSTANCE /* i_hPrevInstance *
1414
1515 // wait for master process exit
1616 WaitForSingleObject(mutex, INFINITE);
17- ReleaseMutex(mutex);
18-
1917 CHECK_FALSE( uninstallMessageHook() );
18+ ReleaseMutex(mutex);
2019 }
2120
2221 return 0;
旧リポジトリブラウザで表示