+
+ if (location == null) {
+ ExceptionHandler.handleErrorCondition("location is null");
+ location = "";
+ }
+ checkState(false);
+
+
+ // Check that the mutex is locked
+ if (lockingThread == null) {
+ error("Mutex was not locked", false);
+ return false;
+ }
+
+ // Check that the mutex is locked by the current thread
+ if (lockingThread != Thread.currentThread()) {
+ error("Mutex is being unlocked from differerent thread than where it was locked", false);
+ return false;
+ }
+
+ // Check that the unlock location is correct
+ String lastLocation = locations.pop();
+ if (!location.equals(lastLocation)) {
+ locations.push(lastLocation);
+ error("Mutex unlocking location does not match locking location, location=" + location, false);
+ return false;
+ }
+
+ // Unlock the mutex if the last one
+ if (locations.isEmpty()) {
+ lockingThread = null;
+ lockingLocation = null;
+ }
+ return true;
+ } catch (Exception e) {
+ ExceptionHandler.handleErrorCondition("An exception occurred while unlocking a mutex, " +
+ "locking thread=" + lockingThread + " locations=" + locations, e);
+ return false;