mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
fix race condition
This commit is contained in:
parent
38d262b7ba
commit
9087b030a9
@ -27,6 +27,7 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_active(bool active) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_active = active;
|
||||
}
|
||||
|
||||
@ -45,6 +46,7 @@ set_active(bool active) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool BamCache::
|
||||
get_active() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _active;
|
||||
}
|
||||
|
||||
@ -56,6 +58,7 @@ get_active() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_cache_models(bool flag) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_cache_models = flag;
|
||||
}
|
||||
|
||||
@ -69,6 +72,7 @@ set_cache_models(bool flag) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool BamCache::
|
||||
get_cache_models() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _cache_models && _active;
|
||||
}
|
||||
|
||||
@ -80,6 +84,7 @@ get_cache_models() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_cache_textures(bool flag) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_cache_textures = flag;
|
||||
}
|
||||
|
||||
@ -93,6 +98,7 @@ set_cache_textures(bool flag) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool BamCache::
|
||||
get_cache_textures() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _cache_textures && _active;
|
||||
}
|
||||
|
||||
@ -117,6 +123,7 @@ get_cache_textures() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_cache_compressed_textures(bool flag) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_cache_compressed_textures = flag;
|
||||
}
|
||||
|
||||
@ -131,6 +138,7 @@ set_cache_compressed_textures(bool flag) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool BamCache::
|
||||
get_cache_compressed_textures() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _cache_compressed_textures && _active;
|
||||
}
|
||||
|
||||
@ -140,8 +148,9 @@ get_cache_compressed_textures() const {
|
||||
// Description: Returns the current root pathname of the cache. See
|
||||
// set_root().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &BamCache::
|
||||
INLINE Filename BamCache::
|
||||
get_root() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _root;
|
||||
}
|
||||
|
||||
@ -153,6 +162,7 @@ get_root() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_flush_time(int flush_time) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_flush_time = flush_time;
|
||||
}
|
||||
|
||||
@ -164,6 +174,7 @@ set_flush_time(int flush_time) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int BamCache::
|
||||
get_flush_time() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _flush_time;
|
||||
}
|
||||
|
||||
@ -183,6 +194,7 @@ get_flush_time() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_cache_max_kbytes(int max_kbytes) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_max_kbytes = max_kbytes;
|
||||
check_cache_size();
|
||||
}
|
||||
@ -196,6 +208,7 @@ set_cache_max_kbytes(int max_kbytes) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE int BamCache::
|
||||
get_cache_max_kbytes() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _max_kbytes;
|
||||
}
|
||||
|
||||
@ -210,6 +223,7 @@ get_cache_max_kbytes() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void BamCache::
|
||||
set_read_only(bool ro) {
|
||||
ReMutexHolder holder(_lock);
|
||||
_read_only = ro;
|
||||
}
|
||||
|
||||
@ -224,6 +238,7 @@ set_read_only(bool ro) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool BamCache::
|
||||
get_read_only() const {
|
||||
ReMutexHolder holder(_lock);
|
||||
return _read_only;
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,7 @@ BamCache::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void BamCache::
|
||||
set_root(const Filename &root) {
|
||||
ReMutexHolder holder(_lock);
|
||||
flush_index();
|
||||
_root = root;
|
||||
|
||||
@ -159,6 +160,7 @@ set_root(const Filename &root) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(BamCacheRecord) BamCache::
|
||||
lookup(const Filename &source_filename, const string &cache_extension) {
|
||||
ReMutexHolder holder(_lock);
|
||||
consider_flush_index();
|
||||
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
@ -191,6 +193,7 @@ lookup(const Filename &source_filename, const string &cache_extension) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool BamCache::
|
||||
store(BamCacheRecord *record) {
|
||||
ReMutexHolder holder(_lock);
|
||||
nassertr(!record->_cache_pathname.empty(), false);
|
||||
nassertr(record->has_data(), false);
|
||||
|
||||
@ -320,6 +323,7 @@ emergency_read_only() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void BamCache::
|
||||
consider_flush_index() {
|
||||
ReMutexHolder holder(_lock);
|
||||
if (_index_stale_since != 0) {
|
||||
int elapsed = (int)time(NULL) - (int)_index_stale_since;
|
||||
if (elapsed > _flush_time) {
|
||||
@ -335,6 +339,7 @@ consider_flush_index() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void BamCache::
|
||||
flush_index() {
|
||||
ReMutexHolder holder(_lock);
|
||||
if (_index_stale_since == 0) {
|
||||
// Never mind.
|
||||
return;
|
||||
@ -991,7 +996,7 @@ void BamCache::
|
||||
make_global() {
|
||||
_global_ptr = new BamCache;
|
||||
|
||||
if (_global_ptr->get_root().empty()) {
|
||||
if (_global_ptr->_root.empty()) {
|
||||
_global_ptr->set_active(false);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "filename.h"
|
||||
#include "pmap.h"
|
||||
#include "pvector.h"
|
||||
#include "reMutex.h"
|
||||
#include "reMutexHolder.h"
|
||||
|
||||
class BamCacheIndex;
|
||||
|
||||
@ -58,7 +60,7 @@ PUBLISHED:
|
||||
INLINE bool get_cache_compressed_textures() const;
|
||||
|
||||
void set_root(const Filename &root);
|
||||
INLINE const Filename &get_root() const;
|
||||
INLINE Filename get_root() const;
|
||||
|
||||
INLINE void set_flush_time(int flush_time);
|
||||
INLINE int get_flush_time() const;
|
||||
@ -122,6 +124,8 @@ private:
|
||||
|
||||
Filename _index_pathname;
|
||||
string _index_ref_contents;
|
||||
|
||||
ReMutex _lock;
|
||||
};
|
||||
|
||||
#include "bamCache.I"
|
||||
|
Loading…
x
Reference in New Issue
Block a user