aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/distributed_runtime/master.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/distributed_runtime/master.cc')
-rw-r--r--tensorflow/core/distributed_runtime/master.cc46
1 files changed, 19 insertions, 27 deletions
diff --git a/tensorflow/core/distributed_runtime/master.cc b/tensorflow/core/distributed_runtime/master.cc
index 4ff2d0f5e3..d1dc622ce7 100644
--- a/tensorflow/core/distributed_runtime/master.cc
+++ b/tensorflow/core/distributed_runtime/master.cc
@@ -116,6 +116,18 @@ void Master::GC() {
}
}
+MasterSession* Master::FindMasterSession(const string& handle) {
+ MasterSession* session = nullptr;
+ {
+ mutex_lock l(mu_);
+ session = gtl::FindPtrOrNull(sessions_, handle);
+ if (session != nullptr) {
+ session->Ref();
+ }
+ }
+ return session;
+}
+
class DeviceFinder {
public:
static Status GetRemoteDevices(
@@ -429,16 +441,11 @@ void Master::CreateSession(const CreateSessionRequest* req,
void Master::ExtendSession(const ExtendSessionRequest* req,
ExtendSessionResponse* resp, MyClosure done) {
- mu_.lock();
- MasterSession* session = nullptr;
- session = gtl::FindPtrOrNull(sessions_, req->session_handle());
+ auto session = FindMasterSession(req->session_handle());
if (session == nullptr) {
- mu_.unlock();
done(errors::Aborted("Session ", req->session_handle(), " is not found."));
return;
}
- session->Ref();
- mu_.unlock();
SchedClosure([session, req, resp, done]() {
Status status = ValidateExternalGraphDefSyntax(req->graph_def());
@@ -452,15 +459,11 @@ void Master::ExtendSession(const ExtendSessionRequest* req,
void Master::PartialRunSetup(const PartialRunSetupRequest* req,
PartialRunSetupResponse* resp, MyClosure done) {
- mu_.lock();
- MasterSession* session = gtl::FindPtrOrNull(sessions_, req->session_handle());
+ auto session = FindMasterSession(req->session_handle());
if (session == nullptr) {
- mu_.unlock();
done(errors::Aborted("Session ", req->session_handle(), " is not found."));
return;
}
- session->Ref();
- mu_.unlock();
SchedClosure([this, session, req, resp, done]() {
Status s = session->PartialRunSetup(req, resp);
@@ -471,16 +474,12 @@ void Master::PartialRunSetup(const PartialRunSetupRequest* req,
void Master::RunStep(CallOptions* opts, const RunStepRequestWrapper* req,
MutableRunStepResponseWrapper* resp, MyClosure done) {
- mu_.lock();
- uint64 start_time = env_->env->NowMicros();
- MasterSession* session = gtl::FindPtrOrNull(sessions_, req->session_handle());
+ auto start_time = env_->env->NowMicros();
+ auto session = FindMasterSession(req->session_handle());
if (session == nullptr) {
- mu_.unlock();
done(errors::Aborted("Session ", req->session_handle(), " is not found."));
return;
}
- session->Ref();
- mu_.unlock();
SchedClosure([this, start_time, session, opts, req, resp, done]() {
Status status = session->Run(opts, *req, resp);
@@ -526,18 +525,11 @@ void Master::ListDevices(const ListDevicesRequest* req,
ListDevicesResponse* resp, MyClosure done) {
SchedClosure([this, req, resp, done]() {
if (!req->session_handle().empty()) {
- MasterSession* session = nullptr;
- {
- mutex_lock l(mu_);
- session = gtl::FindPtrOrNull(sessions_, req->session_handle());
- if (session != nullptr) {
- session->Ref();
- }
- }
+ auto session = FindMasterSession(req->session_handle());
if (session == nullptr) {
done(errors::InvalidArgument(
- "Session ", req->session_handle(),
- " is not found. Possibly, this master has restarted."));
+ "Session ", req->session_handle(),
+ " is not found. Possibly, this master has restarted."));
return;
}
core::ScopedUnref ref(session);