15 #ifndef VERTEXDATAPAGE_H
16 #define VERTEXDATAPAGE_H
18 #include "pandabase.h"
19 #include "simpleLru.h"
20 #include "simpleAllocator.h"
21 #include "pStatCollector.h"
22 #include "vertexDataSaveFile.h"
24 #include "conditionVar.h"
25 #include "conditionVarFull.h"
27 #include "mutexHolder.h"
58 INLINE RamClass get_ram_class()
const;
59 INLINE RamClass get_pending_ram_class()
const;
60 INLINE
void request_resident();
67 INLINE
static SimpleLru *get_global_lru(RamClass rclass);
68 INLINE
static SimpleLru *get_pending_lru();
71 INLINE
bool save_to_disk();
73 INLINE
static int get_num_threads();
74 INLINE
static int get_num_pending_reads();
75 INLINE
static int get_num_pending_writes();
76 static void stop_threads();
77 static void flush_threads();
79 virtual void output(ostream &out)
const;
80 virtual void write(ostream &out,
int indent_level)
const;
83 INLINE
unsigned char *get_page_data(
bool force);
88 virtual void changed_contiguous();
96 void make_resident_now();
98 void make_compressed();
101 bool do_save_to_disk();
102 void do_restore_from_disk();
104 void adjust_book_size();
106 void request_ram_class(RamClass ram_class);
107 INLINE
void set_ram_class(RamClass ram_class);
108 static void make_save_file();
110 INLINE
size_t round_up(
size_t page_size)
const;
111 unsigned char *alloc_page_data(
size_t page_size)
const;
112 void free_page_data(
unsigned char *page_data,
size_t page_size)
const;
116 class PageThreadManager;
117 class EXPCL_PANDA_GOBJ PageThread :
public Thread {
119 PageThread(PageThreadManager *manager,
const string &name);
122 virtual void thread_main();
125 PageThreadManager *_manager;
131 friend class PageThreadManager;
135 class EXPCL_PANDA_GOBJ PageThreadManager :
public ReferenceCount {
137 PageThreadManager(
int num_threads);
140 int get_num_threads()
const;
141 int get_num_pending_reads()
const;
142 int get_num_pending_writes()
const;
143 void start_threads(
int num_threads);
157 friend class PageThread;
160 static PT(PageThreadManager) _thread_mgr;
161 static Mutex &_tlock;
163 unsigned char *_page_data;
164 size_t _size, _allocated_size, _uncompressed_size;
171 RamClass _pending_ram_class;
175 enum { deflate_page_size = 1024, inflate_page_size = 1024 };
179 class EXPCL_PANDA_GOBJ DeflatePage {
185 ALLOC_DELETED_CHAIN(DeflatePage);
187 unsigned char _buffer[deflate_page_size];
195 static void init_type() {
196 register_type(_type_handle,
"VertexDataPage::DeflatePage");
207 static SimpleLru *_global_lru[RC_end_of_list];
211 static Mutex _unused_mutex;
224 static void init_type() {
225 register_type(_type_handle,
"VertexDataPage");
231 friend class PageThread;
235 inline ostream &operator << (ostream &out,
const VertexDataPage &page) {
240 #include "vertexDataPage.I"
A block of bytes on the save file.
An implementation of a very simple LRU algorithm.
A block of bytes that holds one or more VertexDataBlocks.
A temporary file to hold the vertex data that has been evicted from memory and written to disk...
An implementation of a very simple block allocator.
SimpleAllocatorBlock * alloc(size_t size)
Allocates a new block.
SimpleAllocatorBlock * get_first_block() const
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks...
A standard mutex, or mutual exclusion lock.
A condition variable, usually used to communicate information about changing state to a thread that i...
A block of bytes that stores the actual raw vertex data referenced by a GeomVertexArrayData object...
A single block as returned from SimpleAllocator::alloc().
A lightweight class that represents a single element that may be timed and/or counted via stats...
virtual void evict_lru()
Evicts the page from the LRU.
One atomic piece that may be managed by a SimpleLru chain.
A collection of VertexDataPages, which can be used to allocate new VertexDataBlock objects...
A base class for all things that want to be reference-counted.
This class implements a condition variable; see ConditionVar for a brief introduction to this class...
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.