https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=48a210a457c5608e29d3b97dd39d101e27ee0dd8

commit 48a210a457c5608e29d3b97dd39d101e27ee0dd8
Author: Corinna Vinschen <[email protected]>
Date:   Mon Aug 22 14:38:49 2022 +0200

    Cygwin: debugging: convert muto to SRWLOCK
    
    this avoids having to call debug_init, because the SRWLOCK
    is statically initialized.
    
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/dcrt0.cc |  4 ----
 winsup/cygwin/debug.cc | 23 ++++-------------------
 2 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 9ea846e41..e1197092e 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -854,10 +854,6 @@ dll_crt0_1 (void *)
   strace.microseconds ();
 #endif
 
-  /* Initialize debug muto, if DLL is built with --enable-debugging.
-     Need to do this before any helper threads start. */
-  debug_init ();
-
   cygbench ("pre-forkee");
   if (in_forkee)
     {
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index efa101ba7..050ffd9dc 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -22,30 +22,16 @@ details. */
 
 class lock_debug
 {
-  static muto locker;
+  static NO_COPY SRWLOCK lock;
  public:
-  lock_debug ()
-  {
-    locker.acquire (INFINITE);
-  }
-  void unlock ()
-  {
-    locker.release ();
-  }
-  ~lock_debug () {unlock ();}
-  friend void debug_init ();
+  lock_debug () { AcquireSRWLockExclusive (&lock); }
+  ~lock_debug () { ReleaseSRWLockExclusive (&lock); }
 };
 
-muto NO_COPY lock_debug::locker;
+SRWLOCK NO_COPY lock_debug::lock = SRWLOCK_INIT;
 
 static bool mark_closed (const char *, int, HANDLE, const char *, bool);
 
-void
-debug_init ()
-{
-  lock_debug::locker.init ("debug_lock");
-}
-
 /* Find a registered handle in the linked list of handles. */
 static handle_list *
 find_handle (HANDLE h)
@@ -138,7 +124,6 @@ add_handle (const char *func, int ln, HANDLE h, const char 
*name, bool inh)
 
   if ((hl = newh ()) == NULL)
     {
-      here.unlock ();
       debug_printf ("couldn't allocate memory for %s(%d): %s(%p)",
                    func, ln, name, h);
       return;

Reply via email to