29 SimpleLru(
const std::string &name,
size_t max_size) :
43 delete _active_marker;
50 nassertv(_next !=
nullptr);
68 if (_lru !=
nullptr) {
75 if (_lru !=
nullptr) {
77 _lru->_total_size -= _lru_size;
83 if (_lru !=
nullptr) {
84 _lru->_total_size += _lru_size;
102 while (node != _active_marker && node !=
this) {
114 output(ostream &out)
const {
116 out <<
"SimpleLru " << get_name()
117 <<
", " << _total_size <<
" of " << _max_size;
124 write(ostream &out,
int indent_level)
const {
125 indent(out, indent_level) << *
this <<
":\n";
133 while (node != _active_marker && node !=
this) {
135 indent(out, indent_level + 2) << *page <<
" (active)\n";
138 if (node == _active_marker) {
139 node = _active_marker->_prev;
140 while (node !=
this) {
142 indent(out, indent_level + 2) << *page <<
"\n";
158 do_evict_to(
size_t target_size,
bool hard_evict) {
170 while (_total_size > target_size) {
178 if (node == end || node == _prev) {
182 if (!hard_evict && node == _active_marker) {
200 while (node !=
this) {
205 return (total == _total_size);
213 if (_lru !=
nullptr) {
237 output(ostream &out)
const {
238 out <<
"page " <<
this <<
", " << _lru_size;
245 write(ostream &out,
int indent_level)
const {
246 indent(out, indent_level) << *
this <<
"\n";
An implementation of a very simple LRU algorithm.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
size_t count_active_size() const
Returns the total size of the pages that were enqueued since the last call to begin_epoch().
void enqueue_lru(SimpleLru *lru)
Adds the page to the LRU for the first time, or marks it recently-accessed if it has already been add...
void dequeue_lru()
Removes the page from its SimpleLru.
size_t get_lru_size() const
Returns the size of this page as reported to the LRU, presumably in bytes.
This just stores the pointers to implement a doubly-linked list of some kind of object.
A base class for all things which can have a name.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Similar to MutexHolder, but for a light mutex.
virtual void evict_lru()
Evicts the page from the LRU.
One atomic piece that may be managed by a SimpleLru chain.
void unlock()
Alias for release() to match C++11 semantics.
This is a standard, non-reentrant mutex, similar to the Mutex class.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void lock()
Alias for acquire() to match C++11 semantics.