diff options
author | Simon Kaegi | 2009-03-06 16:32:05 +0000 |
---|---|---|
committer | Simon Kaegi | 2009-03-06 16:32:05 +0000 |
commit | af9165d50982006d721fcaed036356ceb2a558ed (patch) | |
tree | b2cc8a53719c5ef81cb1acf6ac64affb4705e478 /bundles | |
parent | bcaf8235e6f8558fda3b1f47d5e5f273e164d68c (diff) | |
download | rt.equinox.p2-af9165d50982006d721fcaed036356ceb2a558ed.tar.gz rt.equinox.p2-af9165d50982006d721fcaed036356ceb2a558ed.tar.xz rt.equinox.p2-af9165d50982006d721fcaed036356ceb2a558ed.zip |
Bug 266388 Make ProfileLock not re-entrant
Diffstat (limited to 'bundles')
4 files changed, 37 insertions, 35 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java index fa7ea861c..f88831998 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Messages.java @@ -57,6 +57,7 @@ class Messages extends NLS { public static String SimpleProfileRegistry_Bad_profile_location; public static String thread_not_owner; + public static String profile_lock_not_reentrant; public static String TouchpointManager_Attribute_Not_Specified; public static String TouchpointManager_Conflicting_Touchpoint_Types; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java index a8bf3b42a..815ecd00f 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java @@ -26,7 +26,6 @@ public class ProfileLock { private final Location location; private final Object lock; private Thread lockHolder; - private int lockedCount; private int waiting; public ProfileLock(Object lock, File profileDirectory) { @@ -64,33 +63,33 @@ public class ProfileLock { public boolean lock() { synchronized (lock) { Thread current = Thread.currentThread(); - if (lockHolder != current) { - boolean locationLocked = false; - while (lockHolder != null) { - locationLocked = true; - waiting++; - boolean interrupted = false; - try { - lock.wait(); - } catch (InterruptedException e) { - interrupted = true; - } finally { - waiting--; - // if interrupted restore interrupt to thread state - if (interrupted) - current.interrupt(); - } - } - try { - if (!locationLocked && !location.lock()) - return false; + if (lockHolder == current) + throw new IllegalStateException(Messages.profile_lock_not_reentrant); - lockHolder = current; - } catch (IOException e) { - throw new IllegalStateException(NLS.bind(Messages.SimpleProfileRegistry_Profile_not_locked_due_to_exception, e.getLocalizedMessage())); + boolean locationLocked = false; + while (lockHolder != null) { + locationLocked = true; + waiting++; + boolean interrupted = false; + try { + lock.wait(); + } catch (InterruptedException e) { + interrupted = true; + } finally { + waiting--; + // if interrupted restore interrupt to thread state + if (interrupted) + current.interrupt(); } } - lockedCount++; + try { + if (!locationLocked && !location.lock()) + return false; + + lockHolder = current; + } catch (IOException e) { + throw new IllegalStateException(NLS.bind(Messages.SimpleProfileRegistry_Profile_not_locked_due_to_exception, e.getLocalizedMessage())); + } return true; } } @@ -104,14 +103,11 @@ public class ProfileLock { if (lockHolder != current) throw new IllegalStateException(Messages.thread_not_owner); - lockedCount--; - if (lockedCount == 0) { - lockHolder = null; - if (waiting == 0) - location.release(); - else - lock.notify(); - } + lockHolder = null; + if (waiting == 0) + location.release(); + else + lock.notify(); } } }
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties index 28a551bd5..5750a36a2 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/messages.properties @@ -46,6 +46,7 @@ profile_not_current=Profile {0} is not current. profile_not_registered=Profile {0} not registered. reg_dir_not_available=Registry Directory not available. thread_not_owner=Thread not lock owner. +profile_lock_not_reentrant=Lock failed. Profile does not permit reentrant locking. shared_profile_not_found=Shared profile {0} not found. ProfilePreferences_save_failed=An error occurred while saving preferences for profile {0} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java index d1fe4a3de..e276d4841 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java @@ -246,8 +246,12 @@ public class ProfileRegistryTest extends AbstractProvisioningTest { // Try lock, lock, unlock, unlock should pass simpleRgy.lockProfile(simpleProfile); - simpleRgy.lockProfile(simpleProfile); - simpleRgy.unlockProfile(simpleProfile); + try { + simpleRgy.lockProfile(simpleProfile); + fail("Profile does not permit reentrant locking"); + } catch (IllegalStateException e) { + // expected + } simpleRgy.unlockProfile(simpleProfile); // NOTE: remaining nested tests are commented out for now |