From 33bcc689c6711ea6ab6bb6ee709e8ac4cbb2ae65 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 23 Aug 2007 23:06:40 +0000
Subject: [PATCH] Fix a issue where adding entries below a parent entry and modifying the parent entry causes lock expirations. All writer threads for the modify  operations were being starved by the reader threads for the add operations. Changed the LockManager to observe fairness rules when granting  locks so waiting write locks are granted before read locks.

---
 opends/src/server/org/opends/server/types/LockManager.java |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/opends/src/server/org/opends/server/types/LockManager.java b/opends/src/server/org/opends/server/types/LockManager.java
index a5473bd..b8d31ca 100644
--- a/opends/src/server/org/opends/server/types/LockManager.java
+++ b/opends/src/server/org/opends/server/types/LockManager.java
@@ -217,12 +217,21 @@
           // and either return it or return null.
           readLock.unlock();
           readLock = existingLock.readLock();
-          if (readLock.tryLock())
+
+          try
           {
-            return readLock;
+            if (readLock.tryLock(0, TimeUnit.SECONDS))
+            {
+              return readLock;
+            }
+            else
+            {
+              return null;
+            }
           }
-          else
+          catch(InterruptedException ie)
           {
+            // This should never happen. Just return null
             return null;
           }
         }
@@ -421,12 +430,20 @@
           // and either return it or return null.
           writeLock.unlock();
           writeLock = existingLock.writeLock();
-          if (writeLock.tryLock())
+          try
           {
-            return writeLock;
+            if (writeLock.tryLock(0, TimeUnit.SECONDS))
+            {
+              return writeLock;
+            }
+            else
+            {
+              return null;
+            }
           }
-          else
+          catch(InterruptedException ie)
           {
+            // This should never happen. Just return null
             return null;
           }
         }

--
Gitblit v1.10.0