libfoedus-core
FOEDUS Core Library
foedus::thread::ThreadPoolPimpl Class Referencefinal

Pimpl object of ThreadPool. More...

Detailed Description

Pimpl object of ThreadPool.

A private pimpl object for ThreadPool. Do not include this header from a client program unless you know what you are doing.

Definition at line 41 of file thread_pool_pimpl.hpp.

#include <thread_pool_pimpl.hpp>

Inheritance diagram for foedus::thread::ThreadPoolPimpl:
Collaboration diagram for foedus::thread::ThreadPoolPimpl:

Public Member Functions

 ThreadPoolPimpl ()=delete
 
 ThreadPoolPimpl (Engine *engine)
 
ErrorStack initialize_once () override
 
ErrorStack uninitialize_once () override
 
bool impersonate (const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
 
bool impersonate_on_numa_node (ThreadGroupId node, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
 
bool impersonate_on_numa_core (ThreadId core, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
 
ThreadGroupRefget_group (ThreadGroupId numa_node)
 
ThreadGroupget_local_group () const
 
ThreadRefget_thread (ThreadId id)
 
ThreadRef get_thread_ref (ThreadId id) __attribute__((always_inline))
 For better performance, but for some reason this method causes an issue in MCS lock. More...
 
- Public Member Functions inherited from foedus::DefaultInitializable
 DefaultInitializable ()
 
virtual ~DefaultInitializable ()
 
 DefaultInitializable (const DefaultInitializable &)=delete
 
DefaultInitializableoperator= (const DefaultInitializable &)=delete
 
ErrorStack initialize () override final
 Typical implementation of Initializable::initialize() that provides initialize-once semantics. More...
 
ErrorStack uninitialize () override final
 Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics. More...
 
bool is_initialized () const override final
 Returns whether the object has been already initialized or not. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Public Attributes

Engine *const engine_
 
ThreadGrouplocal_group_
 Thread group of the local SOC engine. More...
 
std::vector< ThreadGroupRefgroups_
 List of all thread groups, one for each NUMA node in this engine. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const ThreadPoolPimpl &v)
 

Constructor & Destructor Documentation

foedus::thread::ThreadPoolPimpl::ThreadPoolPimpl ( )
delete
foedus::thread::ThreadPoolPimpl::ThreadPoolPimpl ( Engine engine)
inlineexplicit

Definition at line 44 of file thread_pool_pimpl.hpp.

44 : engine_(engine), local_group_(nullptr) {}
ThreadGroup * local_group_
Thread group of the local SOC engine.

Member Function Documentation

ThreadGroupRef* foedus::thread::ThreadPoolPimpl::get_group ( ThreadGroupId  numa_node)
inline

Definition at line 66 of file thread_pool_pimpl.hpp.

References groups_.

Referenced by foedus::thread::ThreadPool::get_group_ref(), and get_thread().

66 { return &groups_[numa_node]; }
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.

Here is the caller graph for this function:

ThreadGroup* foedus::thread::ThreadPoolPimpl::get_local_group ( ) const
inline

Definition at line 67 of file thread_pool_pimpl.hpp.

References local_group_.

Referenced by foedus::log::Logger::initialize_once().

67 { return local_group_; }
ThreadGroup * local_group_
Thread group of the local SOC engine.

Here is the caller graph for this function:

ThreadRef * foedus::thread::ThreadPoolPimpl::get_thread ( ThreadId  id)

Definition at line 74 of file thread_pool_pimpl.cpp.

References foedus::thread::decompose_numa_local_ordinal(), foedus::thread::decompose_numa_node(), get_group(), and foedus::thread::ThreadGroupRef::get_thread().

Referenced by foedus::thread::ThreadPool::get_thread_ref(), and impersonate_on_numa_core().

74  {
76 }
ThreadRef * get_thread(ThreadLocalOrdinal ordinal)
Returns Thread object for the given ordinal in this group.
Definition: thread_ref.hpp:115
ThreadLocalOrdinal decompose_numa_local_ordinal(ThreadId global_id)
Extracts local ordinal from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:139
ThreadGroupRef * get_group(ThreadGroupId numa_node)
ThreadGroupId decompose_numa_node(ThreadId global_id)
Extracts NUMA node ID from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:131

Here is the call graph for this function:

Here is the caller graph for this function:

ThreadRef foedus::thread::ThreadPoolPimpl::get_thread_ref ( ThreadId  id)
inline

For better performance, but for some reason this method causes an issue in MCS lock.

Definition at line 92 of file thread_pool_pimpl.hpp.

References foedus::thread::decompose_numa_local_ordinal(), foedus::thread::decompose_numa_node(), and groups_.

Referenced by foedus::thread::ThreadPimpl::get_thread_ref().

92  {
93  ThreadGroupId numa_node = decompose_numa_node(id);
95  return groups_[numa_node].get_thread_ref(core_ordinal);
96 }
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
ThreadLocalOrdinal decompose_numa_local_ordinal(ThreadId global_id)
Extracts local ordinal from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:139
ThreadGroupId decompose_numa_node(ThreadId global_id)
Extracts NUMA node ID from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:131
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::thread::ThreadPoolPimpl::impersonate ( const proc::ProcName proc_name,
const void *  task_input,
uint64_t  task_input_size,
ImpersonateSession session 
)

Definition at line 79 of file thread_pool_pimpl.cpp.

References engine_, foedus::Engine::get_options(), groups_, foedus::EngineOptions::thread_, foedus::thread::ThreadOptions::thread_count_per_group_, and foedus::thread::ThreadRef::try_impersonate().

Referenced by foedus::thread::ThreadPool::impersonate().

83  {
84  uint16_t thread_per_group = engine_->get_options().thread_.thread_count_per_group_;
85  for (ThreadGroupRef& group : groups_) {
86  for (size_t j = 0; j < thread_per_group; ++j) {
87  ThreadRef* thread = group.get_thread(j);
88  if (thread->try_impersonate(proc_name, task_input, task_input_size, session)) {
89  return true;
90  }
91  }
92  }
93  return false;
94 }
const EngineOptions & get_options() const
Definition: engine.cpp:39
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.
thread::ThreadOptions thread_

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::thread::ThreadPoolPimpl::impersonate_on_numa_core ( ThreadId  core,
const proc::ProcName proc_name,
const void *  task_input,
uint64_t  task_input_size,
ImpersonateSession session 
)

Definition at line 111 of file thread_pool_pimpl.cpp.

References get_thread(), and foedus::thread::ThreadRef::try_impersonate().

Referenced by foedus::thread::ThreadPool::impersonate_on_numa_core().

116  {
117  ThreadRef* thread = get_thread(core);
118  return thread->try_impersonate(proc_name, task_input, task_input_size, session);
119 }
ThreadRef * get_thread(ThreadId id)

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::thread::ThreadPoolPimpl::impersonate_on_numa_node ( ThreadGroupId  node,
const proc::ProcName proc_name,
const void *  task_input,
uint64_t  task_input_size,
ImpersonateSession session 
)

Definition at line 95 of file thread_pool_pimpl.cpp.

References engine_, foedus::Engine::get_options(), foedus::thread::ThreadGroupRef::get_thread(), groups_, foedus::EngineOptions::thread_, foedus::thread::ThreadOptions::thread_count_per_group_, and foedus::thread::ThreadRef::try_impersonate().

Referenced by foedus::thread::ThreadPool::impersonate_on_numa_node().

100  {
101  uint16_t thread_per_group = engine_->get_options().thread_.thread_count_per_group_;
102  ThreadGroupRef& group = groups_[node];
103  for (size_t j = 0; j < thread_per_group; ++j) {
104  ThreadRef* thread = group.get_thread(j);
105  if (thread->try_impersonate(proc_name, task_input, task_input_size, session)) {
106  return true;
107  }
108  }
109  return false;
110 }
const EngineOptions & get_options() const
Definition: engine.cpp:39
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.
thread::ThreadOptions thread_

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::thread::ThreadPoolPimpl::initialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 40 of file thread_pool_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, engine_, ERROR_STACK, foedus::Engine::get_memory_manager(), foedus::Engine::get_options(), foedus::Engine::get_soc_id(), groups_, foedus::DefaultInitializable::initialize(), foedus::DefaultInitializable::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableInit, foedus::kRetOk, local_group_, and foedus::EngineOptions::thread_.

40  {
43  }
44  ASSERT_ND(groups_.empty());
45  const ThreadOptions &options = engine_->get_options().thread_;
46  for (ThreadGroupId group_id = 0; group_id < options.group_count_; ++group_id) {
47  groups_.emplace_back(ThreadGroupRef(engine_, group_id));
48  }
49 
50  if (!engine_->is_master()) {
51  // initialize local thread group object
52  soc::SocId node = engine_->get_soc_id();
53  local_group_ = new ThreadGroup(engine_, node);
55  }
56  return kRetOk;
57 }
ThreadGroup * local_group_
Thread group of the local SOC engine.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Definition: error_code.hpp:109
const EngineOptions & get_options() const
Definition: engine.cpp:39
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.
uint16_t SocId
Represents an ID of an SOC, or NUMA node.
Definition: soc_id.hpp:41
thread::ThreadOptions thread_
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
soc::SocId get_soc_id() const
If this is a child instance, returns its SOC ID (NUMA node).
Definition: engine.cpp:73
#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
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
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:

ErrorStack foedus::thread::ThreadPoolPimpl::uninitialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 59 of file thread_pool_pimpl.cpp.

References ASSERT_ND, foedus::ErrorStackBatch::emprace_back(), engine_, ERROR_STACK, foedus::Engine::get_memory_manager(), groups_, foedus::DefaultInitializable::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableUninit, local_group_, SUMMARIZE_ERROR_BATCH, and foedus::DefaultInitializable::uninitialize().

59  {
60  ErrorStackBatch batch;
63  }
64 
65  groups_.clear();
66  if (local_group_) {
68  batch.emprace_back(local_group_->uninitialize());
69  delete local_group_;
70  local_group_ = nullptr;
71  }
72  return SUMMARIZE_ERROR_BATCH(batch);
73 }
ThreadGroup * local_group_
Thread group of the local SOC engine.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
std::vector< ThreadGroupRef > groups_
List of all thread groups, one for each NUMA node in this engine.
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
0x0006 : "GENERAL: A dependent module is already uninitialized. This implies a wrong uninitialization...
Definition: error_code.hpp:110
#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
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
Definition: engine.cpp:50
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const ThreadPoolPimpl v 
)
friend

Definition at line 121 of file thread_pool_pimpl.cpp.

121  {
122  o << "<ThreadPool>";
123  o << "<groups>";
124  for (const ThreadGroupRef& group : v.groups_) {
125  o << group;
126  }
127  o << "</groups>";
128  o << "</ThreadPool>";
129  return o;
130 }

Member Data Documentation

Engine* const foedus::thread::ThreadPoolPimpl::engine_
std::vector<ThreadGroupRef> foedus::thread::ThreadPoolPimpl::groups_

List of all thread groups, one for each NUMA node in this engine.

Index is ThreadGroupId.

Definition at line 89 of file thread_pool_pimpl.hpp.

Referenced by get_group(), get_thread_ref(), impersonate(), impersonate_on_numa_node(), initialize_once(), foedus::thread::operator<<(), and uninitialize_once().

ThreadGroup* foedus::thread::ThreadPoolPimpl::local_group_

Thread group of the local SOC engine.

If this is a master engine, null.

Definition at line 83 of file thread_pool_pimpl.hpp.

Referenced by get_local_group(), initialize_once(), and uninitialize_once().


The documentation for this class was generated from the following files: