libfoedus-core
FOEDUS Core Library
initializable.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #include "foedus/initializable.hpp"
19 
20 #include <glog/logging.h>
21 
22 #include <cstdlib>
23 #include <iostream>
24 #include <typeinfo>
25 
26 #include "foedus/assert_nd.hpp"
27 
28 namespace foedus {
30  if (target_->is_initialized()) {
31  if (policy_ != kSilent) {
32  LOG(ERROR) << "UninitializeGuard has found that " << typeid(*target_).name()
33  << "#uninitialize() was not called when it was destructed. This is a BUG!"
34  << " We must call uninitialize() before destructors!";
36  }
37  if (policy_ == kAbortIfNotExplicitlyUninitialized) {
38  LOG(FATAL) << "FATAL: According to kAbortIfNotExplicitlyUninitialized policy,"
39  << " we abort the program" << std::endl;
40  ASSERT_ND(false);
41  std::abort();
42  } else {
43  // okay, call uninitialize().
44  ErrorStack error = target_->uninitialize();
45  // Note that this is AFTER uninitialize(). "target_" might be Engine
46  // or DebuggingSupports. So, we might not be able to use glog any more.
47  // Thus, we must use stderr in this case.
48  if (error.is_error()) {
49  switch (policy_) {
51  std::cerr << "FATAL: UninitializeGuard encounters an error on uninitialize()."
52  << " Aborting as we can't propagate this error appropriately."
53  << " error=" << error << std::endl;
54  ASSERT_ND(false);
55  std::abort();
56  break;
58  std::cerr << "WARN: UninitializeGuard encounters an error on uninitialize()."
59  << " We can't propagate this error appropriately. Not cool!"
60  << " error=" << error << std::endl;
61  break;
62  default:
63  // warns nothing. this policy is NOT recommended
64  ASSERT_ND(policy_ == kSilent);
65  }
66  } else {
67  if (policy_ != kSilent) {
68  std::cerr << "But, fortunately uninitialize() didn't return errors, phew"
69  << std::endl;
70  }
71  }
72  }
73  }
74 }
75 } // namespace foedus
76 
Automatically calls if uninitialize() wasn't called when it gets out of scope, and just complains whe...
Automatically calls if uninitialize() wasn't called when it gets out of scope, and does nothing even ...
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Terminates the entire program if uninitialize() wasn't called when it gets out of scope...
Automatically calls if uninitialize() wasn't called when it gets out of scope, and terminates the ent...
virtual ErrorStack uninitialize()=0
An idempotent method to release all resources of this object, if any.
std::string print_backtrace()
Prints out backtrace.
Definition: assert_nd.cpp:37
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
virtual bool is_initialized() const =0
Returns whether the object has been already initialized or not.
bool is_error() const
Returns if this return code is not kErrorCodeOk.