need true mutexes in a few places for vertex paging

This commit is contained in:
David Rose 2008-12-31 20:22:27 +00:00
parent 2d648de716
commit 6090507c4c
12 changed files with 51 additions and 54 deletions

View File

@ -28,7 +28,7 @@
#include "cycleDataStageWriter.h"
#include "pipelineCycler.h"
#include "pmap.h"
#include "lightReMutex.h"
#include "reMutex.h"
#include "simpleLru.h"
#include "vertexDataBuffer.h"
#include "config_gobj.h"
@ -166,7 +166,7 @@ private:
// This implements read-write locking. Anyone who gets the data for
// reading or writing will hold this mutex during the lock.
LightReMutex _rw_lock;
ReMutex _rw_lock;
public:
static TypeHandle get_class_type() {

View File

@ -19,7 +19,7 @@
// Description:
////////////////////////////////////////////////////////////////////
INLINE SimpleAllocator::
SimpleAllocator(size_t max_size, LightMutex &lock) :
SimpleAllocator(size_t max_size, Mutex &lock) :
LinkedListNode(true),
_total_size(0),
_max_size(max_size),
@ -39,7 +39,7 @@ SimpleAllocator(size_t max_size, LightMutex &lock) :
////////////////////////////////////////////////////////////////////
SimpleAllocatorBlock *SimpleAllocator::
alloc(size_t size) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return do_alloc(size);
}
@ -51,7 +51,7 @@ alloc(size_t size) {
////////////////////////////////////////////////////////////////////
INLINE bool SimpleAllocator::
is_empty() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return do_is_empty();
}
@ -62,7 +62,7 @@ is_empty() const {
////////////////////////////////////////////////////////////////////
INLINE size_t SimpleAllocator::
get_total_size() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return _total_size;
}
@ -73,7 +73,7 @@ get_total_size() const {
////////////////////////////////////////////////////////////////////
INLINE size_t SimpleAllocator::
get_max_size() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return _max_size;
}
@ -86,7 +86,7 @@ get_max_size() const {
////////////////////////////////////////////////////////////////////
INLINE void SimpleAllocator::
set_max_size(size_t max_size) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
_max_size = max_size;
}
@ -102,7 +102,7 @@ set_max_size(size_t max_size) {
////////////////////////////////////////////////////////////////////
INLINE size_t SimpleAllocator::
get_contiguous() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return _contiguous;
}
@ -114,7 +114,7 @@ get_contiguous() const {
////////////////////////////////////////////////////////////////////
INLINE SimpleAllocatorBlock *SimpleAllocator::
get_first_block() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return (_next == this) ? (SimpleAllocatorBlock *)NULL : (SimpleAllocatorBlock *)_next;
}
@ -194,7 +194,7 @@ INLINE SimpleAllocatorBlock::
INLINE void SimpleAllocatorBlock::
free() {
if (_allocator != (SimpleAllocator *)NULL) {
LightMutexHolder holder(_allocator->_lock);
MutexHolder holder(_allocator->_lock);
do_free();
}
}
@ -254,7 +254,7 @@ is_free() const {
INLINE size_t SimpleAllocatorBlock::
get_max_size() const {
nassertr(_allocator != (SimpleAllocator *)NULL, 0);
LightMutexHolder holder(_allocator->_lock);
MutexHolder holder(_allocator->_lock);
return do_get_max_size();
}
@ -268,7 +268,7 @@ get_max_size() const {
INLINE bool SimpleAllocatorBlock::
realloc(size_t size) {
nassertr(_allocator != (SimpleAllocator *)NULL, false);
LightMutexHolder holder(_allocator->_lock);
MutexHolder holder(_allocator->_lock);
return do_realloc(size);
}
@ -281,7 +281,7 @@ realloc(size_t size) {
INLINE SimpleAllocatorBlock *SimpleAllocatorBlock::
get_next_block() const {
nassertr(_allocator != (SimpleAllocator *)NULL, NULL);
LightMutexHolder holder(_allocator->_lock);
MutexHolder holder(_allocator->_lock);
return (_next == _allocator) ? (SimpleAllocatorBlock *)NULL : (SimpleAllocatorBlock *)_next;
}

View File

@ -23,7 +23,7 @@ SimpleAllocator::
~SimpleAllocator() {
// We're shutting down. Force-free everything remaining.
if (_next != (LinkedListNode *)this) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
while (_next != (LinkedListNode *)this) {
nassertv(_next != (LinkedListNode *)NULL);
((SimpleAllocatorBlock *)_next)->do_free();
@ -38,7 +38,7 @@ SimpleAllocator::
////////////////////////////////////////////////////////////////////
void SimpleAllocator::
output(ostream &out) const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
out << "SimpleAllocator, " << _total_size << " of " << _max_size
<< " allocated";
}
@ -50,7 +50,7 @@ output(ostream &out) const {
////////////////////////////////////////////////////////////////////
void SimpleAllocator::
write(ostream &out) const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
out << "SimpleAllocator, " << _total_size << " of " << _max_size
<< " allocated";
@ -187,7 +187,7 @@ output(ostream &out) const {
if (_allocator == (SimpleAllocator *)NULL) {
out << "free block\n";
} else {
LightMutexHolder holder(_allocator->_lock);
MutexHolder holder(_allocator->_lock);
out << "block of size " << _size << " at " << _start;
}
}

View File

@ -17,8 +17,8 @@
#include "pandabase.h"
#include "linkedListNode.h"
#include "lightMutex.h"
#include "lightMutexHolder.h"
#include "pmutex.h"
#include "mutexHolder.h"
class SimpleAllocatorBlock;
@ -32,7 +32,7 @@ class SimpleAllocatorBlock;
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GOBJ SimpleAllocator : public LinkedListNode {
PUBLISHED:
INLINE SimpleAllocator(size_t max_size, LightMutex &lock);
INLINE SimpleAllocator(size_t max_size, Mutex &lock);
virtual ~SimpleAllocator();
INLINE SimpleAllocatorBlock *alloc(size_t size);
@ -82,7 +82,7 @@ protected:
// A derived class may also use it to protect itself as well, but
// take care to call do_alloc() instead of alloc() etc. as
// necessary.
LightMutex &_lock;
Mutex &_lock;
friend class SimpleAllocatorBlock;
};

View File

@ -21,7 +21,7 @@
////////////////////////////////////////////////////////////////////
INLINE VertexDataBlock *VertexDataBook::
alloc(size_t size) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return do_alloc(size);
}

View File

@ -13,7 +13,7 @@
////////////////////////////////////////////////////////////////////
#include "vertexDataBook.h"
#include "lightReMutexHolder.h"
#include "mutexHolder.h"
////////////////////////////////////////////////////////////////////
// Function: VertexDataBook::Constructor
@ -44,7 +44,7 @@ VertexDataBook::
////////////////////////////////////////////////////////////////////
size_t VertexDataBook::
count_total_page_size() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
size_t total = 0;
Pages::const_iterator pi;
@ -63,7 +63,7 @@ count_total_page_size() const {
////////////////////////////////////////////////////////////////////
size_t VertexDataBook::
count_total_page_size(VertexDataPage::RamClass ram_class) const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
size_t total = 0;
Pages::const_iterator pi;
@ -83,7 +83,7 @@ count_total_page_size(VertexDataPage::RamClass ram_class) const {
////////////////////////////////////////////////////////////////////
size_t VertexDataBook::
count_allocated_size() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
size_t total = 0;
Pages::const_iterator pi;
@ -102,7 +102,7 @@ count_allocated_size() const {
////////////////////////////////////////////////////////////////////
size_t VertexDataBook::
count_allocated_size(VertexDataPage::RamClass ram_class) const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
size_t total = 0;
Pages::const_iterator pi;
@ -124,7 +124,7 @@ count_allocated_size(VertexDataPage::RamClass ram_class) const {
////////////////////////////////////////////////////////////////////
void VertexDataBook::
save_to_disk() {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
Pages::iterator pi;
for (pi = _pages.begin(); pi != _pages.end(); ++pi) {

View File

@ -16,8 +16,8 @@
#define VERTEXDATABOOK_H
#include "pandabase.h"
#include "lightMutex.h"
#include "lightMutexHolder.h"
#include "pmutex.h"
#include "mutexHolder.h"
#include "vertexDataPage.h"
#include "indirectLess.h"
#include "plist.h"
@ -58,7 +58,7 @@ private:
typedef pset<VertexDataPage *, IndirectLess<VertexDataPage> > Pages;
Pages _pages;
LightMutex _lock;
Mutex _lock;
friend class VertexDataPage;
};

View File

@ -22,7 +22,7 @@
////////////////////////////////////////////////////////////////////
INLINE VertexDataPage::RamClass VertexDataPage::
get_ram_class() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return _ram_class;
}
@ -36,7 +36,7 @@ get_ram_class() const {
////////////////////////////////////////////////////////////////////
INLINE VertexDataPage::RamClass VertexDataPage::
get_pending_ram_class() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return _pending_ram_class;
}
@ -49,7 +49,7 @@ get_pending_ram_class() const {
////////////////////////////////////////////////////////////////////
INLINE void VertexDataPage::
request_resident() {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
if (_ram_class != RC_resident) {
request_ram_class(RC_resident);
}
@ -66,7 +66,7 @@ request_resident() {
////////////////////////////////////////////////////////////////////
INLINE VertexDataBlock *VertexDataPage::
alloc(size_t size) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return do_alloc(size);
}
@ -78,7 +78,7 @@ alloc(size_t size) {
////////////////////////////////////////////////////////////////////
INLINE VertexDataBlock *VertexDataPage::
get_first_block() const {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return (VertexDataBlock *)SimpleAllocator::get_first_block();
}
@ -142,7 +142,7 @@ get_save_file() {
////////////////////////////////////////////////////////////////////
INLINE bool VertexDataPage::
save_to_disk() {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
return do_save_to_disk();
}
@ -208,7 +208,7 @@ get_num_pending_writes() {
////////////////////////////////////////////////////////////////////
INLINE unsigned char *VertexDataPage::
get_page_data(bool force) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
if (_ram_class != RC_resident || _pending_ram_class != RC_resident) {
if (force) {
make_resident_now();

View File

@ -17,7 +17,6 @@
#include "vertexDataSaveFile.h"
#include "vertexDataBook.h"
#include "pStatTimer.h"
#include "lightMutexHolder.h"
#include "memoryHook.h"
#ifdef HAVE_ZLIB
@ -72,9 +71,9 @@ SimpleLru *VertexDataPage::_global_lru[RC_end_of_list] = {
VertexDataSaveFile *VertexDataPage::_save_file;
// This mutex is (mostly) unused. We just need a LightMutex to pass
// This mutex is (mostly) unused. We just need a Mutex to pass
// to the Book Constructor, below.
LightMutex VertexDataPage::_unused_mutex;
Mutex VertexDataPage::_unused_mutex;
PStatCollector VertexDataPage::_vdata_compress_pcollector("*:Vertex Data:Compress");
PStatCollector VertexDataPage::_vdata_decompress_pcollector("*:Vertex Data:Decompress");
@ -153,7 +152,7 @@ VertexDataPage::
// Since the only way to delete a page is via the
// changed_contiguous() method, the lock will already be held.
// LightMutexHolder holder(_lock);
// MutexHolder holder(_lock);
{
MutexHolder holder2(_tlock);
@ -291,7 +290,7 @@ changed_contiguous() {
////////////////////////////////////////////////////////////////////
void VertexDataPage::
evict_lru() {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
switch (_ram_class) {
case RC_resident:
@ -1041,7 +1040,7 @@ thread_main() {
_tlock.release();
{
LightMutexHolder holder(_working_page->_lock);
MutexHolder holder(_working_page->_lock);
switch (ram_class) {
case RC_resident:
_working_page->make_resident();

View File

@ -21,12 +21,10 @@
#include "pStatCollector.h"
#include "vertexDataSaveFile.h"
#include "pmutex.h"
#include "lightMutex.h"
#include "conditionVar.h"
#include "conditionVarFull.h"
#include "thread.h"
#include "mutexHolder.h"
#include "lightMutexHolder.h"
#include "pdeque.h"
class VertexDataBook;
@ -169,7 +167,7 @@ private:
size_t _book_size;
size_t _block_size;
//LightMutex _lock; // Inherited from SimpleAllocator. Protects above members.
//Mutex _lock; // Inherited from SimpleAllocator. Protects above members.
RamClass _pending_ram_class; // Protected by _tlock.
VertexDataBook *_book; // never changes.
@ -210,7 +208,7 @@ private:
static VertexDataSaveFile *_save_file;
static LightMutex _unused_mutex;
static Mutex _unused_mutex;
static PStatCollector _vdata_compress_pcollector;
static PStatCollector _vdata_decompress_pcollector;

View File

@ -13,7 +13,7 @@
////////////////////////////////////////////////////////////////////
#include "vertexDataSaveFile.h"
#include "lightMutexHolder.h"
#include "mutexHolder.h"
#include "clockObject.h"
#ifndef _WIN32
@ -192,7 +192,7 @@ VertexDataSaveFile::
////////////////////////////////////////////////////////////////////
PT(VertexDataSaveBlock) VertexDataSaveFile::
write_data(const unsigned char *data, size_t size, bool compressed) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
if (!_is_valid) {
return NULL;
@ -272,7 +272,7 @@ write_data(const unsigned char *data, size_t size, bool compressed) {
////////////////////////////////////////////////////////////////////
bool VertexDataSaveFile::
read_data(unsigned char *data, size_t size, VertexDataSaveBlock *block) {
LightMutexHolder holder(_lock);
MutexHolder holder(_lock);
if (!_is_valid) {
return false;

View File

@ -18,7 +18,7 @@
#include "pandabase.h"
#include "simpleAllocator.h"
#include "filename.h"
#include "lightMutex.h"
#include "pmutex.h"
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
@ -59,7 +59,7 @@ private:
Filename _filename;
bool _is_valid;
size_t _total_file_size;
LightMutex _lock;
Mutex _lock;
#ifdef _WIN32
HANDLE _handle;