Skip to content

Commit b65adf8

Browse files
suopytorchmergebot
authored andcommitted
Revert D34645508: [PyTorch] Use c10::Synchronized<T> in RWSafeLeftRightWrapper
Test Plan: revert-hammer Differential Revision: D34645508 (pytorch@62ff23d) Original commit changeset: effa8064f925 Original Phabricator Diff: D34645508 (pytorch@62ff23d) fbshipit-source-id: 4f9bfc79c06a626fccc5cad9faeaa33e00f4f718 (cherry picked from commit ed51c6c)
1 parent 1ac519e commit b65adf8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

c10/util/LeftRight.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <c10/macros/Macros.h>
2-
#include <c10/util/Synchronized.h>
32
#include <array>
43
#include <atomic>
54
#include <functional>
@@ -193,9 +192,13 @@ class LeftRight final {
193192
// read-write lock to protect T (data).
194193
template <class T>
195194
class RWSafeLeftRightWrapper final {
195+
using mutexType = std::mutex;
196+
using rLockType = std::unique_lock<std::mutex>;
197+
using wLockType = std::unique_lock<std::mutex>;
198+
196199
public:
197200
template <class... Args>
198-
explicit RWSafeLeftRightWrapper(const Args&... args) : data_{args...} {}
201+
explicit RWSafeLeftRightWrapper(const Args&... args) : _data{args...} {}
199202

200203
// RWSafeLeftRightWrapper is not copyable or moveable since LeftRight
201204
// is not copyable or moveable.
@@ -206,17 +209,19 @@ class RWSafeLeftRightWrapper final {
206209

207210
template <typename F>
208211
auto read(F&& readFunc) const -> typename std::result_of<F(const T&)>::type {
209-
return data_.withLock(
210-
[&readFunc](T const& data) { return readFunc(data); });
212+
rLockType lock(mutex_);
213+
return readFunc(_data);
211214
}
212215

213216
template <typename F>
214217
auto write(F&& writeFunc) -> typename std::result_of<F(T&)>::type {
215-
return data_.withLock([&writeFunc](T& data) { return writeFunc(data); });
218+
wLockType lock(mutex_);
219+
return writeFunc(_data);
216220
}
217221

218222
private:
219-
c10::Synchronized<T> data_;
223+
T _data;
224+
mutable mutexType mutex_;
220225
};
221226

222227
} // namespace c10

0 commit comments

Comments
 (0)