14#ifndef VERTEXDATAPAGE_H
15#define VERTEXDATAPAGE_H
37class EXPCL_PANDA_GOBJ VertexDataPage :
public SimpleAllocator,
public SimpleLruPage {
39 VertexDataPage(
size_t book_size);
40 VertexDataPage(VertexDataBook *book,
size_t page_size,
size_t block_size);
41 virtual ~VertexDataPage();
62 INLINE VertexDataBook *
get_book()
const;
77 virtual void output(std::ostream &out)
const;
78 virtual void write(std::ostream &out,
int indent_level)
const;
82 INLINE
bool operator < (
const VertexDataPage &other)
const;
85 virtual SimpleAllocatorBlock *make_block(
size_t start,
size_t size);
86 virtual void changed_contiguous();
94 void make_resident_now();
96 void make_compressed();
99 bool do_save_to_disk();
100 void do_restore_from_disk();
102 void adjust_book_size();
104 void request_ram_class(RamClass ram_class);
105 INLINE
void set_ram_class(RamClass ram_class);
106 static void make_save_file();
108 INLINE
size_t round_up(
size_t page_size)
const;
109 unsigned char *alloc_page_data(
size_t page_size)
const;
110 void free_page_data(
unsigned char *page_data,
size_t page_size)
const;
114 class PageThreadManager;
115 class EXPCL_PANDA_GOBJ PageThread :
public Thread {
117 PageThread(PageThreadManager *manager,
const std::string &name);
120 virtual void thread_main();
123 PageThreadManager *_manager;
124 VertexDataPage *_working_page;
128 friend class PageThreadManager;
130 typedef pvector<PT(PageThread) > PageThreads;
132 class EXPCL_PANDA_GOBJ PageThreadManager :
public ReferenceCount {
134 PageThreadManager(
int num_threads);
137 int get_num_threads()
const;
138 int get_num_pending_reads()
const;
139 int get_num_pending_writes()
const;
140 void start_threads(
int num_threads);
144 PendingPages _pending_writes;
145 PendingPages _pending_reads;
152 PageThreads _threads;
153 friend class PageThread;
156 static PT(PageThreadManager) _thread_mgr;
157 static Mutex &_tlock;
159 unsigned char *_page_data;
160 size_t _size, _allocated_size, _uncompressed_size;
162 PT(VertexDataSaveBlock) _saved_block;
167 RamClass _pending_ram_class;
169 VertexDataBook *_book;
171 enum { deflate_page_size = 1024, inflate_page_size = 1024 };
175 class EXPCL_PANDA_GOBJ DeflatePage {
181 ALLOC_DELETED_CHAIN(DeflatePage);
183 unsigned char _buffer[deflate_page_size];
188 static TypeHandle get_class_type() {
191 static void init_type() {
196 static TypeHandle _type_handle;
199 static SimpleLru _resident_lru;
200 static SimpleLru _compressed_lru;
201 static SimpleLru _disk_lru;
202 static SimpleLru _pending_lru;
203 static SimpleLru *_global_lru[RC_end_of_list];
205 static VertexDataSaveFile *_save_file;
207 static Mutex _unused_mutex;
209 static PStatCollector _vdata_compress_pcollector;
210 static PStatCollector _vdata_decompress_pcollector;
211 static PStatCollector _vdata_save_pcollector;
212 static PStatCollector _vdata_restore_pcollector;
213 static PStatCollector _thread_wait_pcollector;
214 static PStatCollector _alloc_pages_pcollector;
217 static TypeHandle get_class_type() {
220 static void init_type() {
225 static TypeHandle _type_handle;
227 friend class PageThread;
228 friend class VertexDataBook;
231inline std::ostream &operator << (std::ostream &out,
const VertexDataPage &page) {
This class implements a condition variable; see ConditionVar for a brief introduction to this class.
A condition variable, usually used to communicate information about changing state to a thread that i...
A base class for all things that want to be reference-counted.
SimpleAllocatorBlock * get_first_block() const
Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.
SimpleAllocatorBlock * alloc(size_t size, size_t alignment=1)
Allocates a new block.
virtual void evict_lru()
Evicts the page from the LRU.
A thread; that is, a lightweight process.
A block of bytes that stores the actual raw vertex data referenced by a GeomVertexArrayData object.
A collection of VertexDataPages, which can be used to allocate new VertexDataBlock objects.
A block of bytes that holds one or more VertexDataBlocks.
void request_resident()
Ensures that the page will become resident soon.
static SimpleLru * get_pending_lru()
Returns a pointer to the global LRU object that manages the VertexDataPage's that are pending process...
static void flush_threads()
Waits for all of the pending thread tasks to finish before returning.
unsigned char * get_page_data(bool force)
Returns a pointer to the page's data area, or NULL if the page is not currently resident.
static int get_num_pending_reads()
Returns the number of read requests that are waiting to be serviced by a thread.
static void stop_threads()
Call this to stop the paging threads, if they were started.
RamClass get_pending_ram_class() const
Returns the pending ram class of the array.
static int get_num_threads()
Returns the number of threads that have been spawned to service vertex paging requests,...
bool save_to_disk()
Writes the page to disk, but does not evict it from memory or affect its LRU status.
static SimpleLru * get_global_lru(RamClass rclass)
Returns a pointer to the global LRU object that manages the VertexDataPage's with the indicated RamCl...
static int get_num_pending_writes()
Returns the number of write requests that are waiting to be serviced by a thread.
RamClass get_ram_class() const
Returns the current ram class of the array.
VertexDataBook * get_book() const
Returns a pointer to the book that owns this page.
get_save_file
Returns the global VertexDataSaveFile that will be used to save vertex data buffers to disk when nece...
A temporary file to hold the vertex data that has been evicted from memory and written to disk.
This is our own Panda specialization on the default STL deque.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.