libfoedus-core
FOEDUS Core Library
thread_group.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 <ostream>
21 #include <vector>
22 
23 #include "foedus/engine.hpp"
27 #include "foedus/thread/thread.hpp"
29 
30 namespace foedus {
31 namespace thread {
33  : engine_(engine), group_id_(group_id) {
34 }
36 }
37 
39  node_memory_ = engine_->get_memory_manager()->get_local_memory();
41  for (ThreadLocalOrdinal ordinal = 0; ordinal < count; ++ordinal) {
42  ThreadId id = compose_thread_id(group_id_, ordinal);
43  ThreadGlobalOrdinal global_ordinal = to_global_ordinal(id, count);
44  threads_.push_back(new Thread(engine_, id, global_ordinal));
45  CHECK_ERROR(threads_.back()->initialize());
46  }
47  return kRetOk;
48 }
49 
51  ErrorStackBatch batch;
52  batch.uninitialize_and_delete_all(&threads_);
53  node_memory_ = nullptr;
54  return SUMMARIZE_ERROR_BATCH(batch);
55 }
56 
57 std::ostream& operator<<(std::ostream& o, const ThreadGroup& v) {
58  o << "<ThreadGroup>";
59  o << "<group_id_>" << static_cast<int>(v.group_id_) << "</group_id_>";
60  o << "<threads_>";
61  for (Thread* child_thread : v.threads_) {
62  o << *child_thread;
63  }
64  o << "</threads_>";
65  o << "</ThreadGroup>";
66  return o;
67 }
68 
69 } // namespace thread
70 } // namespace foedus
ErrorStack initialize_once() override
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
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
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
ErrorStack uninitialize_once() override
const EngineOptions & get_options() const
Definition: engine.cpp:39
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
Represents a group of pre-allocated threads running in one NUMA node.
Batches zero or more ErrorStack objects to represent in one ErrorStack.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
ThreadId compose_thread_id(ThreadGroupId node, ThreadLocalOrdinal local_core)
Returns a globally unique ID of Thread (core) for the given node and ordinal in the node...
Definition: thread_id.hpp:123
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
uint16_t ThreadGlobalOrdinal
Typedef for a globally and contiguously numbered ID of thread.
Definition: thread_id.hpp:98
thread::ThreadOptions thread_
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
NumaNodeMemory * get_local_memory() const
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
void uninitialize_and_delete_all(std::vector< T * > *vec)
A convenience method to uninitialize and delete all Initializable objects in a vector, storing all errors in this batch.
const ErrorStack kRetOk
Normal return value for no-error case.
std::ostream & operator<<(std::ostream &o, const ImpersonateSession &v)
ThreadGlobalOrdinal to_global_ordinal(ThreadId thread_id, uint8_t threads_per_nodes)
Calculate ThreadGlobalOrdinal from ThreadId.
Definition: thread_id.hpp:147
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
Definition: engine.cpp:50