You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/12/02 17:56:57 UTC
[03/14] git commit: Renamed Shared::upgrade() to Shared::own().
Renamed Shared::upgrade() to Shared::own().
From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15739
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6e251cc7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6e251cc7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6e251cc7
Branch: refs/heads/master
Commit: 6e251cc7a6f32aab464ec725f56fbf201451460e
Parents: 845ff1b
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:50:26 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:50:26 2013 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/shared.hpp | 24 ++++++++++-----------
3rdparty/libprocess/src/tests/shared_tests.cpp | 12 +++++------
2 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6e251cc7/3rdparty/libprocess/include/process/shared.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/shared.hpp b/3rdparty/libprocess/include/process/shared.hpp
index e0c7991..475a18c 100644
--- a/3rdparty/libprocess/include/process/shared.hpp
+++ b/3rdparty/libprocess/include/process/shared.hpp
@@ -33,12 +33,12 @@ public:
void reset(T* t);
void swap(Shared<T>& that);
- // Upgrading from a shared pointer to an owned pointer. This shared
- // pointer will be reset after this function is invoked. If two
- // shared pointers pointing to the same object both want to be
- // upgraded, only one of them may succeed and the other one will get
- // a failed future.
- Future<Owned<T> > upgrade();
+ // Transfers ownership of the pointer by waiting for exclusive
+ // access (i.e., no other Shared instances). This shared pointer
+ // will be reset after this function is invoked. If multiple shared
+ // pointers pointing to the same object all want to be upgraded,
+ // only one of them may succeed and the rest will get failures.
+ Future<Owned<T> > own();
private:
struct Data
@@ -47,7 +47,7 @@ private:
~Data();
T* t;
- volatile bool upgraded;
+ volatile bool owned;
Promise<Owned<T> > promise;
};
@@ -140,7 +140,7 @@ void Shared<T>::swap(Shared<T>& that)
template <typename T>
-Future<Owned<T> > Shared<T>::upgrade()
+Future<Owned<T> > Shared<T>::own()
{
// If two threads simultaneously access this object and at least one
// of them is a write, the behavior is undefined. This is similar to
@@ -150,8 +150,8 @@ Future<Owned<T> > Shared<T>::upgrade()
return Owned<T>(NULL);
}
- if (!__sync_bool_compare_and_swap(&data->upgraded, false, true)) {
- return Future<Owned<T> >::failed("An upgrade is already being performed");
+ if (!__sync_bool_compare_and_swap(&data->owned, false, true)) {
+ return Future<Owned<T> >::failed("Ownership has already been transferred");
}
Future<Owned<T> > future = data->promise.future();
@@ -162,13 +162,13 @@ Future<Owned<T> > Shared<T>::upgrade()
template <typename T>
Shared<T>::Data::Data(T* _t)
- : t(CHECK_NOTNULL(_t)), upgraded(false) {}
+ : t(CHECK_NOTNULL(_t)), owned(false) {}
template <typename T>
Shared<T>::Data::~Data()
{
- if (upgraded) {
+ if (owned) {
promise.set(Owned<T>(t));
} else {
delete t;
http://git-wip-us.apache.org/repos/asf/mesos/blob/6e251cc7/3rdparty/libprocess/src/tests/shared_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/shared_tests.cpp b/3rdparty/libprocess/src/tests/shared_tests.cpp
index 860a9aa..d4fc031 100644
--- a/3rdparty/libprocess/src/tests/shared_tests.cpp
+++ b/3rdparty/libprocess/src/tests/shared_tests.cpp
@@ -63,7 +63,7 @@ TEST(Shared, Reset)
}
-TEST(Shared, Upgrade)
+TEST(Shared, Own)
{
Foo* foo = new Foo();
foo->set(42);
@@ -86,15 +86,15 @@ TEST(Shared, Upgrade)
EXPECT_FALSE(shared2.unique());
EXPECT_FALSE(shared.unique());
- future = shared2.upgrade();
+ future = shared2.own();
- // A shared pointer will be reset after it called upgrade.
+ // A shared pointer will be reset after it called 'own'.
EXPECT_TRUE(shared2.get() == NULL);
- // Only one upgrade is allowed.
- AWAIT_FAILED(shared.upgrade());
+ // Do not allow 'own' to be called twice.
+ AWAIT_FAILED(shared.own());
- // Upgrade is not done yet as 'shared' is still holding the reference.
+ // Not "owned" yet as 'shared' is still holding the reference.
EXPECT_TRUE(future.isPending());
}