libfoedus-core
FOEDUS Core Library
foedus::thread::GrabFreeVolatilePagesScope Class Reference

Obtains multiple free volatile pages at once and releases them automatically when this object gets out of scope. More...

Detailed Description

Obtains multiple free volatile pages at once and releases them automatically when this object gets out of scope.

You can also dispatch some of the grabbed pages, which means they will NOT be released.

Definition at line 391 of file thread.hpp.

#include <thread.hpp>

Public Member Functions

 GrabFreeVolatilePagesScope (Thread *context, memory::PagePoolOffset *offsets)
 
 ~GrabFreeVolatilePagesScope ()
 
ErrorCode grab (uint32_t count)
 If this thread doesn't have enough free pages, no page is obtained, returning kErrorCodeMemoryNoFreePages. More...
 
void release ()
 Idempotent. More...
 
uint32_t get_count () const
 
void dispatch (uint32_t index)
 Call this when the page is placed somewhere. More...
 
memory::PagePoolOffset get (uint32_t index) const
 

Constructor & Destructor Documentation

foedus::thread::GrabFreeVolatilePagesScope::GrabFreeVolatilePagesScope ( Thread context,
memory::PagePoolOffset offsets 
)
inline

Definition at line 393 of file thread.hpp.

394  : context_(context), offsets_(offsets), count_(0) {}
foedus::thread::GrabFreeVolatilePagesScope::~GrabFreeVolatilePagesScope ( )
inline

Definition at line 395 of file thread.hpp.

References release().

395  {
396  release();
397  }

Here is the call graph for this function:

Member Function Documentation

void foedus::thread::GrabFreeVolatilePagesScope::dispatch ( uint32_t  index)
inline

Call this when the page is placed somewhere.

Definition at line 409 of file thread.hpp.

References ASSERT_ND.

Referenced by foedus::storage::masstree::SplitBorder::run(), and foedus::storage::masstree::SplitIntermediate::split_impl_no_error().

409  {
410  ASSERT_ND(index < count_);
411  offsets_[index] = 0; // This entry will be skipped in release()
412  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the caller graph for this function:

memory::PagePoolOffset foedus::thread::GrabFreeVolatilePagesScope::get ( uint32_t  index) const
inline

Definition at line 413 of file thread.hpp.

References ASSERT_ND.

Referenced by foedus::storage::masstree::SplitIntermediate::split_impl_no_error().

413  {
414  ASSERT_ND(index < count_);
415  return offsets_[index];
416  }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the caller graph for this function:

uint32_t foedus::thread::GrabFreeVolatilePagesScope::get_count ( ) const
inline

Definition at line 406 of file thread.hpp.

406 { return count_; }
ErrorCode foedus::thread::GrabFreeVolatilePagesScope::grab ( uint32_t  count)

If this thread doesn't have enough free pages, no page is obtained, returning kErrorCodeMemoryNoFreePages.

Definition at line 147 of file thread.cpp.

References foedus::thread::Thread::get_thread_memory(), foedus::memory::NumaCoreMemory::grab_free_volatile_page(), foedus::kErrorCodeMemoryNoFreePages, foedus::kErrorCodeOk, release(), and foedus::memory::NumaCoreMemory::release_free_volatile_page().

Referenced by foedus::storage::masstree::Adopt::adopt_case_b(), foedus::storage::masstree::SplitBorder::run(), and foedus::storage::masstree::SplitIntermediate::run().

147  {
148  if (count_) {
149  release();
150  }
151  memory::NumaCoreMemory* memory = context_->get_thread_memory();
152  for (uint32_t i = 0; i < count; ++i) {
153  offsets_[i] = memory->grab_free_volatile_page();
154  if (offsets_[i] == 0) {
155  for (uint32_t j = 0; j < i; ++j) {
156  memory->release_free_volatile_page(offsets_[j]);
157  }
159  }
160  }
161  count_ = count;
162  return kErrorCodeOk;
163 }
memory::NumaCoreMemory * get_thread_memory() const
Returns the private memory repository of this thread.
Definition: thread.cpp:57
0 means no-error.
Definition: error_code.hpp:87
0x0301 : "MEMORY : Not enough free volatile pages. Check the config of MemoryOptions" ...
Definition: error_code.hpp:142

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::thread::GrabFreeVolatilePagesScope::release ( )

Idempotent.

You can release it at any moment.

Definition at line 165 of file thread.cpp.

References foedus::thread::Thread::get_thread_memory(), and foedus::memory::NumaCoreMemory::release_free_volatile_page().

Referenced by grab(), and ~GrabFreeVolatilePagesScope().

165  {
166  memory::NumaCoreMemory* memory = context_->get_thread_memory();
167  for (uint32_t i = 0; i < count_; ++i) {
168  if (offsets_[i] != 0) {
169  memory->release_free_volatile_page(offsets_[i]);
170  }
171  }
172  count_ = 0;
173 }
void release_free_volatile_page(PagePoolOffset offset)
Returns one free volatile page to local page pool.
memory::NumaCoreMemory * get_thread_memory() const
Returns the private memory repository of this thread.
Definition: thread.cpp:57

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: