libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
thread_pool.hpp
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  */
18 #ifndef FOEDUS_THREAD_THREAD_POOL_HPP_
19 #define FOEDUS_THREAD_THREAD_POOL_HPP_
20 #include <stdint.h>
21 
22 #include <iosfwd>
23 
24 #include "foedus/cxx11.hpp"
25 #include "foedus/fwd.hpp"
26 #include "foedus/initializable.hpp"
27 #include "foedus/proc/proc_id.hpp"
28 #include "foedus/thread/fwd.hpp"
30 
31 namespace foedus {
32 namespace thread {
33 
127 class ThreadPool CXX11_FINAL : public virtual Initializable {
128  public:
130  explicit ThreadPool(Engine *engine);
131  ~ThreadPool();
133  bool is_initialized() const CXX11_OVERRIDE;
135 
150  bool impersonate(
151  const proc::ProcName& proc_name,
152  const void* task_input,
153  uint64_t task_input_size,
154  ImpersonateSession *session);
155 
172  const proc::ProcName& proc_name,
173  const void* task_input = CXX11_NULLPTR,
174  uint64_t task_input_size = 0) {
175  ImpersonateSession session;
176  if (!impersonate(proc_name, task_input, task_input_size, &session)) {
178  }
179  return session.get_result();
180  }
181 
187  ThreadGroupId node,
188  const proc::ProcName& proc_name,
189  const void* task_input,
190  uint64_t task_input_size,
191  ImpersonateSession *session);
192 
198  ThreadGroupId node,
199  const proc::ProcName& proc_name,
200  const void* task_input = CXX11_NULLPTR,
201  uint64_t task_input_size = 0) {
202  ImpersonateSession session;
203  if (!impersonate_on_numa_node(node, proc_name, task_input, task_input_size, &session)) {
205  }
206  return session.get_result();
207  }
208 
214  ThreadId core,
215  const proc::ProcName& proc_name,
216  const void* task_input,
217  uint64_t task_input_size,
218  ImpersonateSession *session);
219 
225  ThreadId core,
226  const proc::ProcName& proc_name,
227  const void* task_input = CXX11_NULLPTR,
228  uint64_t task_input_size = 0) {
229  ImpersonateSession session;
230  if (!impersonate_on_numa_core(core, proc_name, task_input, task_input_size, &session)) {
232  }
233  return session.get_result();
234  }
235 
237  ThreadPoolPimpl* get_pimpl() const { return pimpl_; }
238 
241 
242  friend std::ostream& operator<<(std::ostream& o, const ThreadPool& v);
243 
244  private:
245  ThreadPoolPimpl* pimpl_;
246 };
247 } // namespace thread
248 } // namespace foedus
249 #endif // FOEDUS_THREAD_THREAD_POOL_HPP_
ThreadPoolPimpl * get_pimpl() const
Returns the pimpl of this object.
Pimpl object of ThreadPool.
A view of Thread group object for other SOCs and master engine.
Definition: thread_ref.hpp:106
ErrorStack get_result()
Waits until the completion of the asynchronous session and retrieves the result.
The pure-virtual interface to initialize/uninitialize non-trivial resources.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
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
0x0E01 : "THREAD : No worker thread is available for impersonation." .
Definition: error_code.hpp:242
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
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 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.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Typedefs of ID types used in procedure package.
A view of Thread object for other SOCs and master engine.
Definition: thread_ref.hpp:39
ErrorStack uninitialize() override
An idempotent method to release all resources of this object, if any.
Definition: thread_pool.cpp:38
friend std::ostream & operator<<(std::ostream &o, const ThreadPool &v)
Definition: thread_pool.cpp:75
#define CXX11_OVERRIDE
Used in public headers in place of "override" of C++11.
Definition: cxx11.hpp:134
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
Definition: cxx11.hpp:128
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
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.
ErrorStack initialize() override
Acquires resources in this object, usually called right after constructor.
Definition: thread_pool.cpp:36
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.
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
Forward declarations of classes in thread package.
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
The pool of pre-allocated threads in the engine to execute transactions.