From 18 Jan, 2021 0:00 UTC: All services will be temporary unavailable for maintenance
  • R/O
  • HTTP
  • SSH
  • HTTPS

timidity41: Commit


Commit MetaInfo

Revisiond822eb1b2120e8a1cc317c22615f6199efa880ba (tree)
Time2020-09-26 16:23:57
AuthorStarg <starg@user...>
CommiterStarg

Log Message

Use more usermode locks

Change Summary

Incremental Difference

--- a/interface/w32g_i.c
+++ b/interface/w32g_i.c
@@ -5825,13 +5825,23 @@ void w32g_show_console(void)
58255825 //
58265826 // GDI アクセスを単一スレッドに限定するためのロック機構
58275827
5828+#ifdef TIMW32G_USE_USERMODE_LOCKS
5829+static SRWLOCK w32g_gdi_lock = SRWLOCK_INIT;
5830+#else
58285831 static HANDLE volatile hMutexGDI = NULL;
5832+#endif
58295833 // static int volatile lock_num = 0;
58305834 int gdi_lock_ex ( DWORD timeout )
58315835 {
58325836 // lock_num++;
58335837 // ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
58345838 // "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
58355845 if(hMutexGDI==NULL){
58365846 hMutexGDI = CreateMutex(NULL,FALSE,NULL);
58375847 if(hMutexGDI==NULL)
@@ -5840,6 +5850,7 @@ int gdi_lock_ex ( DWORD timeout )
58405850 if(WaitForSingleObject(hMutexGDI,timeout)==WAIT_FAILED){
58415851 return -1;
58425852 }
5853+#endif
58435854 return 0;
58445855 }
58455856 int gdi_lock(void)
@@ -5852,8 +5863,12 @@ extern int gdi_unlock(void)
58525863 //lock_num--;
58535864 //ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
58545865 // "gdi_unlock<%d %d>", GetCurrentThreadId(),lock_num );
5866+#ifdef TIMW32G_USE_USERMODE_LOCKS
5867+ ReleaseSRWLockExclusive(&w32g_gdi_lock);
5868+#else
58555869 if(hMutexGDI!=NULL){
58565870 ReleaseMutex(hMutexGDI);
58575871 }
5872+#endif
58585873 return 0;
58595874 }
--- a/interface/w32g_subwin2.c
+++ b/interface/w32g_subwin2.c
@@ -170,9 +170,27 @@ static void wrd_text_update ( int x_from, int y_from, int x_to, int y_to, int lo
170170
171171 static int volatile wrd_graphic_pal_init_flag = 0;
172172
173+#define TIMW32G_USE_USERMODE_LOCKS
174+#ifdef TIMW32G_USE_USERMODE_LOCKS
175+static CRITICAL_SECTION *w32g_wrd_wnd_lock = NULL;
176+#else
173177 static HANDLE volatile hMutexWrd = NULL;
178+#endif
179+
174180 static BOOL wrd_wnd_lock_ex ( DWORD timeout )
175181 {
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
176194 if ( hMutexWrd == NULL ) {
177195 hMutexWrd = CreateMutex ( NULL, FALSE, NULL );
178196 if ( hMutexWrd == NULL )
@@ -181,6 +199,7 @@ static BOOL wrd_wnd_lock_ex ( DWORD timeout )
181199 if ( WaitForSingleObject ( hMutexWrd, timeout )== WAIT_FAILED ) {
182200 return FALSE;
183201 }
202+#endif
184203 return TRUE;
185204 }
186205 static BOOL wrd_wnd_lock (void)
@@ -189,7 +208,11 @@ static BOOL wrd_wnd_lock (void)
189208 }
190209 static void wrd_wnd_unlock (void)
191210 {
211+#ifdef TIMW32G_USE_USERMODE_LOCKS
212+ LeaveCriticalSection(w32g_wrd_wnd_lock);
213+#else
192214 ReleaseMutex ( hMutexWrd );
215+#endif
193216 }
194217
195218
--- a/interface/w32g_subwin3.c
+++ b/interface/w32g_subwin3.c
@@ -251,9 +251,25 @@ static int tracer_lock_result;
251251 #define TRACER_UNLOCK() { tracer_wnd_unlock(); }
252252 #endif
253253
254+#define TIMW32G_USE_USERMODE_LOCKS
255+#ifdef TIMW32G_USE_USERMODE_LOCKS
256+static CRITICAL_SECTION *w32g_tracer_wnd_lock = NULL;
257+#else
254258 static HANDLE volatile hMutexWrd = NULL;
259+#endif
255260 static BOOL tracer_wnd_lock_ex(DWORD timeout)
256261 {
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
257273 if (!hMutexWrd) {
258274 hMutexWrd = CreateMutex(NULL, FALSE, NULL);
259275 if (!hMutexWrd)
@@ -262,6 +278,7 @@ static BOOL tracer_wnd_lock_ex(DWORD timeout)
262278 if (WaitForSingleObject(hMutexWrd, timeout) == WAIT_FAILED) {
263279 return FALSE;
264280 }
281+#endif
265282 return TRUE;
266283 }
267284 static BOOL tracer_wnd_lock(void)
@@ -270,7 +287,11 @@ static BOOL tracer_wnd_lock(void)
270287 }
271288 static void tracer_wnd_unlock(void)
272289 {
290+#ifdef TIMW32G_USE_USERMODE_LOCKS
291+ LeaveCriticalSection(w32g_tracer_wnd_lock);
292+#else
273293 ReleaseMutex(hMutexWrd);
294+#endif
274295 }
275296
276297 // ****************************************************************************
Show on old repository browser