Panda3D
panda
src
gobj
simpleLru.h
1
// Filename: simpleLru.h
2
// Created by: drose (11May07)
3
//
4
////////////////////////////////////////////////////////////////////
5
//
6
// PANDA 3D SOFTWARE
7
// Copyright (c) Carnegie Mellon University. All rights reserved.
8
//
9
// All use of this software is subject to the terms of the revised BSD
10
// license. You should have received a copy of this license along
11
// with this source code in a file named "LICENSE."
12
//
13
////////////////////////////////////////////////////////////////////
14
15
#ifndef SIMPLELRU_H
16
#define SIMPLELRU_H
17
18
#include "pandabase.h"
19
#include "linkedListNode.h"
20
#include "namable.h"
21
#include "lightMutex.h"
22
#include "lightMutexHolder.h"
23
24
class
SimpleLruPage
;
25
26
////////////////////////////////////////////////////////////////////
27
// Class : SimpleLru
28
// Description : An implementation of a very simple LRU algorithm.
29
// Also see AdaptiveLru.
30
////////////////////////////////////////////////////////////////////
31
class
EXPCL_PANDA_GOBJ
SimpleLru
:
public
LinkedListNode
,
public
Namable
{
32
PUBLISHED:
33
SimpleLru
(
const
string
&name,
size_t
max_size);
34
~
SimpleLru
();
35
36
INLINE
size_t
get_total_size()
const
;
37
INLINE
size_t
get_max_size()
const
;
38
INLINE
void
set_max_size(
size_t
max_size);
39
size_t
count_active_size()
const
;
40
41
INLINE
void
consider_evict();
42
INLINE
void
evict_to(
size_t
target_size);
43
INLINE
void
begin_epoch();
44
45
INLINE
bool
validate();
46
47
void
output
(ostream &out)
const
;
48
void
write(ostream &out,
int
indent_level)
const
;
49
50
public
:
51
static
LightMutex
&_global_lock;
52
53
private
:
54
void
do_evict_to(
size_t
target_size,
bool
hard_evict);
55
bool
do_validate();
56
57
size_t
_total_size;
58
size_t
_max_size;
59
SimpleLruPage
*_active_marker;
60
61
friend
class
SimpleLruPage
;
62
};
63
64
////////////////////////////////////////////////////////////////////
65
// Class : SimpleLruPage
66
// Description : One atomic piece that may be managed by a SimpleLru
67
// chain. To use this class, inherit from it and
68
// override evict_lru().
69
////////////////////////////////////////////////////////////////////
70
class
EXPCL_PANDA_GOBJ
SimpleLruPage
:
public
LinkedListNode
{
71
PUBLISHED:
72
INLINE
SimpleLruPage
(
size_t
lru_size);
73
INLINE SimpleLruPage(
const
SimpleLruPage ©);
74
INLINE
void
operator = (
const
SimpleLruPage ©);
75
76
virtual
~SimpleLruPage();
77
78
INLINE
SimpleLru
*get_lru()
const
;
79
80
void
enqueue_lru(
SimpleLru
*lru);
81
INLINE
void
dequeue_lru();
82
83
INLINE
void
mark_used_lru()
const
;
84
INLINE
void
mark_used_lru(
SimpleLru
*lru);
85
86
INLINE
size_t
get_lru_size()
const
;
87
INLINE
void
set_lru_size(
size_t
lru_size);
88
89
virtual
void
evict_lru();
90
91
virtual
void
output(ostream &out)
const
;
92
virtual
void
write(ostream &out,
int
indent_level)
const
;
93
94
private
:
95
SimpleLru
*_lru;
96
97
size_t
_lru_size;
98
99
friend
class
SimpleLru
;
100
};
101
102
inline
ostream &operator << (ostream &out,
const
SimpleLru
&lru) {
103
lru.output(out);
104
return
out;
105
}
106
107
inline
ostream &operator << (ostream &out,
const
SimpleLruPage
&page) {
108
page.output(out);
109
return
out;
110
}
111
112
#include "simpleLru.I"
113
114
#endif
SimpleLru
An implementation of a very simple LRU algorithm.
Definition:
simpleLru.h:31
Namable::output
void output(ostream &out) const
Outputs the Namable.
Definition:
namable.I:97
LinkedListNode
This just stores the pointers to implement a doubly-linked list of some kind of object.
Definition:
linkedListNode.h:35
Namable
A base class for all things which can have a name.
Definition:
namable.h:29
SimpleLruPage
One atomic piece that may be managed by a SimpleLru chain.
Definition:
simpleLru.h:70
LightMutex
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition:
lightMutex.h:45
Generated on Wed May 17 2017 23:42:54 for Panda3D by
1.8.13