Repository: ant-ivy
Updated Branches:
  refs/heads/master bac647543 -> cc6ace189


Revert previous change

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/cc6ace18
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/cc6ace18
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/cc6ace18

Branch: refs/heads/master
Commit: cc6ace18900eb92606b6a312cb1ac5c4ab5f435e
Parents: bac6475
Author: Gintas Grigelionis <[email protected]>
Authored: Thu Nov 2 08:18:52 2017 +0100
Committer: Gintas Grigelionis <[email protected]>
Committed: Thu Nov 2 08:18:52 2017 +0100

----------------------------------------------------------------------
 .../ivy/plugins/lock/FileBasedLockStrategy.java | 68 +++++++++++---------
 1 file changed, 39 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/cc6ace18/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java 
b/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
index d59c544..2e31b2f 100644
--- a/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
+++ b/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
@@ -64,34 +64,39 @@ public abstract class FileBasedLockStrategy extends 
AbstractLockStrategy {
         }
         long start = System.currentTimeMillis();
         do {
-            int lockCount = hasLock(file, currentThread);
-            if (isDebugLocking()) {
-                debugLocking("current status for " + file + " is " + lockCount
-                        + " held locks: " + getCurrentLockHolderNames(file));
-            }
-            if (lockCount < 0) {
-                /* Another thread in this process holds the lock; we need to 
wait */
+            synchronized (currentLockHolders) {
                 if (isDebugLocking()) {
-                    debugLocking("waiting for another thread to release the 
lock: "
-                            + getCurrentLockHolderNames(file));
+                    debugLocking("entered synchronized area (locking)");
                 }
-            } else if (lockCount > 0) {
-                int holdLocks = incrementLock(file, currentThread);
+                int lockCount = hasLock(file, currentThread);
                 if (isDebugLocking()) {
-                    debugLocking("reentrant lock acquired on " + file + " in "
-                            + (System.currentTimeMillis() - start) + "ms" + " 
- hold locks = "
-                            + holdLocks);
+                    debugLocking("current status for " + file + " is " + 
lockCount
+                            + " held locks: " + 
getCurrentLockHolderNames(file));
                 }
-                return true;
-            } else {
-                /* No prior lock on this file is held at all */
-                if (locker.tryLock(file)) {
+                if (lockCount < 0) {
+                    /* Another thread in this process holds the lock; we need 
to wait */
                     if (isDebugLocking()) {
-                        debugLocking("lock acquired on " + file + " in "
-                                + (System.currentTimeMillis() - start) + "ms");
+                        debugLocking("waiting for another thread to release 
the lock: "
+                                + getCurrentLockHolderNames(file));
+                    }
+                } else if (lockCount > 0) {
+                    int holdLocks = incrementLock(file, currentThread);
+                    if (isDebugLocking()) {
+                        debugLocking("reentrant lock acquired on " + file + " 
in "
+                                + (System.currentTimeMillis() - start) + "ms" 
+ " - hold locks = "
+                                + holdLocks);
                     }
-                    incrementLock(file, currentThread);
                     return true;
+                } else {
+                    /* No prior lock on this file is held at all */
+                    if (locker.tryLock(file)) {
+                        if (isDebugLocking()) {
+                            debugLocking("lock acquired on " + file + " in "
+                                    + (System.currentTimeMillis() - start) + 
"ms");
+                        }
+                        incrementLock(file, currentThread);
+                        return true;
+                    }
                 }
             }
             if (isDebugLocking()) {
@@ -107,16 +112,21 @@ public abstract class FileBasedLockStrategy extends 
AbstractLockStrategy {
         if (isDebugLocking()) {
             debugLocking("releasing lock on " + file);
         }
-        int holdLocks = decrementLock(file, currentThread);
-        if (holdLocks == 0) {
-            locker.unlock(file);
+        synchronized (currentLockHolders) {
             if (isDebugLocking()) {
-                debugLocking("lock released on " + file);
+                debugLocking("entered synchronized area (unlocking)");
             }
-        } else {
-            if (isDebugLocking()) {
-                debugLocking("reentrant lock released on " + file + " - hold 
locks = "
-                        + holdLocks);
+            int holdLocks = decrementLock(file, currentThread);
+            if (holdLocks == 0) {
+                locker.unlock(file);
+                if (isDebugLocking()) {
+                    debugLocking("lock released on " + file);
+                }
+            } else {
+                if (isDebugLocking()) {
+                    debugLocking("reentrant lock released on " + file + " - 
hold locks = "
+                            + holdLocks);
+                }
             }
         }
     }

Reply via email to