libfoedus-core
FOEDUS Core Library
thread_pool.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 
22 #include "foedus/assert_nd.hpp"
24 
25 namespace foedus {
26 namespace thread {
27 
28 ThreadPool::ThreadPool(Engine *engine) : pimpl_(nullptr) {
29  pimpl_ = new ThreadPoolPimpl(engine);
30 }
32  delete pimpl_;
33  pimpl_ = nullptr;
34 }
35 
37 bool ThreadPool::is_initialized() const { return pimpl_->is_initialized(); }
39 
41  const proc::ProcName& proc_name,
42  const void* task_input,
43  uint64_t task_input_size,
44  ImpersonateSession *session) {
45  return pimpl_->impersonate(proc_name, task_input, task_input_size, session);
46 }
47 
49  ThreadGroupId node,
50  const proc::ProcName& proc_name,
51  const void* task_input,
52  uint64_t task_input_size,
53  ImpersonateSession *session) {
54  return pimpl_->impersonate_on_numa_node(node, proc_name, task_input, task_input_size, session);
55 }
56 
58  ThreadId core,
59  const proc::ProcName& proc_name,
60  const void* task_input,
61  uint64_t task_input_size,
62  ImpersonateSession *session) {
63  return pimpl_->impersonate_on_numa_core(core, proc_name, task_input, task_input_size, session);
64 }
65 
67  return pimpl_->get_group(numa_node);
68 }
69 
71  return pimpl_->get_thread(id);
72 }
73 
74 
75 std::ostream& operator<<(std::ostream& o, const ThreadPool& v) {
76  o << *v.pimpl_;
77  return o;
78 }
79 
80 
81 } // namespace thread
82 } // namespace foedus
Pimpl object of ThreadPool.
A view of Thread group object for other SOCs and master engine.
Definition: thread_ref.hpp:106
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
ThreadRef * get_thread_ref(ThreadId id)
Definition: thread_pool.cpp:70
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.
Definition: thread_pool.cpp:57
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
ThreadGroupRef * get_group(ThreadGroupId numa_node)
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)
Overload to specify a NUMA node to run on.
Definition: thread_pool.cpp:48
A user session running on an impersonated thread.
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: thread_pool.cpp:37
ThreadGroupRef * get_group_ref(ThreadGroupId numa_node)
Definition: thread_pool.cpp:66
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
A view of Thread object for other SOCs and master engine.
Definition: thread_ref.hpp:39
ThreadRef * get_thread(ThreadId id)
ErrorStack uninitialize() override
An idempotent method to release all resources of this object, if any.
Definition: thread_pool.cpp:38
bool impersonate_on_numa_node(ThreadGroupId node, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
bool impersonate_on_numa_core(ThreadId core, const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
std::ostream & operator<<(std::ostream &o, const ImpersonateSession &v)
ErrorStack initialize() override
Acquires resources in this object, usually called right after constructor.
Definition: thread_pool.cpp:36
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 impersonat...
Definition: thread_pool.cpp:40
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
bool is_initialized() const override final
Returns whether the object has been already initialized or not.
The pool of pre-allocated threads in the engine to execute transactions.