Database.setInboxGroup() doesn't require message lock.

This commit is contained in:
akwizgran
2014-02-27 12:49:57 +00:00
parent c021bfd9aa
commit 1cbaae0734
2 changed files with 11 additions and 16 deletions

View File

@@ -712,7 +712,7 @@ interface Database<T> {
* Makes a group visible to the given contact, adds it to the contact's
* subscriptions, and sets it as the inbox group for the contact.
* <p>
* Locking: contact read, message write, subscription write.
* Locking: subscription write.
*/
public void setInboxGroup(T txn, ContactId c, Group g) throws DbException;

View File

@@ -1770,25 +1770,20 @@ DatabaseCleaner.Callback {
public void setInboxGroup(ContactId c, Group g) throws DbException {
contactLock.readLock().lock();
try {
messageLock.writeLock().lock();
subscriptionLock.writeLock().lock();
try {
subscriptionLock.writeLock().lock();
T txn = db.startTransaction();
try {
T txn = db.startTransaction();
try {
if(!db.containsContact(txn, c))
throw new NoSuchContactException();
db.setInboxGroup(txn, c, g);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
subscriptionLock.writeLock().unlock();
if(!db.containsContact(txn, c))
throw new NoSuchContactException();
db.setInboxGroup(txn, c, g);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
messageLock.writeLock().unlock();
subscriptionLock.writeLock().unlock();
}
} finally {
contactLock.readLock().unlock();