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/debug/debug_callback_registry.h" 17 18 namespace tensorflow { 19 DebugCallbackRegistry()20DebugCallbackRegistry::DebugCallbackRegistry() {} 21 22 /*static */ DebugCallbackRegistry* DebugCallbackRegistry::instance_ = nullptr; 23 singleton()24DebugCallbackRegistry* DebugCallbackRegistry::singleton() { 25 if (instance_ == nullptr) { 26 instance_ = new DebugCallbackRegistry(); 27 } 28 return instance_; 29 } 30 RegisterCallback(const string & key,EventCallback callback)31void DebugCallbackRegistry::RegisterCallback(const string& key, 32 EventCallback callback) { 33 mutex_lock lock(mu_); 34 keyed_callback_[key] = std::move(callback); 35 } 36 GetCallback(const string & key)37DebugCallbackRegistry::EventCallback* DebugCallbackRegistry::GetCallback( 38 const string& key) { 39 mutex_lock lock(mu_); 40 auto iter = keyed_callback_.find(key); 41 return iter == keyed_callback_.end() ? nullptr : &iter->second; 42 } 43 UnregisterCallback(const string & key)44void DebugCallbackRegistry::UnregisterCallback(const string& key) { 45 mutex_lock lock(mu_); 46 keyed_callback_.erase(key); 47 } 48 49 } // namespace tensorflow 50