- public void runReally(boolean hasMutex) throws IOException {
-
- if(!hasMutex)
- impl.acquireMutex();
-
- try {
-
- // These have been set in method persist
- assert(!impl.isResident());
- assert(!impl.isDirty());
-
- impl.toFile(bytes);
-
- synchronized(pending) {
- pending.remove(impl.getKey().toString());
- s.release(Integer.MAX_VALUE);
- }
- } finally {
- if(!hasMutex)
- impl.releaseMutex();
- }
-
- }
-
+ public void runWithMutex() throws IOException, IllegalAcornStateException, AcornAccessVerificationException {
+
+ try {
+ // These have been set in method persist
+ assert (!impl.isResident());
+ assert (!impl.isDirty());
+
+ impl.toFile(bytes);
+ } finally {
+ synchronized (pending) {
+ pending.remove(impl.getKey().toString());
+ s.release(Integer.MAX_VALUE);
+ }
+ }
+
+ }
+
+ // Fix WriteRunnable.runReally() to use LRU.MapValue mutex instead of
+ // borrowMutex
+ public void runReally(boolean hasMutex) throws IOException, IllegalAcornStateException, AcornAccessVerificationException {
+
+ if (hasMutex) {
+
+ runWithMutex();
+
+ } else {
+
+ boolean gotMutex = impl.tryAcquireMutex();
+
+ boolean done = false;
+ int count = 0;
+ long startTime = 0;
+ while (!done) {
+
+ if (gotMutex || borrowMutex) {
+ runWithMutex();
+ done = true;
+ } else {
+ if (count % 10 == 0) {
+ // Taking too long, sleep for a while.
+ LOGGER.warn("Retry mutex acquire");
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ }
+ }
+ gotMutex = impl.tryAcquireMutex();
+ long currentTime = System.currentTimeMillis();
+ if ((currentTime - startTime) > 10) {
+ startTime = currentTime;
+ count++;
+ }
+ }
+
+ }
+
+ if (gotMutex)
+ impl.releaseMutex();
+
+ }
+
+ }