1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include "tensorflow/core/distributed_runtime/call_options.h"
17
18#include "tensorflow/core/platform/mutex.h"
19
20namespace tensorflow {
21
22CallOptions::CallOptions() {}
23
24void CallOptions::StartCancel() {
25 mutex_lock l(mu_);
26 if (cancel_func_ != nullptr) {
27 // NOTE: We must call the cancel_func_ with mu_ held. This ensure
28 // that ClearCancelCallback() does not race with StartCancel().
29 cancel_func_();
30 // NOTE: We can clear cancel_func_ if needed.
31 }
32}
33
34void CallOptions::SetCancelCallback(CancelFunction cancel_func) {
35 mutex_lock l(mu_);
36 cancel_func_ = std::move(cancel_func);
37}
38
39void CallOptions::ClearCancelCallback() {
40 mutex_lock l(mu_);
41 cancel_func_ = nullptr;
42}
43
44int64_t CallOptions::GetTimeout() {
45 mutex_lock l(mu_);
46 return timeout_in_ms_;
47}
48
49void CallOptions::SetTimeout(int64_t ms) {
50 mutex_lock l(mu_);
51 timeout_in_ms_ = ms;
52}
53
54} // end namespace tensorflow
55