Thrill  0.1
PinnedBlock Class Reference

Detailed Description

A pinned / pin-counted derivative of a Block.

By holding a pin, it is a guaranteed that the contained ByteBlock's data is loaded in RAM. Since pins are counted per thread, the PinnedBlock is a counting pointer plus a thread id. An ordinary Block can be pinned by calling Pin(), which delivers a future PinnedBlock, which is available once the data is actually loaded.

Be careful to move PinnedBlock as must as possible, since copying costs a pinning and an unpinning operation, whereas moving is free.

Definition at line 157 of file block.hpp.

+ Inheritance diagram for PinnedBlock:
+ Collaboration diagram for PinnedBlock:

#include <block.hpp>

Public Member Functions

 PinnedBlock ()=default
 Create invalid PinnedBlock. More...
 
 PinnedBlock (PinnedByteBlockPtr &&byte_block, size_t begin, size_t end, size_t first_item, size_t num_items, bool typecode_verify)
 
 PinnedBlock (const PinnedBlock &pb) noexcept
 copy-ctor: increment underlying's pin count More...
 
 PinnedBlock (PinnedBlock &&pb) noexcept
 move-ctor: move underlying's pin More...
 
 ~PinnedBlock ()
 
PinnedByteBlockPtr CopyPinnedByteBlock () const
 
const Bytedata_begin () const
 return pointer to beginning of valid data More...
 
const Bytedata_end () const
 return pointer to end of valid data More...
 
Block MoveToBlock () &&
 extract Block has an unpinning move More...
 
PinnedBlockoperator= (PinnedBlock &pb) noexcept
 copy-assignment: copy underlying and increase pin count More...
 
PinnedBlockoperator= (PinnedBlock &&pb) noexcept
 move-assignment: move underlying, release current's pin More...
 
PinRequestPtr Pin () const =delete
 not available in PinnedBlock More...
 
PinnedBlock PinWait () const =delete
 not available in PinnedBlock More...
 
void Reset ()
 release pin on block and reset Block pointer to nullptr More...
 
PinnedByteBlockPtr StealPinnedByteBlock () &&
 
Block ToBlock () const
 extract Block has an unpinned copy More...
 
std::string ToString () const
 
Accessors to Super-Class
bool IsValid () const
 Return whether the enclosed ByteBlock is valid. More...
 
const ByteBlockPtrbyte_block () const
 access to byte_block_ More...
 
ByteBlockPtrbyte_block ()
 mutable access to byte_block_ More...
 
size_t num_items () const
 return number of items beginning in this block More...
 
size_t pin_count (size_t local_worker_id) const
 return number of pins in underlying ByteBlock More...
 
void set_begin (size_t i)
 accessor to begin_ More...
 
void set_end (size_t i)
 accessor to end_ More...
 
size_t size () const
 return length of valid data in bytes. More...
 
size_t first_item_absolute () const
 accessor to first_item_ (absolute in ByteBlock) More...
 
size_t first_item_relative () const
 return the first_item_offset relative to data_begin(). More...
 
bool typecode_verify () const
 return typecode_verify from Block More...
 

Private Member Functions

 PinnedBlock (const Block &b, size_t local_worker_id)
 
- Private Member Functions inherited from Block
 Block ()=default
 default-ctor: create invalid Block. More...
 
 Block (const Block &other)=default
 
 Block (Block &&other)=default
 
 Block (ByteBlockPtr &&byte_block, size_t begin, size_t end, size_t first_item, size_t num_items, bool typecode_verify)
 
const ByteBlockPtrbyte_block () const
 access to byte_block_ More...
 
ByteBlockPtrbyte_block ()
 mutable access to byte_block_ More...
 
size_t first_item_absolute () const
 accessor to first_item_ (absolute in ByteBlock) More...
 
size_t first_item_relative () const
 return the first_item_offset relative to data_begin(). More...
 
bool IsValid () const
 Return whether the enclosed ByteBlock is valid. More...
 
size_t num_items () const
 return number of items beginning in this block More...
 
Blockoperator= (const Block &other)=default
 
Blockoperator= (Block &&other)=default
 
PinRequestPtr Pin (size_t local_worker_id) const
 
size_t pin_count (size_t local_worker_id) const
 return number of pins in underlying ByteBlock More...
 
PinnedBlock PinWait (size_t local_worker_id) const
 Convenience function to call Pin() and wait for the future. More...
 
void set_begin (size_t i)
 accessor to begin_ More...
 
void set_end (size_t i)
 accessor to end_ More...
 
size_t size () const
 return length of valid data in bytes. More...
 
bool typecode_verify () const
 Returns typecode_verify_. More...
 

Private Attributes

size_t local_worker_id_
 thread id of holder of pin More...
 
- Private Attributes inherited from Block
size_t begin_ = 0
 beginning offset of valid bytes to read More...
 
ByteBlockPtr byte_block_
 referenced ByteBlock More...
 
size_t end_ = 0
 
size_t first_item_ = 0
 
size_t num_items_ = 0
 
bool typecode_verify_ = false
 

Friends

std::ostream & operator<< (std::ostream &os, const PinnedBlock &b)
 make ostreamable for debugging More...
 

Additional Inherited Members

- Static Private Attributes inherited from Block
static constexpr bool debug = false
 

Constructor & Destructor Documentation

◆ PinnedBlock() [1/5]

PinnedBlock ( )
default

Create invalid PinnedBlock.

◆ PinnedBlock() [2/5]

PinnedBlock ( PinnedByteBlockPtr &&  byte_block,
size_t  begin,
size_t  end,
size_t  first_item,
size_t  num_items,
bool  typecode_verify 
)
inline

Creates a block that points to the given data::PinnedByteBlock with the given offsets. The returned block is also pinned, the pin is transfered!

Definition at line 165 of file block.hpp.

References LOG.

◆ PinnedBlock() [3/5]

PinnedBlock ( const PinnedBlock pb)
inlinenoexcept

copy-ctor: increment underlying's pin count

Definition at line 176 of file block.hpp.

References Block::byte_block_.

◆ PinnedBlock() [4/5]

PinnedBlock ( PinnedBlock &&  pb)
inlinenoexcept

move-ctor: move underlying's pin

Definition at line 182 of file block.hpp.

◆ ~PinnedBlock()

~PinnedBlock ( )
inline

Definition at line 213 of file block.hpp.

References Block::byte_block_, CountingPtr< Type, Deleter >::get(), and LOG.

◆ PinnedBlock() [5/5]

PinnedBlock ( const Block b,
size_t  local_worker_id 
)
inlineprivate

protected construction from an unpinned block AFTER the pin was taken, this method does NOT pin it.

Definition at line 320 of file block.hpp.

Member Function Documentation

◆ byte_block() [1/2]

const ByteBlockPtr& byte_block ( ) const
inline

◆ byte_block() [2/2]

ByteBlockPtr& byte_block ( )
inline

mutable access to byte_block_

Definition at line 229 of file block.hpp.

References Block::byte_block().

◆ CopyPinnedByteBlock()

PinnedByteBlockPtr CopyPinnedByteBlock ( ) const
inline

copy the underlying byte_block_ into a new PinnedByteBlockPtr, which increases the pin count. use StealPinnedByteBlock to move the underlying pin out (cheaper).

Definition at line 298 of file block.hpp.

References Block::byte_block_, CountingPtr< Type, Deleter >::get(), Block::operator<<, Block::Pin(), and Block::PinWait().

Referenced by BlockReader< CatBlockSource >::CopyBlock().

◆ data_begin()

const Byte* data_begin ( ) const
inline

return pointer to beginning of valid data

Definition at line 259 of file block.hpp.

References Block::begin_, and Block::byte_block_.

Referenced by BlockReader< CatBlockSource >::CopyBlock(), and BlockReader< CatBlockSource >::LoadBlock().

◆ data_end()

const Byte* data_end ( ) const
inline

return pointer to end of valid data

Definition at line 265 of file block.hpp.

References Block::byte_block_, and Block::end_.

Referenced by BlockReader< CatBlockSource >::LoadBlock().

◆ first_item_absolute()

size_t first_item_absolute ( ) const
inline

accessor to first_item_ (absolute in ByteBlock)

Definition at line 248 of file block.hpp.

References Block::first_item_absolute().

Referenced by BlockReader< CatBlockSource >::CopyBlock(), and BlockReader< CatBlockSource >::GetItemBatch().

◆ first_item_relative()

size_t first_item_relative ( ) const
inline

return the first_item_offset relative to data_begin().

Definition at line 251 of file block.hpp.

References Block::first_item_relative().

◆ IsValid()

bool IsValid ( ) const
inline

◆ MoveToBlock()

Block MoveToBlock ( ) &&
inline

extract Block has an unpinning move

Definition at line 284 of file block.hpp.

References Block::Block(), and Block::byte_block_.

◆ num_items()

size_t num_items ( ) const
inline

return number of items beginning in this block

Definition at line 232 of file block.hpp.

References Block::num_items().

Referenced by BlockReader< CatBlockSource >::LoadBlock().

◆ operator=() [1/2]

PinnedBlock& operator= ( PinnedBlock pb)
inlinenoexcept

copy-assignment: copy underlying and increase pin count

Definition at line 188 of file block.hpp.

References Block::byte_block_, and Block::operator=().

◆ operator=() [2/2]

PinnedBlock& operator= ( PinnedBlock &&  pb)
inlinenoexcept

move-assignment: move underlying, release current's pin

Definition at line 201 of file block.hpp.

References Block::byte_block_, and Block::operator=().

◆ Pin()

PinRequestPtr Pin ( ) const
delete

not available in PinnedBlock

◆ pin_count()

size_t pin_count ( size_t  local_worker_id) const
inline

return number of pins in underlying ByteBlock

Definition at line 235 of file block.hpp.

References Block::pin_count().

◆ PinWait()

PinnedBlock PinWait ( ) const
delete

◆ Reset()

void Reset ( )
inline

release pin on block and reset Block pointer to nullptr

Definition at line 271 of file block.hpp.

References Block::byte_block_, and CountingPtr< Type, Deleter >::reset().

Referenced by BlockReader< CatBlockSource >::GetItemBatch(), and BlockReader< CatBlockSource >::NextBlock().

◆ set_begin()

void set_begin ( size_t  i)
inline

accessor to begin_

Definition at line 239 of file block.hpp.

References Block::set_begin().

◆ set_end()

void set_end ( size_t  i)
inline

accessor to end_

Definition at line 242 of file block.hpp.

References Block::set_end().

◆ size()

size_t size ( ) const
inline

◆ StealPinnedByteBlock()

PinnedByteBlockPtr StealPinnedByteBlock ( ) &&
inline

extract ByteBlock including it's pin. afterwards, this PinnedBlock is invalid.

Definition at line 291 of file block.hpp.

References Block::byte_block_.

Referenced by BlockWriter< BlockSink >::PutSafe().

◆ ToBlock()

Block ToBlock ( ) const
inline

extract Block has an unpinned copy

Definition at line 279 of file block.hpp.

References Block::Block().

◆ ToString()

std::string ToString ( ) const

Return block as std::string (for debugging), includes eventually cut off elements form the beginning included

Definition at line 47 of file block.cpp.

References Block::IsValid(), and Block::size().

◆ typecode_verify()

bool typecode_verify ( ) const
inline

return typecode_verify from Block

Definition at line 254 of file block.hpp.

References Block::typecode_verify().

Referenced by BlockReader< CatBlockSource >::LoadBlock().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const PinnedBlock b 
)
friend

make ostreamable for debugging

Definition at line 53 of file block.cpp.

Member Data Documentation

◆ local_worker_id_

size_t local_worker_id_
private

thread id of holder of pin

Definition at line 324 of file block.hpp.

Referenced by BlockPool::OnReadComplete().


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