diff options
Diffstat (limited to 'src/emacs-module.c')
| -rw-r--r-- | src/emacs-module.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index e730ca35ae5..011cc7be914 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -50,12 +50,9 @@ static thrd_t main_thread; | |||
| 50 | # include <pthread.h> | 50 | # include <pthread.h> |
| 51 | static pthread_t main_thread; | 51 | static pthread_t main_thread; |
| 52 | #elif defined WINDOWSNT | 52 | #elif defined WINDOWSNT |
| 53 | # include <windows.h> | 53 | #include <windows.h> |
| 54 | /* On Windows, store both a handle to the main thread and the | 54 | #include "w32term.h" |
| 55 | thread ID because the latter can be reused when a thread | 55 | static DWORD main_thread; |
| 56 | terminates. */ | ||
| 57 | static HANDLE main_thread; | ||
| 58 | static DWORD main_thread_id; | ||
| 59 | #endif | 56 | #endif |
| 60 | 57 | ||
| 61 | 58 | ||
| @@ -789,11 +786,7 @@ check_main_thread (void) | |||
| 789 | #elif defined HAVE_PTHREAD | 786 | #elif defined HAVE_PTHREAD |
| 790 | eassert (pthread_equal (pthread_self (), main_thread)); | 787 | eassert (pthread_equal (pthread_self (), main_thread)); |
| 791 | #elif defined WINDOWSNT | 788 | #elif defined WINDOWSNT |
| 792 | /* CompareObjectHandles would be perfect, but is only available in | 789 | eassert (GetCurrentThreadId () == main_thread); |
| 793 | Windows 10. Also check whether the thread is still running to | ||
| 794 | protect against thread identifier reuse. */ | ||
| 795 | eassert (GetCurrentThreadId () == main_thread_id | ||
| 796 | && WaitForSingleObject (main_thread, 0) == WAIT_TIMEOUT); | ||
| 797 | #endif | 790 | #endif |
| 798 | } | 791 | } |
| 799 | 792 | ||
| @@ -1123,22 +1116,8 @@ module_init (void) | |||
| 1123 | #elif defined HAVE_PTHREAD | 1116 | #elif defined HAVE_PTHREAD |
| 1124 | main_thread = pthread_self (); | 1117 | main_thread = pthread_self (); |
| 1125 | #elif defined WINDOWSNT | 1118 | #elif defined WINDOWSNT |
| 1126 | /* This calls APIs that are only available on Vista and later. */ | 1119 | /* The 'main' function already recorded the main thread's thread ID, |
| 1127 | # if false | 1120 | so we need just to use it . */ |
| 1128 | /* GetCurrentProcess returns a pseudohandle, which must be duplicated. */ | 1121 | main_thread = dwMainThreadId; |
| 1129 | if (! DuplicateHandle (GetCurrentProcess (), GetCurrentThread (), | ||
| 1130 | GetCurrentProcess (), &main_thread, | ||
| 1131 | SYNCHRONIZE | THREAD_QUERY_INFORMATION, | ||
| 1132 | FALSE, 0)) | ||
| 1133 | emacs_abort (); | ||
| 1134 | # else | ||
| 1135 | /* GetCurrentThread returns a pseudohandle, which must be duplicated. */ | ||
| 1136 | HANDLE th = GetCurrentThread (); | ||
| 1137 | if (!DuplicateHandle (GetCurrentProcess (), th, | ||
| 1138 | GetCurrentProcess (), &main_thread, 0, FALSE, | ||
| 1139 | DUPLICATE_SAME_ACCESS)) | ||
| 1140 | emacs_abort (); | ||
| 1141 | main_thread_id = GetCurrentThreadId (); | ||
| 1142 | # endif | ||
| 1143 | #endif | 1122 | #endif |
| 1144 | } | 1123 | } |