Skip to content

Commit 338e1ee

Browse files
committed
extended interface for memory region params
1 parent 7723ac8 commit 338e1ee

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/MemoryPagesPool.cxx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,32 @@ size_t MemoryPagesPool::getNumberOfPagesAvailable() {
5050
return pagesAvailable->getNumberOfUsedSlots();
5151
}
5252

53+
void *MemoryPagesPool::getBaseBlockAddress() {
54+
return baseBlockAddress;
55+
}
56+
size_t MemoryPagesPool::getBaseBlockSize() {
57+
return baseBlockSize;
58+
}
5359

5460

55-
std::shared_ptr<DataBlockContainer> MemoryPagesPool::getNewDataBlockContainer() {
56-
// get a new page from the pool
57-
void *newPage=getPage();
61+
std::shared_ptr<DataBlockContainer> MemoryPagesPool::getNewDataBlockContainer(void *newPage) {
5862
if (newPage==nullptr) {
59-
return nullptr;
63+
// get a new page from the pool
64+
newPage=getPage();
65+
if (newPage==nullptr) {
66+
return nullptr;
67+
}
6068
}
6169

70+
// fill header
71+
DataBlock *b=(DataBlock *)newPage;
72+
b->header.blockType=DataBlockType::H_BASE;
73+
b->header.headerSize=sizeof(DataBlockHeaderBase);
74+
b->header.dataSize=pageSize-sizeof(DataBlock);
75+
b->header.id=0;
76+
b->header.linkId=0;
77+
b->data=&(((char *)b)[sizeof(DataBlock)]);
78+
6279
// define a function to put it back in pool after use
6380
auto releaseCallback = [this, newPage] (void) -> void {
6481
this->releasePage(newPage);
@@ -72,5 +89,7 @@ std::shared_ptr<DataBlockContainer> MemoryPagesPool::getNewDataBlockContainer()
7289
return nullptr;
7390
}
7491

92+
//printf("create dbc %p with data=%p stored=%p\n",bc,newPage,bc->getData());
93+
7594
return bc;
7695
}

src/MemoryPagesPool.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class MemoryPagesPool {
2626
void *getPage(); // get a new page from the pool (if available, nullptr if none)
2727
void releasePage(void *address); // insert back page to the pool after use, to make it available again
2828

29-
size_t getPageSize(); // retrieve the page size
30-
size_t getTotalNumberOfPages(); // retrieve number of pages in pool
31-
size_t getNumberOfPagesAvailable(); //retrieve number of pages currently available
32-
33-
std::shared_ptr<DataBlockContainer>getNewDataBlockContainer(); // returns an empty data block container (with data = a new page) from the pool. Page will be put back in pool after use.
34-
29+
size_t getPageSize(); // get the page size
30+
size_t getTotalNumberOfPages(); // get number of pages in pool
31+
size_t getNumberOfPagesAvailable(); //get number of pages currently available
32+
void *getBaseBlockAddress(); // get the base address of memory pool block
33+
size_t getBaseBlockSize(); // get the size of memory pool block. All pages guaranteed to be within &baseBlockAddress[0] and &baseBlockAddress[baseBlockSize]
34+
35+
std::shared_ptr<DataBlockContainer>getNewDataBlockContainer(void *page=nullptr); // returns an empty data block container (with data = a given page, retrieved previously by getPage(), or new page if null) from the pool. Page will be put back in pool after use.
36+
3537
private:
3638
std::unique_ptr<AliceO2::Common::Fifo<void *>> pagesAvailable; // a buffer to keep track of individual pages
3739

0 commit comments

Comments
 (0)