libfoedus-core
FOEDUS Core Library
|
The pool of pre-allocated threads in the engine to execute transactions. More...
The pool of pre-allocated threads in the engine to execute transactions.
This is the main API class of thread package. Its gut is impersonate() which allows client programs to create a new session (ImpersonateSession) that runs user-defined procedures (System and User Procedures). The sessions are executed on pre-allocated threads in the engine. We throttle sessions, meaning impersonate() blocks when there is no available thread. To avoid waiting too long, impersonate() receives timeout parameter.
Definition at line 127 of file thread_pool.hpp.
#include <thread_pool.hpp>
Public Member Functions | |
ThreadPool ()=delete | |
ThreadPool (Engine *engine) | |
~ThreadPool () | |
ErrorStack | initialize () override |
Acquires resources in this object, usually called right after constructor. More... | |
bool | is_initialized () const override |
Returns whether the object has been already initialized or not. More... | |
ErrorStack | uninitialize () override |
An idempotent method to release all resources of this object, if any. More... | |
bool | impersonate (const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session) |
Impersonate as one of pre-allocated threads in this engine, executing the procedure on the impersonated thread (NOT the current thread). More... | |
ErrorStack | impersonate_synchronous (const proc::ProcName &proc_name, const void *task_input=nullptr, uint64_t task_input_size=0) |
A shorthand for impersonating a session and synchronously waiting for its end. More... | |
bool | impersonate_on_numa_node (ThreadGroupId node, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session) |
Overload to specify a NUMA node to run on. More... | |
ErrorStack | impersonate_on_numa_node_synchronous (ThreadGroupId node, const proc::ProcName &proc_name, const void *task_input=nullptr, uint64_t task_input_size=0) |
A shorthand for impersonating a session and synchronously waiting for its end. More... | |
bool | impersonate_on_numa_core (ThreadId core, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session) |
Overload to specify a core to run on. More... | |
ErrorStack | impersonate_on_numa_core_synchronous (ThreadId core, const proc::ProcName &proc_name, const void *task_input=nullptr, uint64_t task_input_size=0) |
A shorthand for impersonating a session and synchronously waiting for its end. More... | |
ThreadPoolPimpl * | get_pimpl () const |
Returns the pimpl of this object. More... | |
ThreadGroupRef * | get_group_ref (ThreadGroupId numa_node) |
ThreadRef * | get_thread_ref (ThreadId id) |
![]() | |
virtual | ~Initializable () |
Friends | |
std::ostream & | operator<< (std::ostream &o, const ThreadPool &v) |
|
delete |
|
explicit |
Definition at line 28 of file thread_pool.cpp.
foedus::thread::ThreadPool::~ThreadPool | ( | ) |
Definition at line 31 of file thread_pool.cpp.
ThreadGroupRef * foedus::thread::ThreadPool::get_group_ref | ( | ThreadGroupId | numa_node | ) |
Definition at line 66 of file thread_pool.cpp.
References foedus::thread::ThreadPoolPimpl::get_group().
Referenced by foedus::xct::XctManagerPimpl::handle_epoch_chime_wait_grace_period().
|
inline |
Returns the pimpl of this object.
Use it only when you know what you are doing.
Definition at line 237 of file thread_pool.hpp.
Referenced by foedus::thread::ThreadPimpl::get_thread_ref(), and foedus::log::Logger::initialize_once().
Definition at line 70 of file thread_pool.cpp.
References foedus::thread::ThreadPoolPimpl::get_thread().
bool foedus::thread::ThreadPool::impersonate | ( | const proc::ProcName & | proc_name, |
const void * | task_input, | ||
uint64_t | task_input_size, | ||
ImpersonateSession * | session | ||
) |
Impersonate as one of pre-allocated threads in this engine, executing the procedure on the impersonated thread (NOT the current thread).
[in] | proc_name | the name of the procedure to run on this thread. |
[in] | task_input | input data of arbitrary format for the procedure. |
[in] | task_input_size | byte size of the input data to copy into the thread's memory. |
[out] | session | the session to run on this thread. On success, the session receives a ticket so that the caller can wait for the completion. |
This is similar to launch a new thread that calls the functor. The difference is that this doesn't actually create a thread (which is very expensive) but instead just impersonates as one of the pre-allocated threads in the engine.
Definition at line 40 of file thread_pool.cpp.
References foedus::thread::ThreadPoolPimpl::impersonate().
Referenced by impersonate_synchronous().
bool foedus::thread::ThreadPool::impersonate_on_numa_core | ( | ThreadId | core, |
const proc::ProcName & | proc_name, | ||
const void * | task_input, | ||
uint64_t | task_input_size, | ||
ImpersonateSession * | session | ||
) |
Overload to specify a core to run on.
Definition at line 57 of file thread_pool.cpp.
References foedus::thread::ThreadPoolPimpl::impersonate_on_numa_core().
Referenced by impersonate_on_numa_core_synchronous().
|
inline |
A shorthand for impersonating a session and synchronously waiting for its end.
Definition at line 224 of file thread_pool.hpp.
References ERROR_STACK, foedus::thread::ImpersonateSession::get_result(), impersonate_on_numa_core(), and foedus::kErrorCodeThrNoThreadAvailable.
bool foedus::thread::ThreadPool::impersonate_on_numa_node | ( | ThreadGroupId | node, |
const proc::ProcName & | proc_name, | ||
const void * | task_input, | ||
uint64_t | task_input_size, | ||
ImpersonateSession * | session | ||
) |
Overload to specify a NUMA node to run on.
Definition at line 48 of file thread_pool.cpp.
References foedus::thread::ThreadPoolPimpl::impersonate_on_numa_node().
Referenced by impersonate_on_numa_node_synchronous().
|
inline |
A shorthand for impersonating a session and synchronously waiting for its end.
Definition at line 197 of file thread_pool.hpp.
References ERROR_STACK, foedus::thread::ImpersonateSession::get_result(), impersonate_on_numa_node(), and foedus::kErrorCodeThrNoThreadAvailable.
|
inline |
A shorthand for impersonating a session and synchronously waiting for its end.
Useful for a single and synchronous task invocation. This is equivalent to the following impersonate() invocation.
{.cpp}
Definition at line 171 of file thread_pool.hpp.
References ERROR_STACK, foedus::thread::ImpersonateSession::get_result(), impersonate(), and foedus::kErrorCodeThrNoThreadAvailable.
|
overridevirtual |
Acquires resources in this object, usually called right after constructor.
If and only if the return value was not an error, is_initialized() will return TRUE. This method is usually not idempotent, but some implementation can choose to be. In that case, the implementation class should clarify that it's idempotent. This method is responsible for releasing all acquired resources when initialization fails. This method itself is NOT thread-safe. Do not call this in a racy situation.
Implements foedus::Initializable.
Definition at line 36 of file thread_pool.cpp.
References foedus::DefaultInitializable::initialize().
|
overridevirtual |
Returns whether the object has been already initialized or not.
Implements foedus::Initializable.
Definition at line 37 of file thread_pool.cpp.
References foedus::DefaultInitializable::is_initialized().
Referenced by foedus::storage::StorageManagerPimpl::initialize_once(), foedus::log::LogManagerPimpl::initialize_once(), foedus::storage::StorageManagerPimpl::uninitialize_once(), and foedus::log::LogManagerPimpl::uninitialize_once().
|
overridevirtual |
An idempotent method to release all resources of this object, if any.
After this method, is_initialized() will return FALSE. Whether this method encounters an error or not, the implementation should make the best effort to release as many resources as possible. In other words, Do not leak all resources because of one issue. This method itself is NOT thread-safe. Do not call this in a racy situation.
Implements foedus::Initializable.
Definition at line 38 of file thread_pool.cpp.
References foedus::DefaultInitializable::uninitialize().
|
friend |
Definition at line 75 of file thread_pool.cpp.