libfoedus-core
FOEDUS Core Library
thread_ref.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_REF_HPP_
19 #define FOEDUS_THREAD_THREAD_REF_HPP_
20 
21 #include <iosfwd>
22 #include <vector>
23 
24 #include "foedus/cxx11.hpp"
25 #include "foedus/epoch.hpp"
26 #include "foedus/fwd.hpp"
27 #include "foedus/proc/proc_id.hpp"
28 #include "foedus/thread/fwd.hpp"
30 #include "foedus/xct/fwd.hpp"
31 #include "foedus/xct/xct_id.hpp"
32 
33 namespace foedus {
34 namespace thread {
40  public:
41  ThreadRef();
42  ThreadRef(Engine* engine, ThreadId id);
43 
53  bool try_impersonate(
54  const proc::ProcName& proc_name,
55  const void* task_input,
56  uint64_t task_input_size,
57  ImpersonateSession *session);
58 
59  Engine* get_engine() const { return engine_; }
60  ThreadId get_thread_id() const { return id_; }
62  void* get_task_input_memory() const { return task_input_memory_; }
63  void* get_task_output_memory() const { return task_output_memory_; }
64  xct::McsWwBlock* get_mcs_ww_blocks() const { return mcs_ww_blocks_; }
65  xct::McsRwSimpleBlock* get_mcs_rw_simple_blocks() const { return mcs_rw_simple_blocks_; }
66  xct::McsRwExtendedBlock* get_mcs_rw_extended_blocks() const { return mcs_rw_extended_blocks_; }
67  // overload to be template-friendly
68  void get_mcs_rw_blocks(xct::McsRwSimpleBlock** out) const { *out = mcs_rw_simple_blocks_; }
69  void get_mcs_rw_blocks(xct::McsRwExtendedBlock** out) const { *out = mcs_rw_extended_blocks_; }
71  ThreadControlBlock* get_control_block() const { return control_block_; }
72 
74  Epoch get_in_commit_epoch() const;
75 
76  uint64_t get_snapshot_cache_hits() const;
77  uint64_t get_snapshot_cache_misses() const;
78  void reset_snapshot_cache_counts() const;
79 
80  friend std::ostream& operator<<(std::ostream& o, const ThreadRef& v);
81 
82  private:
83  Engine* engine_;
84 
86  ThreadId id_;
87 
88  ThreadControlBlock* control_block_;
89  void* task_input_memory_;
90  void* task_output_memory_;
91 
93  xct::McsWwBlock* mcs_ww_blocks_;
94  xct::McsRwSimpleBlock* mcs_rw_simple_blocks_;
95  xct::McsRwExtendedBlock* mcs_rw_extended_blocks_;
96 
98  xct::McsRwAsyncMapping* mcs_rw_async_mappings_;
99 };
100 
101 
107  public:
108  ThreadGroupRef();
109  ThreadGroupRef(Engine* engine, ThreadGroupId group_id);
110 
111  Engine* get_engine() const { return engine_; }
112  ThreadGroupId get_group_id() const { return group_id_; }
113 
115  ThreadRef* get_thread(ThreadLocalOrdinal ordinal) { return &threads_[ordinal]; }
117  ThreadRef get_thread_ref(ThreadLocalOrdinal ordinal) const { return threads_[ordinal]; }
118 
126 
127  friend std::ostream& operator<<(std::ostream& o, const ThreadGroupRef& v);
128 
129  private:
130  Engine* engine_;
131  ThreadGroupId group_id_;
132  std::vector<ThreadRef> threads_;
133 };
134 
135 
136 } // namespace thread
137 } // namespace foedus
138 #endif // FOEDUS_THREAD_THREAD_REF_HPP_
ThreadRef * get_thread(ThreadLocalOrdinal ordinal)
Returns Thread object for the given ordinal in this group.
Definition: thread_ref.hpp:115
uint64_t get_snapshot_cache_hits() const
Definition: thread_ref.cpp:119
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
A view of Thread group object for other SOCs and master engine.
Definition: thread_ref.hpp:106
void get_mcs_rw_blocks(xct::McsRwExtendedBlock **out) const
Definition: thread_ref.hpp:69
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Typedefs of ID types used in thread package.
Engine * get_engine() const
Definition: thread_ref.hpp:111
xct::McsRwAsyncMapping * get_mcs_rw_async_mapping(xct::UniversalLockId lock_id)
Definition: thread_ref.cpp:149
Shared data of ThreadPimpl.
Forward declarations of classes in transaction package.
Forward declarations of classes in root package.
Reader-writer (RW) MCS lock classes.
Definition: xct_id.hpp:387
Represents a time epoch.
Definition: epoch.hpp:61
Engine * get_engine() const
Definition: thread_ref.hpp:59
ThreadRef get_thread_ref(ThreadLocalOrdinal ordinal) const
Returns a copied instance.
Definition: thread_ref.hpp:117
A user session running on an impersonated thread.
ThreadGroupId get_numa_node() const
Definition: thread_ref.hpp:61
friend std::ostream & operator<<(std::ostream &o, const ThreadRef &v)
Definition: thread_ref.cpp:172
uintptr_t UniversalLockId
Universally ordered identifier of each lock.
Definition: xct_id.hpp:134
friend std::ostream & operator<<(std::ostream &o, const ThreadGroupRef &v)
Definition: thread_ref.cpp:160
void get_mcs_rw_blocks(xct::McsRwSimpleBlock **out) const
Definition: thread_ref.hpp:68
void * get_task_input_memory() const
Definition: thread_ref.hpp:62
Pre-allocated MCS block for WW-locks.
Definition: xct_id.hpp:274
Definitions of IDs in this package and a few related constant values.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
Pre-allocated MCS block for extended version of RW-locks.
Definition: xct_id.hpp:513
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
ThreadControlBlock * get_control_block() const
Definition: thread_ref.hpp:71
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
bool try_impersonate(const proc::ProcName &proc_name, const void *task_input, uint64_t task_input_size, ImpersonateSession *session)
Conditionally try to occupy this thread, or impersonate.
Definition: thread_ref.cpp:59
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
xct::McsRwExtendedBlock * get_mcs_rw_extended_blocks() const
Definition: thread_ref.hpp:66
ThreadGroupId get_group_id() const
Definition: thread_ref.hpp:112
Epoch get_min_in_commit_epoch() const
Returns the oldest in-commit epoch of the threads in this group.
Definition: thread_ref.cpp:132
Epoch get_in_commit_epoch() const
Definition: thread_ref.cpp:114
void * get_task_output_memory() const
Definition: thread_ref.hpp:63
xct::McsRwSimpleBlock * get_mcs_rw_simple_blocks() const
Definition: thread_ref.hpp:65
Forward declarations of classes in thread package.
uint64_t get_snapshot_cache_misses() const
Definition: thread_ref.cpp:123
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
xct::McsWwBlock * get_mcs_ww_blocks() const
Definition: thread_ref.hpp:64
ThreadId get_thread_id() const
Definition: thread_ref.hpp:60
void reset_snapshot_cache_counts() const
Definition: thread_ref.cpp:127