g_lock: Walk locks only once in g_lock_trylock
authorVolker Lendecke <vl@samba.org>
Wed, 28 Jun 2017 14:21:19 +0000 (16:21 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 25 Jul 2017 15:43:16 +0000 (17:43 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/g_lock.c

index 198fe563eb95938a779d6b7fec37d83dcc42d05d..a22ec94c9c8fdadb717a304769e14bc204d05b18 100644 (file)
@@ -297,18 +297,11 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
                                goto done;
                        }
                        my_lock = i;
-                       break;
-               }
-       }
-
-       for (i=0; i<num_locks; i++) {
-
-               if (i == my_lock) {
                        continue;
                }
 
-               if (g_lock_conflicts(type, locks[i].lock_type)) {
-                       struct server_id pid = locks[i].pid;
+               if (g_lock_conflicts(type, lock->lock_type)) {
+                       struct server_id pid = lock->pid;
 
                        /*
                         * As the serverid_exists might recurse into
@@ -319,7 +312,7 @@ static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
 
                        if (serverid_exists(&pid)) {
                                status = NT_STATUS_LOCK_NOT_GRANTED;
-                               *blocker = locks[i].pid;
+                               *blocker = lock->pid;
                                goto done;
                        }