File tree 1 file changed +11
-6
lines changed
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
#include < c10/macros/Macros.h>
2
- #include < c10/util/Synchronized.h>
3
2
#include < array>
4
3
#include < atomic>
5
4
#include < functional>
@@ -193,9 +192,13 @@ class LeftRight final {
193
192
// read-write lock to protect T (data).
194
193
template <class T >
195
194
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
+
196
199
public:
197
200
template <class ... Args>
198
- explicit RWSafeLeftRightWrapper (const Args&... args) : data_ {args...} {}
201
+ explicit RWSafeLeftRightWrapper (const Args&... args) : _data {args...} {}
199
202
200
203
// RWSafeLeftRightWrapper is not copyable or moveable since LeftRight
201
204
// is not copyable or moveable.
@@ -206,17 +209,19 @@ class RWSafeLeftRightWrapper final {
206
209
207
210
template <typename F>
208
211
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 );
211
214
}
212
215
213
216
template <typename F>
214
217
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);
216
220
}
217
221
218
222
private:
219
- c10::Synchronized<T> data_;
223
+ T _data;
224
+ mutable mutexType mutex_;
220
225
};
221
226
222
227
} // namespace c10
You can’t perform that action at this time.
0 commit comments