Révision | d822eb1b2120e8a1cc317c22615f6199efa880ba (tree) |
---|---|
l'heure | 2020-09-26 16:23:57 |
Auteur | Starg <starg@user...> |
Commiter | Starg |
Use more usermode locks
@@ -5825,13 +5825,23 @@ void w32g_show_console(void) | ||
5825 | 5825 | // |
5826 | 5826 | // GDI アクセスを単一スレッドに限定するためのロック機構 |
5827 | 5827 | |
5828 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5829 | +static SRWLOCK w32g_gdi_lock = SRWLOCK_INIT; | |
5830 | +#else | |
5828 | 5831 | static HANDLE volatile hMutexGDI = NULL; |
5832 | +#endif | |
5829 | 5833 | // static int volatile lock_num = 0; |
5830 | 5834 | int gdi_lock_ex ( DWORD timeout ) |
5831 | 5835 | { |
5832 | 5836 | // lock_num++; |
5833 | 5837 | // ctl->cmsg(CMSG_INFO, VERB_VERBOSE, |
5834 | 5838 | // "gdi_lock<%d %d>", GetCurrentThreadId(),lock_num ); |
5839 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5840 | + if (timeout == INFINITE) | |
5841 | + AcquireSRWLockExclusive(&w32g_gdi_lock); | |
5842 | + else | |
5843 | + return TryAcquireSRWLockExclusive(&w32g_gdi_lock) ? 0 : -1; | |
5844 | +#else | |
5835 | 5845 | if(hMutexGDI==NULL){ |
5836 | 5846 | hMutexGDI = CreateMutex(NULL,FALSE,NULL); |
5837 | 5847 | if(hMutexGDI==NULL) |
@@ -5840,6 +5850,7 @@ int gdi_lock_ex ( DWORD timeout ) | ||
5840 | 5850 | if(WaitForSingleObject(hMutexGDI,timeout)==WAIT_FAILED){ |
5841 | 5851 | return -1; |
5842 | 5852 | } |
5853 | +#endif | |
5843 | 5854 | return 0; |
5844 | 5855 | } |
5845 | 5856 | int gdi_lock(void) |
@@ -5852,8 +5863,12 @@ extern int gdi_unlock(void) | ||
5852 | 5863 | //lock_num--; |
5853 | 5864 | //ctl->cmsg(CMSG_INFO, VERB_VERBOSE, |
5854 | 5865 | // "gdi_unlock<%d %d>", GetCurrentThreadId(),lock_num ); |
5866 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
5867 | + ReleaseSRWLockExclusive(&w32g_gdi_lock); | |
5868 | +#else | |
5855 | 5869 | if(hMutexGDI!=NULL){ |
5856 | 5870 | ReleaseMutex(hMutexGDI); |
5857 | 5871 | } |
5872 | +#endif | |
5858 | 5873 | return 0; |
5859 | 5874 | } |
@@ -170,9 +170,27 @@ static void wrd_text_update ( int x_from, int y_from, int x_to, int y_to, int lo | ||
170 | 170 | |
171 | 171 | static int volatile wrd_graphic_pal_init_flag = 0; |
172 | 172 | |
173 | +#define TIMW32G_USE_USERMODE_LOCKS | |
174 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
175 | +static CRITICAL_SECTION *w32g_wrd_wnd_lock = NULL; | |
176 | +#else | |
173 | 177 | static HANDLE volatile hMutexWrd = NULL; |
178 | +#endif | |
179 | + | |
174 | 180 | static BOOL wrd_wnd_lock_ex ( DWORD timeout ) |
175 | 181 | { |
182 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
183 | + static CRITICAL_SECTION cs; | |
184 | + | |
185 | + if (w32g_wrd_wnd_lock == NULL) { | |
186 | + InitializeCriticalSection(&cs); | |
187 | + w32g_wrd_wnd_lock = &cs; | |
188 | + } | |
189 | + if (timeout == INFINITE) | |
190 | + EnterCriticalSection(w32g_wrd_wnd_lock); | |
191 | + else | |
192 | + return TryEnterCriticalSection(w32g_wrd_wnd_lock); | |
193 | +#else | |
176 | 194 | if ( hMutexWrd == NULL ) { |
177 | 195 | hMutexWrd = CreateMutex ( NULL, FALSE, NULL ); |
178 | 196 | if ( hMutexWrd == NULL ) |
@@ -181,6 +199,7 @@ static BOOL wrd_wnd_lock_ex ( DWORD timeout ) | ||
181 | 199 | if ( WaitForSingleObject ( hMutexWrd, timeout )== WAIT_FAILED ) { |
182 | 200 | return FALSE; |
183 | 201 | } |
202 | +#endif | |
184 | 203 | return TRUE; |
185 | 204 | } |
186 | 205 | static BOOL wrd_wnd_lock (void) |
@@ -189,7 +208,11 @@ static BOOL wrd_wnd_lock (void) | ||
189 | 208 | } |
190 | 209 | static void wrd_wnd_unlock (void) |
191 | 210 | { |
211 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
212 | + LeaveCriticalSection(w32g_wrd_wnd_lock); | |
213 | +#else | |
192 | 214 | ReleaseMutex ( hMutexWrd ); |
215 | +#endif | |
193 | 216 | } |
194 | 217 | |
195 | 218 |
@@ -251,9 +251,25 @@ static int tracer_lock_result; | ||
251 | 251 | #define TRACER_UNLOCK() { tracer_wnd_unlock(); } |
252 | 252 | #endif |
253 | 253 | |
254 | +#define TIMW32G_USE_USERMODE_LOCKS | |
255 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
256 | +static CRITICAL_SECTION *w32g_tracer_wnd_lock = NULL; | |
257 | +#else | |
254 | 258 | static HANDLE volatile hMutexWrd = NULL; |
259 | +#endif | |
255 | 260 | static BOOL tracer_wnd_lock_ex(DWORD timeout) |
256 | 261 | { |
262 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
263 | + static CRITICAL_SECTION cs; | |
264 | + if (!w32g_tracer_wnd_lock) { | |
265 | + InitializeCriticalSection(&cs); | |
266 | + w32g_tracer_wnd_lock = &cs; | |
267 | + } | |
268 | + if (timeout == INFINITE) | |
269 | + EnterCriticalSection(w32g_tracer_wnd_lock); | |
270 | + else | |
271 | + return TryEnterCriticalSection(w32g_tracer_wnd_lock); | |
272 | +#else | |
257 | 273 | if (!hMutexWrd) { |
258 | 274 | hMutexWrd = CreateMutex(NULL, FALSE, NULL); |
259 | 275 | if (!hMutexWrd) |
@@ -262,6 +278,7 @@ static BOOL tracer_wnd_lock_ex(DWORD timeout) | ||
262 | 278 | if (WaitForSingleObject(hMutexWrd, timeout) == WAIT_FAILED) { |
263 | 279 | return FALSE; |
264 | 280 | } |
281 | +#endif | |
265 | 282 | return TRUE; |
266 | 283 | } |
267 | 284 | static BOOL tracer_wnd_lock(void) |
@@ -270,7 +287,11 @@ static BOOL tracer_wnd_lock(void) | ||
270 | 287 | } |
271 | 288 | static void tracer_wnd_unlock(void) |
272 | 289 | { |
290 | +#ifdef TIMW32G_USE_USERMODE_LOCKS | |
291 | + LeaveCriticalSection(w32g_tracer_wnd_lock); | |
292 | +#else | |
273 | 293 | ReleaseMutex(hMutexWrd); |
294 | +#endif | |
274 | 295 | } |
275 | 296 | |
276 | 297 | // **************************************************************************** |