提交 a61eb543 编写于 作者: M minqiyang

Add RWLock to Scope

上级 1b61021c
......@@ -16,7 +16,9 @@ limitations under the License. */
#if !defined(_WIN32)
#include <pthread.h>
#endif // !_WIN32
#else
#include <mutex> // NOLINT
#endif // !_WIN32
#include "paddle/fluid/platform/enforce.h"
......@@ -51,9 +53,15 @@ struct RWLock {
// https://stackoverflow.com/questions/7125250/making-pthread-rwlock-wrlock-recursive
// In windows, rw_lock seems like a hack. Use empty object and do nothing.
struct RWLock {
void RDLock() {}
void WRLock() {}
void UNLock() {}
// FIXME(minqiyang): use mutex here to do fake lock
void RDLock() { mutex_.lock(); }
void WRLock() { mutex_.lock(); }
void UNLock() { mutex_.unlock(); }
private:
std::mutex mutex_;
};
#endif
......
......@@ -46,13 +46,10 @@ DEFINE_double(
#define SCOPE_READER_LOCK
#define SCOPE_WRITER_LOCK
#else
// TODO(minqiyang): use reader lock and writer lock in all platforms
#define SCOPE_READER_LOCK
#define SCOPE_WRITER_LOCK
// #define SCOPE_READER_LOCK boost::shared_lock<boost::shared_mutex>
// lock(mutex_);
// #define SCOPE_WRITER_LOCK boost::unique_lock<boost::shared_mutex>
// lock(mutex_);
// TODO(minqiyang): use rwlock in all platforms, now rwlock is a fake one
// in _WIN32 platform
#define SCOPE_READER_LOCK RWLockGuard(&rw_lock_, RWLockGuard::Status::kRDLock);
#define SCOPE_WRITER_LOCK RWLockGuard(&rw_lock_, RWLockGuard::Status::kWRLock);
#endif
namespace paddle {
......
......@@ -15,11 +15,11 @@ limitations under the License. */
#pragma once
#include <list>
#include <mutex> // NOLINT
#include <string>
#include <unordered_map>
#include <vector>
#include "paddle/fluid/framework/rw_lock.h"
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/platform/macros.h"
......@@ -123,7 +123,7 @@ class Scope {
DISABLE_COPY_AND_ASSIGN(Scope);
private:
mutable std::mutex mutex_;
mutable RWLock rw_lock_;
};
// Generate some debug string about the inherience structure of scope, quite
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册