Merge pull request #611 from matthiasbeyer/libimagstore/drop-wlocks-early

Libimagstore/drop wlocks early
This commit is contained in:
Matthias Beyer 2016-08-02 20:28:08 +02:00 committed by GitHub
commit 76d88e46ad

View file

@ -390,6 +390,7 @@ impl Store {
.map_err_into(SEK::CreateCallError) .map_err_into(SEK::CreateCallError)
} }
{
let mut hsmap = match self.entries.write() { let mut hsmap = match self.entries.write() {
Err(_) => return Err(SEK::LockPoisoned.into_error()).map_err_into(SEK::CreateCallError), Err(_) => return Err(SEK::LockPoisoned.into_error()).map_err_into(SEK::CreateCallError),
Ok(s) => s, Ok(s) => s,
@ -403,6 +404,7 @@ impl Store {
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
se se
}); });
}
let mut fle = FileLockEntry::new(self, Entry::new(id)); let mut fle = FileLockEntry::new(self, Entry::new(id));
self.execute_hooks_for_mut_file(self.post_create_aspects.clone(), &mut fle) self.execute_hooks_for_mut_file(self.post_create_aspects.clone(), &mut fle)
@ -426,6 +428,7 @@ impl Store {
.map_err_into(SEK::RetrieveCallError) .map_err_into(SEK::RetrieveCallError)
} }
let entry = try!({
self.entries self.entries
.write() .write()
.map_err(|_| SE::new(SEK::LockPoisoned, None)) .map_err(|_| SE::new(SEK::LockPoisoned, None))
@ -435,14 +438,15 @@ impl Store {
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
entry entry
}) })
.map(|e| FileLockEntry::new(self, e)) .map_err_into(SEK::RetrieveCallError)
.and_then(|mut fle| { });
let mut fle = FileLockEntry::new(self, entry);
self.execute_hooks_for_mut_file(self.post_retrieve_aspects.clone(), &mut fle) self.execute_hooks_for_mut_file(self.post_retrieve_aspects.clone(), &mut fle)
.map_err_into(SEK::PostHookExecuteError) .map_err_into(SEK::PostHookExecuteError)
.map_err_into(SEK::HookExecutionError) .map_err_into(SEK::HookExecutionError)
.and(Ok(fle))
})
.map_err_into(SEK::RetrieveCallError) .map_err_into(SEK::RetrieveCallError)
.and(Ok(fle))
} }
/// Get an entry from the store if it exists. /// Get an entry from the store if it exists.
@ -596,6 +600,7 @@ impl Store {
.map_err_into(SEK::DeleteCallError) .map_err_into(SEK::DeleteCallError)
} }
{
let mut entries = match self.entries.write() { let mut entries = match self.entries.write() {
Err(_) => return Err(SE::new(SEK::LockPoisoned, None)) Err(_) => return Err(SE::new(SEK::LockPoisoned, None))
.map_err_into(SEK::DeleteCallError), .map_err_into(SEK::DeleteCallError),
@ -614,6 +619,7 @@ impl Store {
return Err(SEK::FileError.into_error_with_cause(Box::new(e))) return Err(SEK::FileError.into_error_with_cause(Box::new(e)))
.map_err_into(SEK::DeleteCallError); .map_err_into(SEK::DeleteCallError);
} }
}
self.execute_hooks_for_id(self.post_delete_aspects.clone(), &id) self.execute_hooks_for_id(self.post_delete_aspects.clone(), &id)
.map_err_into(SEK::PostHookExecuteError) .map_err_into(SEK::PostHookExecuteError)
@ -680,6 +686,7 @@ impl Store {
.map_err_into(SEK::MoveByIdCallError) .map_err_into(SEK::MoveByIdCallError)
} }
{
let hsmap = self.entries.write(); let hsmap = self.entries.write();
if hsmap.is_err() { if hsmap.is_err() {
return Err(SE::new(SEK::LockPoisoned, None)) return Err(SE::new(SEK::LockPoisoned, None))
@ -695,6 +702,8 @@ impl Store {
} }
} }
}
self.execute_hooks_for_id(self.pre_move_aspects.clone(), &new_id) self.execute_hooks_for_id(self.pre_move_aspects.clone(), &new_id)
.map_err_into(SEK::PostHookExecuteError) .map_err_into(SEK::PostHookExecuteError)
.map_err_into(SEK::HookExecutionError) .map_err_into(SEK::HookExecutionError)