Skip to content

Commit

Permalink
Maintenance: code refactoring, removed references to MemObject state …
Browse files Browse the repository at this point in the history
…specifiers, instead using enum values directly from Store class
  • Loading branch information
vshailesh committed Dec 13, 2024
1 parent db10e99 commit 2355803
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/MemObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ class MemObject

SwapOut swapout;

static constexpr Store::IoStatus ioUndecided = Store::ioUndecided;
static constexpr Store::IoStatus ioReading = Store::ioReading;
static constexpr Store::IoStatus ioWriting = Store::ioWriting;
static constexpr Store::IoStatus ioDone = Store::ioDone;
// static constexpr Store::IoStatus ioUndecided = Store::ioUndecided;
// static constexpr Store::IoStatus ioReading = Store::ioReading;
// static constexpr Store::IoStatus ioWriting = Store::ioWriting;
// static constexpr Store::IoStatus ioDone = Store::ioDone;

/// State of an entry with regards to the [shared] in-transit table.
class XitTable
Expand All @@ -192,7 +192,7 @@ class MemObject
}

int32_t index = -1; ///< entry position inside the in-transit table
Store::IoStatus io = ioUndecided; ///< current I/O state
Store::IoStatus io = Store::ioUndecided; ///< current I/O state
};
XitTable xitTable; ///< current [shared] memory caching state for the entry

Expand Down
27 changes: 14 additions & 13 deletions src/MemStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SquidMath.h"
#include "StoreStats.h"
#include "tools.h"
#include "store/forward.h"

/// shared memory segment path to use for MemStore maps
static const auto MapLabel = "cache_mem_map";
Expand Down Expand Up @@ -401,7 +402,7 @@ bool
MemStore::anchorToCache(StoreEntry &entry)
{
Assure(!entry.hasMemStore());
Assure(entry.mem().memCache.io != MemObject::ioDone);
Assure(entry.mem().memCache.io != Store::ioDone);

if (!map)
return false;
Expand Down Expand Up @@ -462,7 +463,7 @@ MemStore::anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnc

MemObject::MemCache &mc = e.mem_obj->memCache;
mc.index = index;
mc.io = MemObject::ioReading;
mc.io = Store::ioReading;
}

/// copies the entire entry from shared to local memory
Expand Down Expand Up @@ -656,7 +657,7 @@ MemStore::startCaching(StoreEntry &e)

assert(e.mem_obj);
e.mem_obj->memCache.index = index;
e.mem_obj->memCache.io = MemObject::ioWriting;
e.mem_obj->memCache.io = Store::ioWriting;
slot->set(e);
// Do not allow others to feed off an unknown-size entry because we will
// stop swapping it out if it grows too large.
Expand Down Expand Up @@ -850,19 +851,19 @@ MemStore::write(StoreEntry &e)
debugs(20, 7, "entry " << e);

switch (e.mem_obj->memCache.io) {
case MemObject::ioUndecided:
case Store::ioUndecided:
if (!shouldCache(e) || !startCaching(e)) {
e.mem_obj->memCache.io = MemObject::ioDone;
e.mem_obj->memCache.io = Store::ioDone;
e.memOutDecision(false);
return;
}
break;

case MemObject::ioDone:
case MemObject::ioReading:
case Store::ioDone:
case Store::ioReading:
return; // we should not write in all of the above cases

case MemObject::ioWriting:
case Store::ioWriting:
break; // already decided to write and still writing
}

Expand Down Expand Up @@ -892,7 +893,7 @@ MemStore::completeWriting(StoreEntry &e)
debugs(20, 5, "mem-cached all " << e.mem_obj->memCache.offset << " bytes of " << e);

e.mem_obj->memCache.index = -1;
e.mem_obj->memCache.io = MemObject::ioDone;
e.mem_obj->memCache.io = Store::ioDone;
map->closeForWriting(index);

CollapsedForwarding::Broadcast(e);
Expand Down Expand Up @@ -931,17 +932,17 @@ MemStore::disconnect(StoreEntry &e)
assert(e.mem_obj);
MemObject &mem_obj = *e.mem_obj;
if (e.hasMemStore()) {
if (mem_obj.memCache.io == MemObject::ioWriting) {
if (mem_obj.memCache.io == Store::ioWriting) {
map->abortWriting(mem_obj.memCache.index);
mem_obj.memCache.index = -1;
mem_obj.memCache.io = MemObject::ioDone;
mem_obj.memCache.io = Store::ioDone;
CollapsedForwarding::Broadcast(e);
e.storeWriterDone();
} else {
assert(mem_obj.memCache.io == MemObject::ioReading);
assert(mem_obj.memCache.io == Store::ioReading);
map->closeForReading(mem_obj.memCache.index);
mem_obj.memCache.index = -1;
mem_obj.memCache.io = MemObject::ioDone;
mem_obj.memCache.io = Store::ioDone;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/store/Controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "store/LocalSearch.h"
#include "tools.h"
#include "Transients.h"
#include "store/forward.h"

#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
Expand Down Expand Up @@ -801,7 +802,7 @@ Store::Controller::syncCollapsed(const sfileno xitIndex)

bool found = false;
bool inSync = false;
if (sharedMemStore && collapsed->mem_obj->memCache.io == MemObject::ioDone) {
if (sharedMemStore && collapsed->mem_obj->memCache.io == Store::ioDone) {
found = true;
inSync = true;
debugs(20, 7, "already handled by memory store: " << *collapsed);
Expand Down Expand Up @@ -868,7 +869,7 @@ Store::Controller::anchorToCache(StoreEntry &entry)
// TODO: Attach entries to both memory and disk

// TODO: Reduce code duplication with syncCollapsed()
if (sharedMemStore && entry.mem().memCache.io == MemObject::ioDone) {
if (sharedMemStore && entry.mem().memCache.io == Store::ioDone) {
debugs(20, 5, "already handled by memory store: " << entry);
return true;
} else if (sharedMemStore && entry.hasMemStore()) {
Expand Down

0 comments on commit 2355803

Please sign in to comment.