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