BufferProvider: decision to use a free-standing pool with lock-free queue
After several fruitless attempts, I have decided now to settle for self-contained ''memory pool'' component, that can be operated **thread-locally** and employs a **lock-free** message queue for the allotment of memory. Seemingly the question of how this relates to `BufferMetadata` must remain unresolved for the time being, until the entire buffer memory subsystem is available for empirical investigation.
This commit is contained in:
parent
e277913e22
commit
e328018b05
3 changed files with 1198 additions and 52 deletions
|
|
@ -25,17 +25,25 @@
|
||||||
#define VAULT_MEM_LOCAL_MEM_POOL_H
|
#define VAULT_MEM_LOCAL_MEM_POOL_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "lib/error.hpp"
|
||||||
//#include "vault/mem/buffer-provider-setup.hpp"
|
//#include "vault/mem/buffer-provider-setup.hpp"
|
||||||
//#include "vault/mem/engine-buffer-metadata.hpp"
|
//#include "vault/mem/engine-buffer-metadata.hpp"
|
||||||
//#include "vault/mem/buffer-metadata.hpp"
|
//#include "vault/mem/buffer-metadata.hpp"
|
||||||
#include "vault/mem/buffhandle.hpp" //////////////TODO
|
#include "vault/mem/buffhandle.hpp" //////////////TODO
|
||||||
//#include "lib/local-slice.hpp"
|
//#include "lib/local-slice.hpp"
|
||||||
//#include "lib/depend.hpp"
|
//#include "lib/depend.hpp"
|
||||||
|
#include "lib/nocopy.hpp"
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
|
||||||
namespace vault {
|
namespace vault {
|
||||||
namespace mem {
|
namespace mem {
|
||||||
|
namespace err = lumiera::error;
|
||||||
|
|
||||||
|
using std::tuple;
|
||||||
|
|
||||||
|
class PoolDiagnostic;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,9 +55,71 @@ namespace mem {
|
||||||
public:
|
public:
|
||||||
LocalMemPool()
|
LocalMemPool()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
/* ===== Pool Access API ===== */
|
||||||
|
|
||||||
|
bool empty() const { return 0 == size(); }
|
||||||
|
size_t size() const { return 0; } ///////////////////////OOO
|
||||||
|
|
||||||
|
bool
|
||||||
|
canServe (size_t sizRequest)
|
||||||
|
{
|
||||||
|
return false; ///////////////////////////////////////OOO
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
add (Buff* mem, size_t siz)
|
||||||
|
{
|
||||||
|
TODO ("add new alloc to pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
reAdd (Buff* mem)
|
||||||
|
{
|
||||||
|
TODO ("return known alloc into pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
tuple<Buff*,size_t>
|
||||||
|
retrieve (size_t sizRequest)
|
||||||
|
{
|
||||||
|
return {nullptr, 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
friend class PoolDiagnostic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class PoolDiagnostic
|
||||||
|
: util::MoveOnly
|
||||||
|
{
|
||||||
|
LocalMemPool memPool_;
|
||||||
|
public:
|
||||||
|
PoolDiagnostic (LocalMemPool& lmp)
|
||||||
|
: memPool_{lmp}
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool
|
||||||
|
isEmpty()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} ///////////////////OOO
|
||||||
|
|
||||||
|
size_t
|
||||||
|
cnt (size_t siz)
|
||||||
|
{
|
||||||
|
return 0; ////////////////////OOO
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline PoolDiagnostic
|
||||||
|
watch (LocalMemPool& lmp)
|
||||||
|
{
|
||||||
|
return PoolDiagnostic{lmp};
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace vault::mem
|
}} // namespace vault::mem
|
||||||
#endif /*VAULT_MEM_LOCAL_MEM_POOL_H*/
|
#endif /*VAULT_MEM_LOCAL_MEM_POOL_H*/
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,19 @@ namespace test {
|
||||||
|
|
||||||
namespace { // Test helper
|
namespace { // Test helper
|
||||||
|
|
||||||
// template<typename X>
|
inline constexpr Buff*
|
||||||
// Buff*
|
fake_Buffer(size_t id)
|
||||||
// mark_as_Buffer(X& something)
|
{
|
||||||
// {
|
return reinterpret_cast<Buff*> (id);
|
||||||
// return reinterpret_cast<Buff*> (std::addressof(something));
|
}
|
||||||
// }
|
|
||||||
//
|
Buff* const MEM1 = fake_Buffer(1);
|
||||||
|
Buff* const MEM2 = fake_Buffer(2);
|
||||||
|
Buff* const MEM3 = fake_Buffer(3);
|
||||||
|
|
||||||
|
const size_t SIZ10{10};
|
||||||
|
const size_t SIZ20{20};
|
||||||
|
const size_t SIZ30{30};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,15 +69,52 @@ namespace test {
|
||||||
{
|
{
|
||||||
seedRand();
|
seedRand();
|
||||||
|
|
||||||
verify_blah();
|
simpleUse();
|
||||||
verify_lolz();
|
verify_matchAlloc();
|
||||||
|
verify_selectAlloc();
|
||||||
|
verify_pruneAlloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @test */
|
/** @test show how to place an allocation into the pool */
|
||||||
void
|
void
|
||||||
verify_blah()
|
simpleUse()
|
||||||
|
{
|
||||||
|
LocalMemPool pool;
|
||||||
|
pool.add (MEM1, SIZ20);
|
||||||
|
CHECK (pool.canServe(SIZ20));
|
||||||
|
CHECK (pool.canServe(SIZ10));
|
||||||
|
|
||||||
|
auto [mem,siz] = pool.retrieve (SIZ10);
|
||||||
|
CHECK (MEM1 == mem);
|
||||||
|
CHECK (SIZ20 == siz);
|
||||||
|
CHECK (not pool.canServe(SIZ10));
|
||||||
|
|
||||||
|
pool.reAdd (MEM1);
|
||||||
|
CHECK (pool.canServe(SIZ20));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @test
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
verify_matchAlloc()
|
||||||
|
{
|
||||||
|
LocalMemPool pool;
|
||||||
|
CHECK (watch(pool).isEmpty());
|
||||||
|
|
||||||
|
pool.add (MEM1, SIZ10);
|
||||||
|
CHECK (watch(pool).cnt(SIZ10) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** @test
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
verify_selectAlloc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +123,7 @@ namespace test {
|
||||||
/** @test
|
/** @test
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
verify_lolz()
|
verify_pruneAlloc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue