25 namespace Buffer_Namespace {
28 BufferList::iterator seg_it,
30 const size_t page_size,
31 const size_t num_bytes)
36 , page_size_(page_size)
51 boost::unique_lock<boost::shared_mutex> write_lock(read_write_mutex_);
68 const size_t num_bytes,
71 const int dst_device_id) {
77 boost::shared_lock<boost::shared_mutex> read_lock(read_write_mutex_);
80 if (num_bytes + offset >
size_) {
81 LOG(
FATAL) <<
"Buffer: Out of bounds read error";
83 readData(dst, num_bytes, offset, dst_buffer_type, dst_device_id);
87 const size_t num_bytes,
90 const int src_device_id) {
93 boost::unique_lock<boost::shared_mutex> write_lock(read_write_mutex_);
99 writeData(src, num_bytes, offset, src_buffer_type, src_device_id);
103 if (offset <
size_) {
106 if (offset + num_bytes >
size_) {
108 size_ = offset + num_bytes;
113 size_t first_dirty_page = offset /
page_size_;
114 size_t last_dirty_page = (offset + num_bytes - 1) /
page_size_;
115 for (
size_t i = first_dirty_page; i <= last_dirty_page; ++i) {
121 const size_t num_bytes,
123 const int src_device_id) {
125 boost::shared_lock<boost::shared_mutex> read_lock(
127 boost::unique_lock<boost::shared_mutex> append_lock(
virtual void writeData(int8_t *const src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1)=0
size_t num_pages_
the size of each page in the buffer
void append(int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int deviceId=-1) override
BufferList::iterator seg_it_
int8_t * getMemoryPtr() override
Returns a raw, constant (read-only) pointer to the underlying buffer.
~Buffer() override
Destructor.
Note(s): Forbid Copying Idiom 4.1.
BufferList::iterator reserveBuffer(BufferList::iterator &seg_it, const size_t num_bytes)
std::vector< bool > page_dirty_flags_
indicates when the buffer was last flushed
An AbstractBuffer is a unit of data management for a data manager.
virtual void readData(int8_t *const dst, const size_t num_bytes, const size_t offset=0, const MemoryLevel dst_buffer_type=CPU_LEVEL, const int dst_device_id=-1)=0
This file includes the class specification for the buffer manager (BufferMgr), and related data struc...
void write(int8_t *src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1) override
Writes (copies) data from src into the buffer. Writes (copies) nbytes of data into the buffer at the ...
void read(int8_t *const dst, const size_t num_bytes, const size_t offset=0, const MemoryLevel dst_buffer_type=CPU_LEVEL, const int device_id=-1) override
Reads (copies) data from the buffer to the destination (dst) memory location. Reads (copies) nbytes o...
Buffer(BufferMgr *bm, BufferList::iterator seg_it, const int device_id, const size_t page_size=512, const size_t num_bytes=0)
Constructs a Buffer object. The constructor requires a memory address (provided by BufferMgr)...
size_t reservedSize() const override
Returns the total number of bytes allocated for the buffer.
void reserve(const size_t num_bytes) override
void setMemoryPtr(int8_t *new_ptr) override