Squid Web Cache master
Loading...
Searching...
No Matches
Ipc::MemMap Class Reference

A map of MemMapSlots indexed by their keys, with read/write slot locking. More...

#include <MemMap.h>

Collaboration diagram for Ipc::MemMap:
[legend]

Classes

class  Shared
 data shared across maps in different processes More...
 

Public Types

typedef MemMapSlot Slot
 
typedef Mem::Owner< SharedOwner
 

Public Member Functions

 MemMap (const char *const aPath)
 
SlotopenForWriting (const cache_key *const key, sfileno &fileno)
 
SlotopenForWritingAt (sfileno fileno, bool overwriteExisting=true)
 
void closeForWriting (const sfileno fileno)
 successfully finish writing the entry
 
void switchWritingToReading (const sfileno fileno)
 stop writing the locked entry and start reading it
 
const SlotpeekAtReader (const sfileno fileno) const
 only works on locked entries; returns nil unless the slot is readable
 
void free (const sfileno fileno)
 mark the slot as waiting to be freed and, if possible, free it
 
const SlotopenForReading (const cache_key *const key, sfileno &fileno)
 open slot for reading, increments read level
 
const SlotopenForReadingAt (const sfileno fileno)
 open slot for reading, increments read level
 
void closeForReading (const sfileno fileno)
 close slot after reading, decrements read level
 
bool full () const
 there are no empty slots left
 
bool valid (const int n) const
 whether n is a valid slot coordinate
 
int entryCount () const
 number of used slots
 
int entryLimit () const
 maximum number of slots that can be used
 
void updateStats (ReadWriteLockStats &stats) const
 adds approximate current stats to the supplied ones
 

Static Public Member Functions

static OwnerInit (const char *const path, const int limit)
 initialize shared memory
 

Public Attributes

MemMapCleanercleaner
 

Static Protected Member Functions

static OwnerInit (const char *const path, const int limit, const size_t extrasSize)
 

Protected Attributes

const SBuf path
 cache_dir path, used for logging
 
Mem::Pointer< Sharedshared
 

Private Member Functions

int slotIndexByKey (const cache_key *const key) const
 
SlotslotByKey (const cache_key *const key)
 
SlotopenForReading (Slot &s)
 
void abortWriting (const sfileno fileno)
 terminate writing the entry, freeing its slot for others to use
 
void freeIfNeeded (Slot &s)
 
void freeLocked (Slot &s, bool keepLocked)
 unconditionally frees the already exclusively locked slot and releases lock
 

Detailed Description

Definition at line 56 of file MemMap.h.

Member Typedef Documentation

◆ Owner

Definition at line 77 of file MemMap.h.

◆ Slot

Definition at line 59 of file MemMap.h.

Constructor & Destructor Documentation

◆ MemMap()

Ipc::MemMap::MemMap ( const char *const  aPath)

Definition at line 16 of file MemMap.cc.

References assert, debugs, path, and shared.

Member Function Documentation

◆ abortWriting()

void Ipc::MemMap::abortWriting ( const sfileno  fileno)
private

Definition at line 114 of file MemMap.cc.

References assert, debugs, and Ipc::MemMapSlot::writing().

◆ closeForReading()

void Ipc::MemMap::closeForReading ( const sfileno  fileno)

◆ closeForWriting()

void Ipc::MemMap::closeForWriting ( const sfileno  fileno)

◆ entryCount()

int Ipc::MemMap::entryCount ( ) const

Definition at line 224 of file MemMap.cc.

◆ entryLimit()

int Ipc::MemMap::entryLimit ( ) const

Definition at line 218 of file MemMap.cc.

◆ free()

void Ipc::MemMap::free ( const sfileno  fileno)

◆ freeIfNeeded()

void Ipc::MemMap::freeIfNeeded ( Slot s)
private

◆ freeLocked()

void Ipc::MemMap::freeLocked ( Slot s,
bool  keepLocked 
)
private

◆ full()

bool Ipc::MemMap::full ( ) const

Definition at line 230 of file MemMap.cc.

◆ Init() [1/2]

Ipc::MemMap::Owner * Ipc::MemMap::Init ( const char *const  path,
const int  limit 
)
static

Definition at line 36 of file MemMap.cc.

Referenced by SharedSessionCacheRr::create().

◆ Init() [2/2]

Ipc::MemMap::Owner * Ipc::MemMap::Init ( const char *const  path,
const int  limit,
const size_t  extrasSize 
)
staticprotected

Definition at line 27 of file MemMap.cc.

References assert, debugs, and shm_new.

◆ openForReading() [1/2]

const Ipc::MemMap::Slot * Ipc::MemMap::openForReading ( const cache_key *const  key,
sfileno fileno 
)

Definition at line 153 of file MemMap.cc.

References debugs, and storeKeyText().

Referenced by get_session_cb(), and remove_session_cb().

◆ openForReading() [2/2]

Slot * Ipc::MemMap::openForReading ( Slot s)
private

◆ openForReadingAt()

◆ openForWriting()

Ipc::MemMap::Slot * Ipc::MemMap::openForWriting ( const cache_key *const  key,
sfileno fileno 
)

finds, locks and return a slot for an empty key position, erasing the old entry (if any)

Definition at line 42 of file MemMap.cc.

References debugs, and storeKeyText().

Referenced by store_session_cb().

◆ openForWritingAt()

Ipc::MemMap::Slot * Ipc::MemMap::openForWritingAt ( sfileno  fileno,
bool  overwriteExisting = true 
)

locks and returns a slot for the empty fileno position; if overwriteExisting is false and the position is not empty, returns nil

Definition at line 57 of file MemMap.cc.

References assert, debugs, Ipc::MemMapSlot::empty(), Ipc::MemMapSlot::lock, Ipc::ReadWriteLock::lockExclusive(), Ipc::MemMapSlot::reading(), Ipc::ReadWriteLock::unlockExclusive(), Ipc::MemMapSlot::waitingToBeFreed, and Ipc::MemMapSlot::writing().

◆ peekAtReader()

const Ipc::MemMap::Slot * Ipc::MemMap::peekAtReader ( const sfileno  fileno) const

Definition at line 125 of file MemMap.cc.

References assert, Ipc::MemMapSlot::reading(), and Ipc::MemMapSlot::writing().

◆ slotByKey()

Ipc::MemMap::Slot & Ipc::MemMap::slotByKey ( const cache_key *const  key)
private

Definition at line 269 of file MemMap.cc.

◆ slotIndexByKey()

int Ipc::MemMap::slotIndexByKey ( const cache_key *const  key) const
private

Definition at line 262 of file MemMap.cc.

References hash_key(), and MEMMAP_SLOT_KEY_SIZE.

◆ switchWritingToReading()

void Ipc::MemMap::switchWritingToReading ( const sfileno  fileno)

◆ updateStats()

void Ipc::MemMap::updateStats ( ReadWriteLockStats stats) const

Definition at line 236 of file MemMap.cc.

◆ valid()

bool Ipc::MemMap::valid ( const int  n) const

Definition at line 243 of file MemMap.cc.

Member Data Documentation

◆ cleaner

MemMapCleaner* Ipc::MemMap::cleaner

The cleaner MemMapCleaner::noteFreeMapSlot method called when a readable entry is freed.

Definition at line 123 of file MemMap.h.

◆ path

const SBuf Ipc::MemMap::path
protected

Definition at line 128 of file MemMap.h.

Referenced by MemMap().

◆ shared

Mem::Pointer<Shared> Ipc::MemMap::shared
protected

Definition at line 129 of file MemMap.h.

Referenced by MemMap().


The documentation for this class was generated from the following files: