2424#include " dramstore.h"
2525#include " logger/logger.h"
2626#include " status/status.h"
27+ #include " trans/dram_trans_manager.h"
28+ #include " memory/memory_pool.h"
2729
2830namespace UC {
2931
3032class DRAMStoreImpl : public DRAMStore {
3133public:
32- int32_t Setup (const size_t ioSize, const size_t capacity, const int32_t deviceId) { return -1 ; }
33- int32_t Alloc (const std::string& block) override { return -1 ; }
34- bool Lookup (const std::string& block) override { return false ; }
35- void Commit (const std::string& block, const bool success) override {}
34+ int32_t Setup (const Config& config) {
35+ auto status = this ->memPool_ .Setup (config.deviceId , config.capacity , config.blockSize );
36+ if (status.Failure ()) {
37+ UC_ERROR (" Failed({}) to setup MemoryPool." , status);
38+ return status.Underlying ();
39+ }
40+ status = this ->transMgr_ .Setup (config.deviceId , config.streamNumber , &this ->memPool_ , config.timeoutMs );
41+ if (status.Failure ()) {
42+ UC_ERROR (" Failed({}) to setup TsfTaskManager." , status);
43+ return status.Underlying ();
44+ }
45+ return Status::OK ().Underlying ();
46+ }
47+ int32_t Alloc (const std::string& block) override { return this ->memPool_ .NewBlock (block).Underlying (); }
48+ bool Lookup (const std::string& block) override { return this ->memPool_ .LookupBlock (block); }
49+ void Commit (const std::string& block, const bool success) override { this ->memPool_ .CommitBlock (block, success).Underlying (); }
3650 std::list<int32_t > Alloc (const std::list<std::string>& blocks) override
3751 {
38- return std::list<int32_t >();
52+ std::list<int32_t > results;
53+ for (const auto &block : blocks) {
54+ results.emplace_back (this ->Alloc (block));
55+ }
56+ return results;
3957 }
4058 std::list<bool > Lookup (const std::list<std::string>& blocks) override
4159 {
42- return std::list<bool >();
60+ std::list<bool > founds;
61+ for (const auto &block : blocks) {
62+ founds.emplace_back (this ->Lookup (block));
63+ }
64+ return founds;
65+ }
66+ void Commit (const std::list<std::string>& blocks, const bool success) override {
67+ for (const auto &block : blocks) {
68+ this ->Commit (block, success);
69+ }
70+ }
71+ size_t Submit (Task&& task) override {
72+ auto taskId = Task::invalid;
73+ auto status = this ->transMgr_ .Submit (std::move (task), taskId);
74+ if (status.Failure ()) { taskId = Task::invalid; }
75+ return taskId; }
76+
77+ int32_t Wait (const size_t task) override {
78+ return this ->transMgr_ .Wait (task).Underlying ();
79+ }
80+
81+ int32_t Check (const size_t task, bool & finish) override {
82+ return this ->transMgr_ .Check (task, finish).Underlying ();
4383 }
44- void Commit (const std::list<std::string>& blocks, const bool success) override {}
45- size_t Submit (Task&& task) override { return 0 ; }
46- int32_t Wait (const size_t task) override { return -1 ; }
47- int32_t Check (const size_t task, bool & finish) override { return -1 ; }
84+
85+
86+ private:
87+
88+ DramTransManager transMgr_;
89+ MemoryPool memPool_;
90+
4891};
4992
5093int32_t DRAMStore::Setup (const Config& config)
@@ -55,7 +98,7 @@ int32_t DRAMStore::Setup(const Config& config)
5598 return Status::OutOfMemory ().Underlying ();
5699 }
57100 this ->impl_ = impl;
58- return impl->Setup (config. ioSize , config. capacity , config. deviceId );
101+ return impl->Setup (config);
59102}
60103
61104} // namespace UC
0 commit comments