Scroom  0.14
Scroom::MemoryBlobs::Blob Class Reference

#include <memoryblobs.hh>

Inheritance diagram for Scroom::MemoryBlobs::Blob:
Inheritance graph
Collaboration diagram for Scroom::MemoryBlobs::Blob:
Collaboration graph

Classes

class  UnloadData
 

Public Types

using Ptr = boost::shared_ptr< Blob >
 

Public Member Functions

RawPageData::Ptr get ()
 
RawPageData::ConstPtr getConst ()
 
RawPageData::Ptr initialize (uint8_t value)
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::shared_ptr< R const > shared_from_this () const
 

Static Public Member Functions

static Ptr create (PageProvider::Ptr provider, size_t size)
 

Private Types

enum  State { UNINITIALIZED, CLEAN, DIRTY, COMPRESSING }
 

Private Member Functions

 Blob (PageProvider::Ptr provider, size_t size)
 
void unload ()
 
RawPageData::Ptr load ()
 
void compress ()
 

Private Attributes

PageProvider::Ptr provider
 
size_t size
 
uint8_t * data {nullptr}
 
State state {UNINITIALIZED}
 
boost::mutex mut
 
RawPageData::WeakPtr weakData
 
PageList pages
 
boost::shared_ptr< ThreadPoolcpuBound
 
int refcount {0}
 

Friends

class UnloadData
 

Member Typedef Documentation

◆ Ptr

using Scroom::MemoryBlobs::Blob::Ptr = boost::shared_ptr<Blob>

Member Enumeration Documentation

◆ State

Enumerator
UNINITIALIZED 
CLEAN 
DIRTY 
COMPRESSING 
82  {
84  CLEAN,
85  DIRTY,
87  };

Constructor & Destructor Documentation

◆ Blob()

Scroom::MemoryBlobs::Blob::Blob ( PageProvider::Ptr  provider,
size_t  size 
)
private
74  : provider(std::move(provider_))
75  , size(size_)
76  , cpuBound(CpuBound())
77 
78  {
79  }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ compress()

void Scroom::MemoryBlobs::Blob::compress ( )
private
137  {
138  boost::mutex::scoped_lock const lock(mut);
139  if(state == COMPRESSING)
140  {
141  require(refcount == 0);
142 
144  free(data);
145  data = nullptr;
146 
147  state = CLEAN;
148  }
149  }

Referenced by unload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

Blob::Ptr Scroom::MemoryBlobs::Blob::create ( PageProvider::Ptr  provider,
size_t  size 
)
static
71 { return Ptr(new Blob(std::move(provider), size)); }

Referenced by BOOST_AUTO_TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

RawPageData::Ptr Scroom::MemoryBlobs::Blob::get ( )
152  {
153  boost::mutex::scoped_lock const lock(mut);
154  RawPageData::Ptr result = load();
155  state = DIRTY;
156  return result;
157  }
Here is the call graph for this function:

◆ getConst()

RawPageData::ConstPtr Scroom::MemoryBlobs::Blob::getConst ( )
169  {
170  boost::mutex::scoped_lock const lock(mut);
171  return load();
172  }
Here is the call graph for this function:

◆ initialize()

RawPageData::Ptr Scroom::MemoryBlobs::Blob::initialize ( uint8_t  value)
160  {
161  boost::mutex::scoped_lock const lock(mut);
162  RawPageData::Ptr result = load();
163  state = DIRTY;
164  memset(result.get(), value, size);
165  return result;
166  }
Here is the call graph for this function:

◆ load()

RawPageData::Ptr Scroom::MemoryBlobs::Blob::load ( )
private
82  {
83  RawPageData::Ptr result = weakData.lock();
84  if(!result)
85  {
86  switch(state)
87  {
88  case UNINITIALIZED:
89  // Allocate new data
90  data = static_cast<uint8_t*>(malloc(size * sizeof(uint8_t)));
91  break;
92  case CLEAN:
93  // Decompress data
94  data = static_cast<uint8_t*>(malloc(size * sizeof(uint8_t)));
96  break;
97  case DIRTY:
98  break;
99  case COMPRESSING:
100  // Data is currently being compressed. Abort...
101  state = DIRTY;
102  break;
103  default:
104  defect_message(fmt::format("Illegal state {}", state));
105  break;
106  }
107 
108  // data should point to something valid here...
109  result = RawPageData::Ptr(data, UnloadData(shared_from_this<Blob>()));
110  weakData = result;
111  refcount++;
112  }
113 
114  return result;
115  }

Referenced by get(), getConst(), and initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unload()

void Scroom::MemoryBlobs::Blob::unload ( )
private
118  {
119  boost::mutex::scoped_lock const lock(mut);
120  refcount--;
121  if(refcount == 0)
122  {
123  if(state == DIRTY)
124  {
125  state = COMPRESSING;
126  cpuBound->schedule(boost::bind(&Blob::compress, shared_from_this<Blob>()), COMPRESS_PRIO);
127  }
128  else
129  {
130  free(data);
131  data = nullptr;
132  }
133  }
134  }
Here is the call graph for this function:

Friends And Related Function Documentation

◆ UnloadData

friend class UnloadData
friend

Referenced by load().

Member Data Documentation

◆ cpuBound

boost::shared_ptr<ThreadPool> Scroom::MemoryBlobs::Blob::cpuBound
private

Referenced by unload().

◆ data

uint8_t* Scroom::MemoryBlobs::Blob::data {nullptr}
private

Referenced by compress(), load(), and unload().

◆ mut

boost::mutex Scroom::MemoryBlobs::Blob::mut
private

◆ pages

PageList Scroom::MemoryBlobs::Blob::pages
private

Referenced by compress(), and load().

◆ provider

PageProvider::Ptr Scroom::MemoryBlobs::Blob::provider
private

Referenced by compress(), create(), and load().

◆ refcount

int Scroom::MemoryBlobs::Blob::refcount {0}
private

Referenced by compress(), load(), and unload().

◆ size

size_t Scroom::MemoryBlobs::Blob::size
private

Referenced by compress(), create(), initialize(), and load().

◆ state

State Scroom::MemoryBlobs::Blob::state {UNINITIALIZED}
private

Referenced by compress(), get(), initialize(), load(), and unload().

◆ weakData

RawPageData::WeakPtr Scroom::MemoryBlobs::Blob::weakData
private

Referenced by load().


The documentation for this class was generated from the following files:
Scroom::MemoryBlobs::Blob::Ptr
boost::shared_ptr< Blob > Ptr
Definition: memoryblobs.hh:78
Scroom::MemoryBlobs::Blob::refcount
int refcount
Definition: memoryblobs.hh:110
Scroom::MemoryBlobs::Blob::provider
PageProvider::Ptr provider
Definition: memoryblobs.hh:102
Scroom::MemoryBlobs::Blob::weakData
RawPageData::WeakPtr weakData
Definition: memoryblobs.hh:107
Scroom::MemoryBlocks::RawPageData::Ptr
boost::shared_ptr< uint8_t > Ptr
Definition: blockallocator.hh:23
Scroom::MemoryBlobs::Blob::UnloadData
friend class UnloadData
Definition: memoryblobs.hh:99
Scroom::MemoryBlobs::Blob::UNINITIALIZED
@ UNINITIALIZED
Definition: memoryblobs.hh:83
Scroom::MemoryBlobs::Blob::load
RawPageData::Ptr load()
Definition: memoryblobs.cc:81
require
#define require(expr)
Definition: assertions.hh:28
Scroom::MemoryBlobs::Detail::compressBlob
PageList compressBlob(const uint8_t *in, size_t size, const PageProvider::Ptr &provider)
Definition: blob-compression.cc:30
Scroom::MemoryBlobs::Blob::size
size_t size
Definition: memoryblobs.hh:103
Scroom::MemoryBlobs::RawPageData::Ptr
boost::shared_ptr< uint8_t > Ptr
Definition: memoryblobs.hh:27
COMPRESS_PRIO
#define COMPRESS_PRIO
Definition: memoryblobs.cc:26
Scroom::MemoryBlobs::Blob::mut
boost::mutex mut
Definition: memoryblobs.hh:106
Scroom::MemoryBlobs::Blob::CLEAN
@ CLEAN
Definition: memoryblobs.hh:84
CpuBound
ThreadPool::Ptr CpuBound()
Definition: threadpoolimpl.cc:452
Scroom::MemoryBlobs::Blob::COMPRESSING
@ COMPRESSING
Definition: memoryblobs.hh:86
Scroom::MemoryBlobs::Blob::compress
void compress()
Definition: memoryblobs.cc:136
defect_message
#define defect_message(m)
Definition: assertions.hh:43
Scroom::MemoryBlobs::Detail::decompressBlob
void decompressBlob(uint8_t *out, size_t size, PageList list, const PageProvider::Ptr &provider)
Definition: blob-compression.cc:70
Scroom::MemoryBlobs::Blob::data
uint8_t * data
Definition: memoryblobs.hh:104
Scroom::MemoryBlobs::Blob::DIRTY
@ DIRTY
Definition: memoryblobs.hh:85
Scroom::MemoryBlobs::Blob::pages
PageList pages
Definition: memoryblobs.hh:108
Scroom::MemoryBlobs::Blob::Blob
Blob(PageProvider::Ptr provider, size_t size)
Definition: memoryblobs.cc:73
Scroom::MemoryBlobs::Blob::state
State state
Definition: memoryblobs.hh:105
Scroom::MemoryBlobs::Blob::cpuBound
boost::shared_ptr< ThreadPool > cpuBound
Definition: memoryblobs.hh:109