libfoedus-core
FOEDUS Core Library
log_type_invoke.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  */
19 
20 #include <iostream>
21 
22 namespace foedus {
23 namespace log {
24 
25 #define X(a, b, c) case a: return reinterpret_cast< c* >(buffer)->apply_engine(context);
26 void invoke_apply_engine(void *buffer, thread::Thread* context) {
27  invoke_assert_valid(buffer);
28  LogHeader* header = reinterpret_cast<LogHeader*>(buffer);
29  LogCode code = header->get_type();
30  switch (code) {
31 #include "foedus/log/log_type.xmacro" // NOLINT
32  default:
33  ASSERT_ND(false);
34  return;
35  }
36 }
37 #undef X
38 
39 #define X(a, b, c) case a: \
40  reinterpret_cast< c* >(buffer)->apply_storage(engine, storage_id); return;
41 void invoke_apply_storage(void *buffer, Engine* engine, storage::StorageId storage_id) {
42  invoke_assert_valid(buffer);
43  LogHeader* header = reinterpret_cast<LogHeader*>(buffer);
44  LogCode code = header->get_type();
45  switch (code) {
46 #include "foedus/log/log_type.xmacro" // NOLINT
47  default:
48  ASSERT_ND(false);
49  return;
50  }
51 }
52 #undef X
53 
54 
55 #define X(a, b, c) case a: o << *reinterpret_cast< const c* >(buffer); break;
56 void invoke_ostream(const void *buffer, std::ostream *ptr) {
57  const LogHeader* header = reinterpret_cast<const LogHeader*>(buffer);
58  LogCode code = header->get_type();
59  std::ostream &o = *ptr;
60  switch (code) {
61  case kLogCodeInvalid: break;
62 #include "foedus/log/log_type.xmacro" // NOLINT
63  }
64 }
65 #undef X
66 
67 } // namespace log
68 } // namespace foedus
LogCode
A unique identifier of all log types.
Definition: log_type.hpp:87
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
void invoke_apply_engine(void *log_buffer, thread::Thread *context)
Invokes the apply logic for an engine-wide log type.
void invoke_assert_valid(void *log_buffer)
Invokes the assertion logic of each log type.
void invoke_apply_storage(void *log_buffer, Engine *engine, storage::StorageId id)
Invokes the apply logic for a storage-wide log type.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
A common header part for all log types.
0 is reserved as a non-existing log type.
Definition: log_type.hpp:89
void invoke_ostream(const void *buffer, std::ostream *ptr)
Invokes the ostream operator for the given log type defined in log_type.xmacro.
LogCode get_type() const __attribute__((always_inline))
Convenience method to cast into LogCode.
#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