Synchronized::exchange
[folly.git] / folly / Synchronized.h
index 094dcdf02af8e9e42fe7827396b780af620b79f8..7b016a1436bd5985232ef68ff35fc7df7645ee37 100644 (file)
@@ -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.
    */