9#ifndef SQUID_SRC_IPC_MEMMAP_H
10#define SQUID_SRC_IPC_MEMMAP_H
29#define MEMMAP_SLOT_KEY_SIZE 32
30#define MEMMAP_SLOT_DATA_SIZE 10*1024
40 void set(
const unsigned char *aKey,
const void *block,
size_t blockSize, time_t
expire = 0);
65 Shared(
const int aLimit,
const size_t anExtrasSize);
82 MemMap(
const char *
const aPath);
114 bool valid(
const int n)
const;
126 static Owner *
Init(
const char *
const path,
const int limit,
const size_t extrasSize);
#define MEMMAP_SLOT_KEY_SIZE
#define MEMMAP_SLOT_DATA_SIZE
API for adjusting external state when dirty map slot is being freed.
virtual void noteFreeMapSlot(const sfileno slotId)=0
adjust slot-linked state before a locked Readable slot is erased
a MemMap basic element, holding basic shareable memory block info
bool sameKey(const cache_key *const aKey) const
void set(const unsigned char *aKey, const void *block, size_t blockSize, time_t expire=0)
std::atomic< uint8_t > waitingToBeFreed
may be accessed w/o a lock
ReadWriteLock lock
protects slot data below
unsigned char key[MEMMAP_SLOT_KEY_SIZE]
The entry key.
unsigned char p[MEMMAP_SLOT_DATA_SIZE]
The memory block;.
data shared across maps in different processes
std::atomic< int > count
current number of map slots
Ipc::Mem::FlexibleArray< Slot > slots
storage
static size_t SharedMemorySize(const int limit, const size_t anExtrasSize)
size_t sharedMemorySize() const
const size_t extrasSize
size of slot extra data
const int limit
maximum number of map slots
A map of MemMapSlots indexed by their keys, with read/write slot locking.
void free(const sfileno fileno)
mark the slot as waiting to be freed and, if possible, free it
const SBuf path
cache_dir path, used for logging
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
bool valid(const int n) const
whether n is a valid slot coordinate
Mem::Pointer< Shared > shared
void abortWriting(const sfileno fileno)
terminate writing the entry, freeing its slot for others to use
bool full() const
there are no empty slots left
int slotIndexByKey(const cache_key *const key) const
int entryLimit() const
maximum number of slots that can be used
void freeLocked(Slot &s, bool keepLocked)
unconditionally frees the already exclusively locked slot and releases lock
Slot * openForReading(Slot &s)
void closeForReading(const sfileno fileno)
close slot after reading, decrements read level
void freeIfNeeded(Slot &s)
const Slot * openForReading(const cache_key *const key, sfileno &fileno)
open slot for reading, increments read level
void switchWritingToReading(const sfileno fileno)
stop writing the locked entry and start reading it
const Slot * openForReadingAt(const sfileno fileno)
open slot for reading, increments read level
Slot * openForWriting(const cache_key *const key, sfileno &fileno)
Slot & slotByKey(const cache_key *const key)
static Owner * Init(const char *const path, const int limit)
initialize shared memory
int entryCount() const
number of used slots
void closeForWriting(const sfileno fileno)
successfully finish writing the entry
const Slot * peekAtReader(const sfileno fileno) const
only works on locked entries; returns nil unless the slot is readable
Slot * openForWritingAt(sfileno fileno, bool overwriteExisting=true)
Mem::Owner< Shared > Owner
approximate stats of a set of ReadWriteLocks
std::atomic< uint32_t > readers
number of reading users
std::atomic< bool > writing
there is a writing user (there can be at most 1)
unsigned char cache_key
Store key.