/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2011-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Lets you construct non-movable types in-place. Use the constexpr
- * instance `construct_in_place` as the first argument.
+ * instance `in_place` as the first argument.
*/
template <typename... Args>
- explicit Synchronized(construct_in_place_t, Args&&... args)
+ explicit Synchronized(in_place_t, Args&&... args)
: datum_(std::forward<Args>(args)...) {}
/**
/**
* Attempts to acquire for a given number of milliseconds. If
- * acquisition is unsuccessful, the returned LockedPtr is NULL.
+ * acquisition is unsuccessful, the returned LockedPtr is nullptr.
*
* NOTE: This API is deprecated. Use lock(), wlock(), or rlock() instead.
* In the future it will be marked with a deprecation attribute to emit
/**
* Attempts to acquire for a given number of milliseconds. If
- * acquisition is unsuccessful, the returned ConstLockedPtr is NULL.
+ * acquisition is unsuccessful, the returned ConstLockedPtr is nullptr.
*
* NOTE: This API is deprecated. Use lock(), wlock(), or rlock() instead.
* In the future it will be marked with a deprecation attribute to emit
swap(datum_, rhs);
}
+ /**
+ * Assign another datum and return the original value. Recommended
+ * because it keeps the mutex held only briefly.
+ */
+ T exchange(T&& rhs) {
+ swap(rhs);
+ return std::move(rhs);
+ }
+
/**
* Copies datum to a given target.
*/
std::is_const<SynchronizedType>::value,
typename SynchronizedType::ConstLockedPtr,
typename SynchronizedType::LockedPtr>::type;
-} // detail
+} // namespace detail
/**
* A helper base class for implementing LockedPtr.