Sirikata
|
A read-write iterator. More...
#include <CacheMap.hpp>
Public Member Functions | |
write_iterator (CacheMap &m) | |
Construct from a CacheMap (contains a scoped write lock) | |
operator bool () const | |
bool | find (const Fingerprint &id) |
Moves this iterator to id. | |
CacheData & | operator* () |
const Fingerprint & | getId () const |
cache_usize_type | getSize () const |
PolicyData | getPolicyInfo () |
void | use () |
Sets the use bit in the corresponding cache policy. | |
void | update (cache_usize_type newSize) |
Calls use(), and updates the size of this element. | |
void | erase () |
Erases the current iterator. | |
void | eraseAll () |
Iterates through the whole map, destroy()ing everything. | |
bool | insert (const Fingerprint &id, cache_usize_type size) |
Inserts a new entry into the map, unless it already exists. | |
Private Attributes | |
CacheMap * | mCachemap |
boost::unique_lock < boost::shared_mutex > | mLock |
MapClass * | mMap |
MapClass::iterator | mIter |
A read-write iterator.
Also contains insert() and erase() functions which also interact with the appropriate CachePolicy. The write_iterator aassumes exclusive ownership of the map. Since creating two write_iterators at once causes deadlock, make sure to call the alloc() function that takes a write_iterator argument if you already own one.
Sirikata::Transfer::CacheMap::write_iterator::write_iterator | ( | CacheMap & | m | ) | [inline] |
Construct from a CacheMap (contains a scoped write lock)
void Sirikata::Transfer::CacheMap::write_iterator::erase | ( | ) | [inline] |
Erases the current iterator.
Note that this iterator is invalidated at the point you erase it.
s * Also, calls CachePolicy::destroy() and CacheInfo::destroy()
References Sirikata::Transfer::CachePolicy::destroy(), Sirikata::Transfer::CacheMap::destroyCacheLayerEntry(), getId(), getPolicyInfo(), getSize(), mCachemap, mIter, mMap, and Sirikata::Transfer::CacheMap::mPolicy.
Referenced by Sirikata::Transfer::CacheMap::alloc(), Sirikata::Transfer::MemoryCacheLayer::purgeFromCache(), and Sirikata::Transfer::DiskCacheLayer::purgeFromCache().
void Sirikata::Transfer::CacheMap::write_iterator::eraseAll | ( | ) | [inline] |
Iterates through the whole map, destroy()ing everything.
Note that the write_iterator contains no iterate() method because it is generally not safe.
References Sirikata::Transfer::CachePolicy::destroy(), Sirikata::Transfer::CacheMap::destroyCacheLayerEntry(), getId(), getPolicyInfo(), getSize(), mCachemap, mIter, mMap, and Sirikata::Transfer::CacheMap::mPolicy.
Referenced by Sirikata::Transfer::CacheMap::~CacheMap().
bool Sirikata::Transfer::CacheMap::write_iterator::find | ( | const Fingerprint & | id | ) | [inline] |
Moves this iterator to id.
id | what to search for |
Referenced by Sirikata::Transfer::CacheMap::alloc(), Sirikata::Transfer::MemoryCacheLayer::purgeFromCache(), Sirikata::Transfer::DiskCacheLayer::purgeFromCache(), Sirikata::Transfer::DiskCacheLayer::unserialize(), and Sirikata::Transfer::DiskCacheLayer::workerThread().
const Fingerprint& Sirikata::Transfer::CacheMap::write_iterator::getId | ( | ) | const [inline] |
Referenced by erase(), eraseAll(), update(), and use().
PolicyData Sirikata::Transfer::CacheMap::write_iterator::getPolicyInfo | ( | ) | [inline] |
Referenced by erase(), eraseAll(), update(), and use().
cache_usize_type Sirikata::Transfer::CacheMap::write_iterator::getSize | ( | ) | const [inline] |
Referenced by erase(), eraseAll(), update(), and use().
bool Sirikata::Transfer::CacheMap::write_iterator::insert | ( | const Fingerprint & | id, |
cache_usize_type | size | ||
) | [inline] |
Inserts a new entry into the map, unless it already exists.
Follows the semantics of std::map::insert(id).
The iterator is guaranteed to be valid after this call.
id | The Fingerprint to insert under (or search for). |
size | The amount of space reserved for this entry--used only if the entry did not exist before. |
References Sirikata::Transfer::CachePolicy::create(), mCachemap, mIter, mMap, and Sirikata::Transfer::CacheMap::mPolicy.
Referenced by Sirikata::Transfer::MemoryCacheLayer::populateCache(), Sirikata::Transfer::DiskCacheLayer::unserialize(), and Sirikata::Transfer::DiskCacheLayer::workerThread().
Sirikata::Transfer::CacheMap::write_iterator::operator bool | ( | ) | const [inline] |
CacheData& Sirikata::Transfer::CacheMap::write_iterator::operator* | ( | ) | [inline] |
void Sirikata::Transfer::CacheMap::write_iterator::update | ( | cache_usize_type | newSize | ) | [inline] |
Calls use(), and updates the size of this element.
This function has no other effect if the size is unchanged.
newSize | The new total size of this element. |
References getId(), getPolicyInfo(), getSize(), mCachemap, Sirikata::Transfer::CacheMap::mPolicy, and Sirikata::Transfer::CachePolicy::useAndUpdate().
Referenced by Sirikata::Transfer::MemoryCacheLayer::populateCache(), and Sirikata::Transfer::DiskCacheLayer::workerThread().
void Sirikata::Transfer::CacheMap::write_iterator::use | ( | ) | [inline] |
Sets the use bit in the corresponding cache policy.
References getId(), getPolicyInfo(), getSize(), mCachemap, Sirikata::Transfer::CacheMap::mPolicy, and Sirikata::Transfer::CachePolicy::use().
Referenced by Sirikata::Transfer::MemoryCacheLayer::populateCache(), Sirikata::Transfer::DiskCacheLayer::unserialize(), and Sirikata::Transfer::DiskCacheLayer::workerThread().
Referenced by erase(), eraseAll(), insert(), update(), and use().
MapClass::iterator Sirikata::Transfer::CacheMap::write_iterator::mIter [private] |
Referenced by erase(), eraseAll(), find(), insert(), and operator bool().
boost::unique_lock<boost::shared_mutex> Sirikata::Transfer::CacheMap::write_iterator::mLock [private] |
Referenced by erase(), eraseAll(), find(), insert(), and operator bool().