]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: authz: Use dedicated locks per datastructure
authorCorinna Vinschen <corinna@vinschen.de>
Mon, 22 Aug 2022 12:25:05 +0000 (14:25 +0200)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 22 Aug 2022 12:25:05 +0000 (14:25 +0200)
So far we use a single muto to guard three different datastructures
inside class authz_ctx: the authz HANDLE, the user context HANDLE
and the context cache list.  Split the single muto into three
independent SRWLOCKs and guard all datastrcutures as necessary to
avoid thread contention.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/sec/helper.cc

index 750631b2b3231a6ef664ce7333b7fb2fc1370c91..45bf65dac4675e56d7604314357f0fa384da8f0b 100644 (file)
@@ -707,7 +707,18 @@ _everyone_sd (void *buf, ACCESS_MASK access)
   return psd;
 }
 
-static NO_COPY muto authz_guard;
+static NO_COPY SRWLOCK authz_lock = SRWLOCK_INIT;
+#define AUTHZ_LOCK()    (AcquireSRWLockExclusive (&authz_lock))
+#define AUTHZ_UNLOCK()  (ReleaseSRWLockExclusive (&authz_lock))
+
+static NO_COPY SRWLOCK user_ctx_lock = SRWLOCK_INIT;
+#define USER_CTX_LOCK()    (AcquireSRWLockExclusive (&user_ctx_lock))
+#define USER_CTX_UNLOCK()  (ReleaseSRWLockExclusive (&user_ctx_lock))
+
+static NO_COPY SRWLOCK slist_lock = SRWLOCK_INIT;
+#define SLIST_LOCK()    (AcquireSRWLockExclusive (&slist_lock))
+#define SLIST_UNLOCK()  (ReleaseSRWLockExclusive (&slist_lock))
+
 static LUID authz_dummy_luid = { 0 };
 
 class authz_ctx_cache_entry
@@ -766,13 +777,13 @@ authz_ctx::operator AUTHZ_RESOURCE_MANAGER_HANDLE ()
   if (!authz_hdl)
     {
       /* Create handle to Authz resource manager */
-      authz_guard.init ("authz_guard")->acquire ();
+      AUTHZ_LOCK ();
       if (!authz_hdl
          && !AuthzInitializeResourceManager (AUTHZ_RM_FLAG_NO_AUDIT,
                                              NULL, NULL, NULL, NULL,
                                              &authz_hdl))
        debug_printf ("AuthzInitializeResourceManager, %E");
-      authz_guard.release ();
+      AUTHZ_UNLOCK ();
     }
   return authz_hdl;
 }
@@ -805,9 +816,9 @@ authz_ctx_cache::context (PSID user_sid)
   else
     {
       entry->set (user_sid, ctx_hdl);
-      authz_guard.acquire ();
+      SLIST_LOCK ();
       SLIST_INSERT_HEAD (&ctx_list, entry, ctx_next);
-      authz_guard.release ();
+      SLIST_UNLOCK ();
       return entry->context ();
     }
   delete entry;
@@ -830,7 +841,7 @@ authz_ctx::get_user_attribute (mode_t *attribute, PSECURITY_DESCRIPTOR psd,
       /* Avoid lock in default case. */
       if (!user_ctx_hdl)
        {
-         authz_guard.acquire ();
+         USER_CTX_LOCK ();
          /* Check user_ctx_hdl again under lock to avoid overwriting
             user_ctx_hdl if it has already been initialized. */
          if (!user_ctx_hdl
@@ -838,7 +849,7 @@ authz_ctx::get_user_attribute (mode_t *attribute, PSECURITY_DESCRIPTOR psd,
                                                   authz_dummy_luid, NULL,
                                                   &user_ctx_hdl))
            debug_printf ("AuthzInitializeContextFromToken, %E");
-         authz_guard.release ();
+         USER_CTX_UNLOCK ();
        }
       if (user_ctx_hdl)
        ctx_hdl = user_ctx_hdl;
This page took 0.0336 seconds and 5 git commands to generate.