Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Euclid::FilePool::LRUFileManager Class Referencefinal

#include <LRUFileManager.h>

Inheritance diagram for Euclid::FilePool::LRUFileManager:
Inheritance graph
[legend]
Collaboration diagram for Euclid::FilePool::LRUFileManager:
Collaboration graph
[legend]

Public Member Functions

 LRUFileManager (unsigned limit=500)
 
virtual ~LRUFileManager ()
 
void notifyUsed (FileId id) override
 
unsigned getLimit () const
 
unsigned getUsed () const
 
unsigned getAvailable () const
 
- Public Member Functions inherited from Euclid::FilePool::FileManager
 FileManager ()
 Constructor.
 
virtual ~FileManager ()
 Destructor.
 
std::shared_ptr< FileHandlergetFileHandler (const boost::filesystem::path &path)
 
template<typename TFD >
std::pair< FileId, TFD > open (const boost::filesystem::path &path, bool write, std::function< bool(FileId)> request_close)
 
template<typename TFD >
void close (FileId id, TFD &fd)
 
void closeAll ()
 
bool hasHandler (const boost::filesystem::path &path) const
 
- Public Member Functions inherited from std::enable_shared_from_this< FileManager >
enable_shared_from_this (T... args)
 
operator= (T... args)
 
shared_from_this (T... args)
 
~enable_shared_from_this (T... args)
 

Protected Member Functions

void notifyIntentToOpen (bool write) override
 
void notifyOpenedFile (FileId id) override
 
void notifyClosedFile (FileId id) override
 

Private Attributes

unsigned m_limit
 
std::mutex m_close_fd_mutex
 
std::list< FileIdm_sorted_ids
 Sorted from less to more recent.
 
std::map< FileId, std::list< FileId >::iterator > m_current_pos
 

Additional Inherited Members

- Public Types inherited from Euclid::FilePool::FileManager
using FileId = intptr_t
 Opaque FileId, its concrete type should only be assumed to be copyable and hashable.
 
- Static Public Member Functions inherited from Euclid::FilePool::FileManager
static std::shared_ptr< FileManagergetDefault ()
 
- Protected Types inherited from Euclid::FilePool::FileManager
using Clock = std::chrono::steady_clock
 
using Timestamp = Clock::time_point
 
- Protected Attributes inherited from Euclid::FilePool::FileManager
std::mutex m_mutex
 
std::map< boost::filesystem::path, std::weak_ptr< FileHandler > > m_handlers
 
std::map< FileId, std::unique_ptr< FileMetadata > > m_files
 

Detailed Description

Least Recently Used strategy for the FileManager

Definition at line 30 of file LRUFileManager.h.

Constructor & Destructor Documentation

◆ LRUFileManager()

Euclid::FilePool::LRUFileManager::LRUFileManager ( unsigned  limit = 500)
explicit

Constructor

Parameters
limitLimit on the number of open files. If 0, it will query the system to obtain the configured limit.

Definition at line 26 of file LRUFileManager.cpp.

References m_limit.

◆ ~LRUFileManager()

Euclid::FilePool::LRUFileManager::~LRUFileManager ( )
virtual

Definition at line 35 of file LRUFileManager.cpp.

References Euclid::FilePool::FileManager::closeAll().

Here is the call graph for this function:

Member Function Documentation

◆ getAvailable()

unsigned int Euclid::FilePool::LRUFileManager::getAvailable ( ) const

Definition at line 100 of file LRUFileManager.cpp.

References m_limit, m_sorted_ids, and std::list< T >::size().

Here is the call graph for this function:

◆ getLimit()

unsigned int Euclid::FilePool::LRUFileManager::getLimit ( ) const

Definition at line 92 of file LRUFileManager.cpp.

References m_limit.

◆ getUsed()

unsigned int Euclid::FilePool::LRUFileManager::getUsed ( ) const

Definition at line 96 of file LRUFileManager.cpp.

References m_sorted_ids, and std::list< T >::size().

Here is the call graph for this function:

◆ notifyClosedFile()

void Euclid::FilePool::LRUFileManager::notifyClosedFile ( FileManager::FileId  id)
overrideprotectedvirtual

Implements Euclid::FilePool::FileManager.

Definition at line 69 of file LRUFileManager.cpp.

References std::list< T >::erase(), std::map< K, T >::erase(), m_current_pos, Euclid::FilePool::FileManager::m_mutex, and m_sorted_ids.

Here is the call graph for this function:

◆ notifyIntentToOpen()

void Euclid::FilePool::LRUFileManager::notifyIntentToOpen ( bool  write)
overrideprotectedvirtual

◆ notifyOpenedFile()

void Euclid::FilePool::LRUFileManager::notifyOpenedFile ( FileManager::FileId  id)
overrideprotectedvirtual

Implements Euclid::FilePool::FileManager.

Definition at line 62 of file LRUFileManager.cpp.

References std::list< T >::emplace_back(), std::list< T >::end(), m_current_pos, Euclid::FilePool::FileManager::m_mutex, and m_sorted_ids.

Here is the call graph for this function:

◆ notifyUsed()

void Euclid::FilePool::LRUFileManager::notifyUsed ( FileManager::FileId  id)
overridevirtual

Notify that the given file has been/is going to be used. This will update the book-keeping data used to decide what to close when.

Reimplemented from Euclid::FilePool::FileManager.

Definition at line 76 of file LRUFileManager.cpp.

References std::list< T >::emplace_back(), std::list< T >::end(), std::list< T >::erase(), m_current_pos, Euclid::FilePool::FileManager::m_mutex, m_sorted_ids, std::move(), and std::chrono::steady_clock::now().

Here is the call graph for this function:

Member Data Documentation

◆ m_close_fd_mutex

std::mutex Euclid::FilePool::LRUFileManager::m_close_fd_mutex
private

Definition at line 53 of file LRUFileManager.h.

Referenced by notifyIntentToOpen().

◆ m_current_pos

std::map<FileId, std::list<FileId>::iterator> Euclid::FilePool::LRUFileManager::m_current_pos
private

Definition at line 56 of file LRUFileManager.h.

Referenced by notifyClosedFile(), notifyOpenedFile(), and notifyUsed().

◆ m_limit

unsigned Euclid::FilePool::LRUFileManager::m_limit
private

Definition at line 52 of file LRUFileManager.h.

Referenced by getAvailable(), getLimit(), LRUFileManager(), and notifyIntentToOpen().

◆ m_sorted_ids

std::list<FileId> Euclid::FilePool::LRUFileManager::m_sorted_ids
private

Sorted from less to more recent.

Definition at line 55 of file LRUFileManager.h.

Referenced by getAvailable(), getUsed(), notifyClosedFile(), notifyIntentToOpen(), notifyOpenedFile(), and notifyUsed().


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