SpiecsEngine
 
Loading...
Searching...
No Matches

◆ GetOneSpan()

scl::span * Spices::CentralCache::GetOneSpan ( scl::span_list & list,
size_t size )
staticprivate

Get a not empty span.

Parameters
[in,out]listspan list.
[in]sizealigned bytes.
Returns
Returns span.

Find span in cc.

Release mutex.

get pages count.

get a new span.

get start/end pointer.

split pages to blocks.

Get mutex.

Push to list.

Find span in cc.

Release mutex.

get pages count.

get a new span.

get start/end pointer.

split pages to blocks.

Get mutex.

Push to list.

Definition at line 48 of file CentralCache.cpp.

49 {
53 scl::span* it = list.Begin();
54 while (it != list.End())
55 {
56 if (it->m_FreeList != nullptr)
57 {
58 return it;
59 }
60 else
61 {
62 it = it->m_Next;
63 }
64 }
65
69 list.GetMutex().unlock();
70
74 size_t k = MemoryPool::GetPages(size);
75
80 s->m_IsUse = true;
81 s->m_BlockSize = size;
82
86 char* start = reinterpret_cast<char*>( s->m_PageId << MemoryPool::PAGE_SHIFT );
87 char* end = reinterpret_cast<char*>(start + (s->m_NPages << MemoryPool::PAGE_SHIFT));
88
89 s->m_FreeList = start;
90
94 {
95 void* tail = start;
96 start += size;
97
98 int i = 0;
99 while (start + size <= end)
100 {
101 ++i;
103 start += size;
105 }
107 }
108
112 list.GetMutex().lock();
113
117 list.PushFront(s);
118
119 return s;
120 }
static size_t GetPages(size_t size)
Get pages count by given bytes.
static constexpr size_t PAGE_SHIFT
8KB in a page.
Definition MemoryPool.h:44
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
static PageCache * Get()
Get this single instance.
Definition PageCache.h:50
scl::span * NewSpan(size_t k)
Fetch pages span.
Definition PageCache.cpp:14
void PushFront(span *s)
Push a span to this list.
Definition SpanList.cpp:40
span * Begin() const
Get begin pointer.
Definition SpanList.cpp:59
span * End() const
Get end pointer.
Definition SpanList.cpp:64
std::mutex & GetMutex()
Get mutex.
Definition SpanList.h:133
span * m_Next
next span.
Definition SpanList.h:41
size_t m_BlockSize
page block size.
Definition SpanList.h:66
size_t m_PageId
Start page id.
Definition SpanList.h:31
void * m_FreeList
current pointer.
Definition SpanList.h:51
size_t m_NPages
How much page it managed.
Definition SpanList.h:36
bool m_IsUse
True if in use.
Definition SpanList.h:61
Used for manage multiple page memory.
Definition SpanList.h:15
typename detail::tail< TypeList >::type tail
Get elements of type_list except the first.
Definition TypeList.h:273

References scl::span_list::Begin(), scl::span_list::End(), scl::span::m_FreeList, scl::span::m_IsUse, scl::span::m_Next, Spices::MemoryPool::PointerSpace(), and scl::span_list::PushFront().