20 #include <glog/logging.h>
39 control_block_(nullptr),
40 task_input_memory_(nullptr),
41 task_output_memory_(nullptr),
42 mcs_ww_blocks_(nullptr),
43 mcs_rw_simple_blocks_(nullptr),
44 mcs_rw_extended_blocks_(nullptr),
45 mcs_rw_async_mappings_(nullptr) {}
61 const void* task_input,
62 uint64_t task_input_size,
65 LOG(WARNING) <<
"This session is already attached to some thread. Releasing the current one..";
72 std::this_thread::sleep_for(std::chrono::milliseconds(1));
77 DVLOG(0) <<
"(fast path) Someone already took Thread-" << id_ <<
".";
85 DVLOG(0) <<
"(slow path) Someone already took Thread-" << id_ <<
".";
93 if (task_input_size > 0) {
94 std::memcpy(task_input_memory_, task_input, task_input_size);
99 VLOG(0) <<
"Impersonation succeeded for Thread-" << id_ <<
".";
107 : engine_(engine), group_id_(group_id) {
109 for (uint16_t i = 0; i < count; ++i) {
135 for (
const auto& t : threads_) {
136 Epoch in_commit_epoch = t.get_control_block()->in_commit_epoch_;
139 ret = in_commit_epoch;
151 for (uint32_t i = 0; i < nmappings; ++i) {
152 if (mcs_rw_async_mappings_[i].lock_id_ == lock_id) {
153 return mcs_rw_async_mappings_ + i;
161 o <<
"<ThreadGroupRef>";
162 o <<
"<group_id_>" <<
static_cast<int>(v.
get_group_id()) <<
"</group_id_>";
164 for (
const ThreadRef& child_thread : v.threads_) {
168 o <<
"</ThreadGroup>";
xct::McsRwAsyncMapping * mcs_rw_async_mappings_memories_
void release()
Releases all resources and ownerships this session has acquired.
uint64_t get_snapshot_cache_hits() const
ThreadTicket current_ticket_
The most recently issued impersonation ticket.
A view of Thread group object for other SOCs and master engine.
Idle state, receiving a new task.
uint64_t stat_snapshot_cache_hits_
uint32_t input_len_
Byte size of input given to the procedure.
thread::ThreadRef * thread_
The impersonated thread.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
xct::McsRwExtendedBlock * mcs_rw_extended_lock_memories_
Typedefs of ID types used in thread package.
xct::McsRwAsyncMapping * get_mcs_rw_async_mapping(xct::UniversalLockId lock_id)
A client has set a next task.
soc::SharedMutex task_mutex_
The following variables are protected by this mutex.
thread::ThreadTicket ticket_
The ticket issued as of impersonation.
Part of NodeMemoryAnchors for each thread.
void * task_input_memory_
Input buffer for an impersonated task.
A user session running on an impersonated thread.
const EngineOptions & get_options() const
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
uintptr_t UniversalLockId
Universally ordered identifier of each lock.
soc::SharedPolling wakeup_cond_
The thread sleeps on this conditional when it has no task.
Database engine object that holds all resources and provides APIs.
xct::McsWwBlock * mcs_ww_lock_memories_
Pre-allocated MCS block for each thread.
bool is_valid() const
Returns if the impersonation succeeded.
uint32_t mcs_rw_async_mapping_current_
How many async mappings for extended RW lock we have so far.
A view of Thread object for other SOCs and master engine.
thread::ThreadControlBlock * thread_memory_
Status and synchronization mechanism for impersonation of this thread.
ThreadControlBlock * get_control_block() const
Auto-lock scope object for SharedMutex.
xct::McsRwSimpleBlock * mcs_rw_simple_lock_memories_
proc::ProcName proc_name_
Name of the procedure to execute next.
Repository of all shared memory in one FOEDUS instance.
ThreadId compose_thread_id(ThreadGroupId node, ThreadLocalOrdinal local_core)
Returns a globally unique ID of Thread (core) for the given node and ordinal in the node...
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.
thread::ThreadOptions thread_
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
uint64_t stat_snapshot_cache_misses_
ThreadGroupId get_group_id() const
ThreadStatus status_
Impersonation status of this thread.
soc::SocManager * get_soc_manager() const
See SOC and IPC.
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
std::ostream & operator<<(std::ostream &o, const ImpersonateSession &v)
Epoch get_min_in_commit_epoch() const
Returns the oldest in-commit epoch of the threads in this group.
Epoch get_in_commit_epoch() const
void memory_fence_acquire()
Equivalent to std::atomic_thread_fence(std::memory_order_acquire).
#define UNLIKELY(x)
Hints that x is highly likely false.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
ThreadMemoryAnchors * get_thread_memory_anchors(thread::ThreadId thread_id)
uint64_t get_snapshot_cache_misses() const
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
ThreadId get_thread_id() const
void signal()
Signal it to let waiters exit.
void reset_snapshot_cache_counts() const
SharedMemoryRepo * get_shared_memory_repo()
Returns the shared memories maintained across SOCs.
void store_min(const Epoch &other)
Kind of std::min(this, other).
void * task_output_memory_
Output buffer for an impersonated task.