Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
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 = std::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 >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::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
 
std::shared_ptr< ThreadPoolcpuBound
 
int refcount {0}
 

Friends

class UnloadData
 

Member Typedef Documentation

◆ Ptr

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

Member Enumeration Documentation

◆ State

Enumerator
UNINITIALIZED 
CLEAN 
DIRTY 
COMPRESSING 
81 {
83 CLEAN,
84 DIRTY,
86 };
@ DIRTY
Definition memoryblobs.hh:84
@ COMPRESSING
Definition memoryblobs.hh:85
@ CLEAN
Definition memoryblobs.hh:83
@ UNINITIALIZED
Definition memoryblobs.hh:82

Constructor & Destructor Documentation

◆ Blob()

Scroom::MemoryBlobs::Blob::Blob ( PageProvider::Ptr  provider,
size_t  size 
)
private
74 : provider(std::move(provider_))
75 , size(size_)
77
78 {
79 }
std::shared_ptr< ThreadPool > cpuBound
Definition memoryblobs.hh:108
PageProvider::Ptr provider
Definition memoryblobs.hh:101
size_t size
Definition memoryblobs.hh:102
ThreadPool::Ptr CpuBound()
Definition threadpoolimpl.cc:455

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 }
#define require(expr)
Definition assertions.hh:30
uint8_t * data
Definition memoryblobs.hh:103
PageList pages
Definition memoryblobs.hh:107
State state
Definition memoryblobs.hh:104
int refcount
Definition memoryblobs.hh:109
boost::mutex mut
Definition memoryblobs.hh:105
PageList compressBlob(const uint8_t *in, size_t size, const PageProvider::Ptr &provider)
Definition blob-compression.cc:31
Here is the call 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)); }
std::shared_ptr< Blob > Ptr
Definition memoryblobs.hh:77
Blob(PageProvider::Ptr provider, size_t size)
Definition memoryblobs.cc:73

Referenced by for().

Here is the caller graph for this function:

◆ get()

RawPageData::Ptr Scroom::MemoryBlobs::Blob::get ( )
152 {
153 boost::mutex::scoped_lock const lock(mut);
155 state = DIRTY;
156 return result;
157 }
RawPageData::Ptr load()
Definition memoryblobs.cc:81
std::shared_ptr< uint8_t > Ptr
Definition blockallocator.hh:21
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94
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);
163 state = DIRTY;
164 memset(result.get(), value, size);
165 return result;
166 }
memset(expected, value, blobSize)
const uint8_t value
Definition blob-tests.cc:114
Here is the call graph for this function:

◆ load()

RawPageData::Ptr Scroom::MemoryBlobs::Blob::load ( )
private
82 {
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 {}", static_cast<int>(state)));
105 break;
106 }
107
108 // data should point to something valid here...
109 result = RawPageData::Ptr(data, UnloadData(shared_from_this<Blob>()));
111 refcount++;
112 }
113
114 return result;
115 }
#define defect_message(m)
Definition assertions.hh:49
friend class UnloadData
Definition memoryblobs.hh:98
RawPageData::WeakPtr weakData
Definition memoryblobs.hh:106
void decompressBlob(uint8_t *out, size_t size, PageList list, const PageProvider::Ptr &provider)
Definition blob-compression.cc:71
std::shared_ptr< uint8_t > Ptr
Definition memoryblobs.hh:26

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 {
126 cpuBound->schedule([me = shared_from_this<Blob>()] { me->compress(); }, COMPRESS_PRIO);
127 }
128 else
129 {
130 free(data);
131 data = nullptr;
132 }
133 }
134 }
#define COMPRESS_PRIO
Definition memoryblobs.cc:26

Friends And Related Symbol Documentation

◆ UnloadData

friend class UnloadData
friend

Member Data Documentation

◆ cpuBound

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

Referenced by unload().

◆ data

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

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
109{0}; // Yuk

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: