TensorFlow Serving C++ API Documentation
fake_loader.cc
1 /* Copyright 2016 Google Inc. 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_serving/core/test_util/fake_loader.h"
17 
18 #include "tensorflow/core/lib/core/errors.h"
19 
20 namespace tensorflow {
21 namespace serving {
22 namespace test_util {
23 
24 thread_local bool FakeLoader::was_deleted_in_this_thread_;
25 int FakeLoader::num_fake_loaders_ = 0;
26 mutex FakeLoader::num_fake_loaders_mu_(LINKER_INITIALIZED);
27 
28 FakeLoader::FakeLoader(int64_t servable, const Status load_status)
29  : servable_(servable), load_status_(load_status) {
30  was_deleted_in_this_thread_ = false;
31  {
32  mutex_lock l(num_fake_loaders_mu_);
33  ++num_fake_loaders_;
34  }
35 }
36 
37 FakeLoader::~FakeLoader() {
38  {
39  mutex_lock l(num_fake_loaders_mu_);
40  --num_fake_loaders_;
41  }
42  was_deleted_in_this_thread_ = true;
43 }
44 
45 Status FakeLoader::load_status() { return load_status_; }
46 
47 Status FakeLoader::Load() { return load_status_; }
48 
49 void FakeLoader::Unload() {}
50 
51 AnyPtr FakeLoader::servable() { return AnyPtr(&servable_); }
52 
53 bool FakeLoader::was_deleted_in_this_thread() {
54  return was_deleted_in_this_thread_;
55 }
56 
57 int FakeLoader::num_fake_loaders() {
58  mutex_lock l(num_fake_loaders_mu_);
59  return num_fake_loaders_;
60 }
61 
62 } // namespace test_util
63 } // namespace serving
64 } // namespace tensorflow