Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
memoryblobs.hh
Go to the documentation of this file.
1/*
2 * Scroom - Generic viewer for 2D data
3 * Copyright (C) 2009-2026 Kees-Jan Dijkzeul
4 *
5 * SPDX-License-Identifier: LGPL-2.1
6 */
7
8#pragma once
9
10#include <cstdint>
11#include <list>
12#include <memory>
13#include <utility>
14
15#include <boost/thread.hpp>
16
18#include <scroom/utilities.hh>
19
20class ThreadPool;
21
23{
24 namespace RawPageData
25 {
26 using Ptr = std::shared_ptr<uint8_t>;
27 using ConstPtr = std::shared_ptr<const uint8_t>;
28 using WeakPtr = std::weak_ptr<uint8_t>;
29 } // namespace RawPageData
30
31 namespace Page
32 {
33 using Ptr = std::shared_ptr<Scroom::MemoryBlocks::Page>;
34 }
35 using PageList = std::list<Page::Ptr>;
36
37 class PageProvider : virtual public Scroom::Utils::Base
38 {
39 public:
40 using Ptr = std::shared_ptr<PageProvider>;
41
42 private:
43 size_t blockCount;
44 size_t blockSize;
47 std::list<Scroom::MemoryBlocks::Page*> freePages;
48 boost::mutex mut;
49
50 private:
52 {
53 private:
55
56 public:
59 };
60
61 friend class MarkPageFree;
62
63 private:
64 PageProvider(size_t blockCount, size_t blockSize);
65
67
68 public:
69 static Ptr create(size_t blockCount, size_t blockSize);
71 size_t getPageSize() const;
72 };
73
74 class Blob : virtual public Scroom::Utils::Base
75 {
76 public:
77 using Ptr = std::shared_ptr<Blob>;
78
79 private:
87
89 {
90 private:
92
93 public:
94 explicit UnloadData(Blob::Ptr blob);
95 void operator()(uint8_t* data);
96 };
97
98 friend class UnloadData;
99
100 private:
102 size_t size;
103 uint8_t* data{nullptr};
105 boost::mutex mut;
108 std::shared_ptr<ThreadPool> cpuBound;
109 int refcount{0}; // Yuk
110
111 private:
113 void unload();
115 void compress();
116
117 public:
118 static Ptr create(PageProvider::Ptr provider, size_t size);
122 };
123
125 // Implementation
126
128 : provider(std::move(provider_))
129 {
130 }
131
133
135
137 : blob(std::move(blob_))
138 {
139 }
140
141 inline void Blob::UnloadData::operator()(uint8_t* /*unused*/)
142 {
143 blob->unload();
144 blob.reset();
145 }
146} // namespace Scroom::MemoryBlobs
const uint8_t value
Definition blob-tests.cc:114
PageProvider::Ptr provider
Definition blob-tests.cc:26
Definition memoryblobs.hh:89
UnloadData(Blob::Ptr blob)
Definition memoryblobs.hh:136
Blob::Ptr blob
Definition memoryblobs.hh:91
void operator()(uint8_t *data)
Definition memoryblobs.hh:141
Definition memoryblobs.hh:75
std::shared_ptr< ThreadPool > cpuBound
Definition memoryblobs.hh:108
std::shared_ptr< Blob > Ptr
Definition memoryblobs.hh:77
uint8_t * data
Definition memoryblobs.hh:103
void compress()
Definition memoryblobs.cc:136
static Ptr create(PageProvider::Ptr provider, size_t size)
Definition memoryblobs.cc:71
State
Definition memoryblobs.hh:81
@ DIRTY
Definition memoryblobs.hh:84
@ COMPRESSING
Definition memoryblobs.hh:85
@ CLEAN
Definition memoryblobs.hh:83
@ UNINITIALIZED
Definition memoryblobs.hh:82
void unload()
Definition memoryblobs.cc:117
RawPageData::Ptr get()
Definition memoryblobs.cc:151
PageList pages
Definition memoryblobs.hh:107
RawPageData::Ptr load()
Definition memoryblobs.cc:81
State state
Definition memoryblobs.hh:104
RawPageData::Ptr initialize(uint8_t value)
Definition memoryblobs.cc:159
int refcount
Definition memoryblobs.hh:109
PageProvider::Ptr provider
Definition memoryblobs.hh:101
boost::mutex mut
Definition memoryblobs.hh:105
RawPageData::WeakPtr weakData
Definition memoryblobs.hh:106
RawPageData::ConstPtr getConst()
Definition memoryblobs.cc:168
size_t size
Definition memoryblobs.hh:102
MarkPageFree(PageProvider::Ptr provider)
Definition memoryblobs.hh:127
PageProvider::Ptr provider
Definition memoryblobs.hh:54
void operator()(Scroom::MemoryBlocks::Page *page)
Definition memoryblobs.hh:132
Definition memoryblobs.hh:38
size_t getPageSize() const
Definition memoryblobs.cc:61
static Ptr create(size_t blockCount, size_t blockSize)
Definition memoryblobs.cc:37
void markPageFree(Scroom::MemoryBlocks::Page *page)
Definition memoryblobs.cc:63
Page::Ptr getFreePage()
Definition memoryblobs.cc:42
size_t blockSize
Definition memoryblobs.hh:44
Scroom::MemoryBlocks::BlockFactoryInterface::Ptr blockFactoryInterface
Definition memoryblobs.hh:45
Scroom::MemoryBlocks::PageList allPages
Definition memoryblobs.hh:46
size_t blockCount
Definition memoryblobs.hh:43
std::list< Scroom::MemoryBlocks::Page * > freePages
Definition memoryblobs.hh:47
std::shared_ptr< PageProvider > Ptr
Definition memoryblobs.hh:40
boost::mutex mut
Definition memoryblobs.hh:48
std::shared_ptr< BlockFactoryInterface > Ptr
Definition blockallocator.hh:59
Definition blockallocator.hh:28
Definition utilities.hh:34
Definition threadpool.hh:43
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
std::shared_ptr< Scroom::MemoryBlocks::Page > Ptr
Definition memoryblobs.hh:33
std::shared_ptr< const uint8_t > ConstPtr
Definition memoryblobs.hh:27
std::shared_ptr< uint8_t > Ptr
Definition memoryblobs.hh:26
std::weak_ptr< uint8_t > WeakPtr
Definition memoryblobs.hh:28
Definition memoryblobs.hh:23
std::list< Page::Ptr > PageList
Definition memoryblobs.hh:35
std::list< Page > PageList
Definition blockallocator.hh:39
STL namespace.