Skip to content

Commit

Permalink
Renaming unlock_object methods for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Hare authored and codemercenary committed Aug 5, 2014
1 parent 737bab3 commit 44f9d19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions autowiring/unlock_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
///</summary>
///<remarks>
///An unlock_object cannot be copied by construction or assignment since it maintains access.
///An unlock_object and cannot be used to instantiate new shared_object instances,
///An unlock_object cannot be used to instantiate new shared_object instances,
///because it is not guaranteed to reference a shared_object.
///An unlock_object cannot be applied to an atomic_object, since continued existence of the
///referenced object would not be guaranteed.
Expand All @@ -18,6 +18,7 @@ template<class object, class lock = std::mutex>
class unlock_object {
unlock_object(unlock_object<object, lock>& source) = delete;
unlock_object<object, lock>& operator = (unlock_object<object, lock>& _rhs) = delete;
unlock_object<object, lock>* operator & () = delete;

std::shared_ptr<atomic_object<object, lock>> m_share;

Expand Down Expand Up @@ -61,29 +62,29 @@ class unlock_object {
}

///<summary>
///Reset releases reference and lock, yielding bool(this) == false;
///Releases reference and lock, yielding bool(this) == false;
///</summary>
///<remarks>
///This method is idempotent.
///</remarks>
void reset() {
void release() {
if (m_share) {
m_share->m_lock.unlock();
m_share.reset();
}
}

///<summary>
///Reset re-targets reference and lock to source, yielding bool(this) == false;
///Aquires a lock on and reference to source, yielding unlock_object<object>::operator bool(this) == true;
///</summary>
///<param name="should_try">If true, the returned unlock_object might hold no reference or lock</param>
///<remarks>
///This method is idempotent, including when called repeatedly with the same argument.
///However, reset(source) always releases the any currently held lock.
///</remarks>
void reset(shared_object<object, lock>& source, bool should_try = false) {
void acquire(shared_object<object, lock>& source, bool should_try = false) {
if (m_share)
reset();
release();
if(should_try)
try_unlock(source);
else
Expand Down
4 changes: 2 additions & 2 deletions src/autowiring/test/GuardObjectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ TEST_F(GuardObjectTest, UnlockTests) {
ASSERT_TRUE(static_cast<bool>(so_unlock3));
ASSERT_TRUE(*so_unlock3 == 1);

so_unlock3.reset(so2); //reset with argument
so_unlock3.acquire(so2); //reset with argument
ASSERT_TRUE(static_cast<bool>(so_unlock3));
ASSERT_TRUE(*so_unlock3 == 2);

so_unlock3.reset(so2); //reset is idempotent
so_unlock3.acquire(so2); //reset is idempotent
ASSERT_TRUE(static_cast<bool>(so_unlock3));
ASSERT_TRUE(*so_unlock3 == 2);
}
Expand Down

0 comments on commit 44f9d19

Please sign in to comment.