Add DCHECKs for checking that underlying IOBuf wasn't modified
[folly.git] / folly / Synchronized.h
index 238b2d8ea2c02522c79176e17f19f898113c8558..7b016a1436bd5985232ef68ff35fc7df7645ee37 100644 (file)
@@ -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.
@@ -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.
    */