21#include <sys/resource.h>
29 getrlimit(RLIMIT_NOFILE, &rlim);
30 assert(rlim.rlim_cur > 3);
48 auto close_call = meta->m_request_close;
50 closed = close_call();
57 throw Elements::Exception() <<
"Limit reached and failed to close any existing file descriptor";
78 FileMetadata* f_ptr =
reinterpret_cast<FileMetadata*
>(id);
80 ++f_ptr->m_used_count;
intptr_t FileId
Opaque FileId, its concrete type should only be assumed to be copyable and hashable.
std::map< FileId, std::unique_ptr< FileMetadata > > m_files
unsigned getLimit() const
std::mutex m_close_fd_mutex
std::map< FileId, std::list< FileId >::iterator > m_current_pos
unsigned getAvailable() const
std::list< FileId > m_sorted_ids
Sorted from less to more recent.
void notifyClosedFile(FileId id) override
void notifyUsed(FileId id) override
LRUFileManager(unsigned limit=500)
virtual ~LRUFileManager()
void notifyOpenedFile(FileId id) override
void notifyIntentToOpen(bool write) override
T emplace_back(T... args)