13 #ifndef __PROCESS_SHARED_HPP__
14 #define __PROCESS_SHARED_HPP__
19 #include <glog/logging.h>
39 bool operator<(const Shared<T>& that)
const;
50 void swap(Shared<T>& that);
57 Future<Owned<T>>
own();
66 std::atomic_bool owned;
70 std::shared_ptr<Data> data;
82 data.reset(
new Data(t));
90 return data == that.data;
97 return data < that.data;
101 template <
typename T>
104 return *CHECK_NOTNULL(
get());
108 template <
typename T>
111 return CHECK_NOTNULL(
get());
115 template <
typename T>
118 if (data ==
nullptr) {
126 template <
typename T>
129 return data.unique();
133 template <
typename T>
140 template <
typename T>
146 data.reset(
new Data(t));
151 template <
typename T>
154 data.swap(that.data);
158 template <
typename T>
165 if (data ==
nullptr) {
169 bool false_value =
false;
170 if (!data->owned.compare_exchange_strong(false_value,
true)) {
171 return Failure(
"Ownership has already been transferred");
180 template <
typename T>
182 : t(CHECK_NOTNULL(_t)), owned(false) {}
185 template <
typename T>
186 Shared<T>::Data::~Data()
197 #endif // __PROCESS_SHARED_HPP__
Definition: future.hpp:664
void reset()
Definition: shared.hpp:134
bool operator<(const Shared< T > &that) const
Definition: shared.hpp:95
bool operator==(const Shared< T > &that) const
Definition: shared.hpp:88
bool unique() const
Definition: shared.hpp:127
Protocol< PromiseRequest, PromiseResponse > promise
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
const T * operator->() const
Definition: shared.hpp:109
Shared()
Definition: shared.hpp:75
const T & operator*() const
Definition: shared.hpp:102
Future< Owned< T > > own()
Definition: shared.hpp:159
const T * get() const
Definition: shared.hpp:116
void swap(Shared< T > &that)
Definition: shared.hpp:152
Definition: future.hpp:57