X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FSynchronized.h;h=7b016a1436bd5985232ef68ff35fc7df7645ee37;hp=5b6f9fc0e6b6372f9b132f2e6aed469f83fc66cb;hb=4bfbe0a10e914c3626e16cfdb9e87508e63b065f;hpb=ed8c80a0e0988e4ce687f51ca832a00e4a6b7930 diff --git a/folly/Synchronized.h b/folly/Synchronized.h index 5b6f9fc0..7b016a14 100644 --- a/folly/Synchronized.h +++ b/folly/Synchronized.h @@ -1,5 +1,5 @@ /* - * 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. @@ -491,10 +491,10 @@ struct Synchronized : public SynchronizedBase< /** * 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 - explicit Synchronized(construct_in_place_t, Args&&... args) + explicit Synchronized(in_place_t, Args&&... args) : datum_(std::forward(args)...) {} /** @@ -626,7 +626,7 @@ struct Synchronized : public SynchronizedBase< /** * 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 @@ -638,7 +638,7 @@ struct Synchronized : public SynchronizedBase< /** * 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 @@ -691,6 +691,15 @@ struct Synchronized : public SynchronizedBase< 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. */ @@ -757,7 +766,7 @@ using LockedPtrType = typename std::conditional< std::is_const::value, typename SynchronizedType::ConstLockedPtr, typename SynchronizedType::LockedPtr>::type; -} // detail +} // namespace detail /** * A helper base class for implementing LockedPtr. @@ -1320,7 +1329,7 @@ void swap(Synchronized& lhs, Synchronized& rhs) { */ #define SYNCHRONIZED(...) \ FOLLY_PUSH_WARNING \ - FOLLY_GCC_DISABLE_WARNING(shadow) \ + FOLLY_GCC_DISABLE_WARNING("-Wshadow") \ FOLLY_MSVC_DISABLE_WARNING(4189) /* initialized but unreferenced */ \ FOLLY_MSVC_DISABLE_WARNING(4456) /* declaration hides local */ \ FOLLY_MSVC_DISABLE_WARNING(4457) /* declaration hides parameter */ \