Skip to content

Commit

Permalink
Sequential cache now provides block pos and size.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Dec 20, 2024
1 parent 60166d2 commit bf98d39
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/storage/include/storage/SequentialCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ namespace l::filecache {
int32_t beginPosition,
int32_t endPosition,
int32_t blockWidth,
std::function<bool(CacheBlock<T>*)> callback) {
std::function<bool(int32_t start, int32_t size, CacheBlock<T>*)> callback) {

std::unique_lock<std::mutex> lock(mMutexSequentialCacheMap);
auto it = mSequentialCacheMap.find(cacheKey.data());
Expand All @@ -305,11 +305,13 @@ namespace l::filecache {

auto cacheBlockWidth = sequentialCacheMap->GetBlockWidth();
CacheBlock<T>* cacheBlock = nullptr;

beginPosition = GetClampedPosition(beginPosition, cacheBlockWidth);
if (beginPosition < endPosition) {
do {
cacheBlock = sequentialCacheMap->Get(beginPosition);
if (cacheBlock != nullptr) {
if (!callback(cacheBlock)) {
if (!callback(beginPosition, cacheBlockWidth, cacheBlock)) {
break;
}
}
Expand All @@ -323,7 +325,7 @@ namespace l::filecache {
do {
cacheBlock = sequentialCacheMap->Get(beginPosition);
if (cacheBlock != nullptr) {
if (!callback(cacheBlock)) {
if (!callback(beginPosition, cacheBlockWidth, cacheBlock)) {
break;
}
}
Expand All @@ -342,7 +344,7 @@ namespace l::filecache {
int32_t beginPosition,
int32_t endPosition,
int32_t blockWidth,
std::function<bool(CacheBlock<T>*, CacheBlock<T>*)> callback) {
std::function<bool(int32_t, int32_t, CacheBlock<T>*, CacheBlock<T>*)> callback) {

std::unique_lock<std::mutex> lock(mMutexSequentialCacheMap);
auto it1 = mSequentialCacheMap.find(cacheKey1.data());
Expand Down Expand Up @@ -381,14 +383,15 @@ namespace l::filecache {

CacheBlock<T>* cacheBlock1 = nullptr;
CacheBlock<T>* cacheBlock2 = nullptr;
beginPosition = GetClampedPosition(beginPosition, cacheBlockWidth1);
if (beginPosition < endPosition) {
do {
cacheBlock1 = sequentialCacheMap1->Get(beginPosition);
if (cacheBlock1 != nullptr) {
if (sequentialCacheMap2 != nullptr) {
cacheBlock2 = sequentialCacheMap2->Get(beginPosition);
}
if (!callback(cacheBlock1, cacheBlock2)) {
if (!callback(beginPosition, cacheBlockWidth1, cacheBlock1, cacheBlock2)) {
break;
}
}
Expand All @@ -405,7 +408,7 @@ namespace l::filecache {
if (sequentialCacheMap2 != nullptr) {
cacheBlock2 = sequentialCacheMap2->Get(beginPosition);
}
if (!callback(cacheBlock1, cacheBlock2)) {
if (!callback(beginPosition, cacheBlockWidth1, cacheBlock1, cacheBlock2)) {
break;
}
}
Expand Down

0 comments on commit bf98d39

Please sign in to comment.