16 #ifndef TENSORFLOW_SERVING_SESSION_BUNDLE_GRAPH_REWRITER_H_
17 #define TENSORFLOW_SERVING_SESSION_BUNDLE_GRAPH_REWRITER_H_
22 #include "absl/base/thread_annotations.h"
23 #include "absl/synchronization/mutex.h"
24 #include "tensorflow/core/platform/errors.h"
25 #include "tensorflow/core/platform/status.h"
26 #include "tensorflow/core/protobuf/meta_graph.pb.h"
28 namespace tensorflow {
39 Status Set(std::function<Status(tensorflow::MetaGraphDef*)>&& rewriter) {
40 absl::MutexLock l(&m_);
41 if (rewriter_ !=
nullptr)
42 return errors::AlreadyExists(
"Graph rewriter already set.");
44 rewriter_ = std::move(rewriter);
50 Status ResetForTesting() {
51 absl::MutexLock l(&m_);
56 std::function<Status(tensorflow::MetaGraphDef*)>& Get() {
57 absl::MutexLock l(&m_);
62 absl::MutexLock l(&m_);
63 return rewriter_ !=
nullptr;
70 std::function<Status(tensorflow::MetaGraphDef*)> rewriter_
78 inline Status SetGraphRewriter(
79 std::function<Status(tensorflow::MetaGraphDef*)>&& rewriter) {
80 return GraphRewriter::GetGlobal().Set(std::move(rewriter));
84 inline Status ResetGraphRewriterForTesting() {
85 return GraphRewriter::GetGlobal().ResetForTesting();