aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/grappler/utils.cc
diff options
context:
space:
mode:
authorGravatar Vinu Rajashekhar <vinuraja@google.com>2017-03-15 23:24:41 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-16 00:49:09 -0700
commit1ce242420ecb64b196f29d510f51e795c92696ca (patch)
treeca46b71b5e52f90b39efcf7e60bc7a221e9552bc /tensorflow/core/grappler/utils.cc
parent91d502ad1f752838371c0f5059c1b2dce5f6e074 (diff)
- Makes SingleMachine::Run(...) thread-safe.
Change: 150289918
Diffstat (limited to 'tensorflow/core/grappler/utils.cc')
-rw-r--r--tensorflow/core/grappler/utils.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/tensorflow/core/grappler/utils.cc b/tensorflow/core/grappler/utils.cc
index 35e62432bb..03ae6b8278 100644
--- a/tensorflow/core/grappler/utils.cc
+++ b/tensorflow/core/grappler/utils.cc
@@ -13,11 +13,14 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
-#include "tensorflow/core/grappler/utils.h"
+#include <memory>
+
#include "tensorflow/core/common_runtime/gpu/gpu_init.h"
+#include "tensorflow/core/grappler/utils.h"
#include "tensorflow/core/lib/strings/scanner.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/cpu_info.h"
+#include "tensorflow/core/platform/notification.h"
#include "tensorflow/core/platform/stream_executor.h"
namespace tensorflow {
@@ -96,5 +99,24 @@ string AddPrefixToNodeName(const string& name, const string& prefix) {
return strings::StrCat(prefix, "-", name);
}
+bool ExecuteWithTimeout(std::function<void()> fn, const int64 timeout_in_ms,
+ thread::ThreadPool* const thread_pool) {
+ if (timeout_in_ms <= 0) {
+ fn();
+ return true;
+ }
+ auto done = std::make_shared<Notification>();
+ thread_pool->Schedule([done, &fn]() {
+ fn();
+ done->Notify();
+ });
+ const bool notified =
+ WaitForNotificationWithTimeout(done.get(), timeout_in_ms * 1000);
+ if (!notified) {
+ return false;
+ }
+ return true;
+}
+
} // end namespace grappler
} // end namespace tensorflow