general: switch to C++11 Lockable semantics for mutexes
This renames acquire/release to lock/unlock in order to be compatible with std::lock_guard and std::unique_lock (which will eventually replace the *MutexHolder classes). It will also allow us to typedef MutexImpl to std::mutex later on.
This commit is contained in:
parent
3653413cd4
commit
f45ddcab2f
|
|
@ -43,11 +43,11 @@ allocate(size_t size, TypeHandle type_handle) {
|
|||
|
||||
ObjectNode *obj;
|
||||
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
if (_deleted_chain != (ObjectNode *)NULL) {
|
||||
obj = _deleted_chain;
|
||||
_deleted_chain = _deleted_chain->_next;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
#ifdef USE_DELETEDCHAINFLAG
|
||||
assert(obj->_flag == (AtomicAdjust::Integer)DCF_deleted);
|
||||
|
|
@ -64,7 +64,7 @@ allocate(size_t size, TypeHandle type_handle) {
|
|||
|
||||
return ptr;
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
// If we get here, the deleted_chain is empty; we have to allocate a new
|
||||
// object from the system pool.
|
||||
|
|
@ -126,12 +126,12 @@ deallocate(void *ptr, TypeHandle type_handle) {
|
|||
assert(orig_flag == (AtomicAdjust::Integer)DCF_alive);
|
||||
#endif // USE_DELETEDCHAINFLAG
|
||||
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
obj->_next = _deleted_chain;
|
||||
_deleted_chain = obj;
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
#else // USE_DELETED_CHAIN
|
||||
PANDA_FREE_SINGLE(ptr);
|
||||
|
|
|
|||
|
|
@ -223,9 +223,9 @@ MemoryHook(const MemoryHook ©) :
|
|||
_total_mmap_size(copy._total_mmap_size),
|
||||
_max_heap_size(copy._max_heap_size) {
|
||||
|
||||
copy._lock.acquire();
|
||||
copy._lock.lock();
|
||||
_deleted_chains = copy._deleted_chains;
|
||||
copy._lock.release();
|
||||
copy._lock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -249,9 +249,9 @@ heap_alloc_single(size_t size) {
|
|||
size_t inflated_size = inflate_size(size);
|
||||
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
void *alloc = call_malloc(inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
void *alloc = call_malloc(inflated_size);
|
||||
#endif
|
||||
|
|
@ -259,9 +259,9 @@ heap_alloc_single(size_t size) {
|
|||
while (alloc == (void *)NULL) {
|
||||
alloc_fail(inflated_size);
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
alloc = call_malloc(inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
alloc = call_malloc(inflated_size);
|
||||
#endif
|
||||
|
|
@ -305,9 +305,9 @@ heap_free_single(void *ptr) {
|
|||
#endif // DO_MEMORY_USAGE
|
||||
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
call_free(alloc);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
call_free(alloc);
|
||||
#endif
|
||||
|
|
@ -326,9 +326,9 @@ heap_alloc_array(size_t size) {
|
|||
size_t inflated_size = inflate_size(size);
|
||||
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
void *alloc = call_malloc(inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
void *alloc = call_malloc(inflated_size);
|
||||
#endif
|
||||
|
|
@ -336,9 +336,9 @@ heap_alloc_array(size_t size) {
|
|||
while (alloc == (void *)NULL) {
|
||||
alloc_fail(inflated_size);
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
alloc = call_malloc(inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
alloc = call_malloc(inflated_size);
|
||||
#endif
|
||||
|
|
@ -380,9 +380,9 @@ heap_realloc_array(void *ptr, size_t size) {
|
|||
|
||||
void *alloc1 = alloc;
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
alloc1 = call_realloc(alloc1, inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
alloc1 = call_realloc(alloc1, inflated_size);
|
||||
#endif
|
||||
|
|
@ -394,9 +394,9 @@ heap_realloc_array(void *ptr, size_t size) {
|
|||
alloc1 = alloc;
|
||||
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
alloc1 = call_realloc(alloc1, inflated_size);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
alloc1 = call_realloc(alloc1, inflated_size);
|
||||
#endif
|
||||
|
|
@ -453,9 +453,9 @@ heap_free_array(void *ptr) {
|
|||
#endif // DO_MEMORY_USAGE
|
||||
|
||||
#ifdef MEMORY_HOOK_MALLOC_LOCK
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
call_free(alloc);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#else
|
||||
call_free(alloc);
|
||||
#endif
|
||||
|
|
@ -478,11 +478,11 @@ heap_trim(size_t pad) {
|
|||
// Since malloc_trim() isn't standard C, we can't be sure it exists on a
|
||||
// given platform. But if we're using dlmalloc, we know we have
|
||||
// dlmalloc_trim.
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
if (dlmalloc_trim(pad)) {
|
||||
trimmed = true;
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
@ -596,7 +596,7 @@ DeletedBufferChain *MemoryHook::
|
|||
get_deleted_chain(size_t buffer_size) {
|
||||
DeletedBufferChain *chain;
|
||||
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
DeletedChains::iterator dci = _deleted_chains.find(buffer_size);
|
||||
if (dci != _deleted_chains.end()) {
|
||||
chain = (*dci).second;
|
||||
|
|
@ -606,7 +606,7 @@ get_deleted_chain(size_t buffer_size) {
|
|||
_deleted_chains.insert(DeletedChains::value_type(buffer_size, chain));
|
||||
}
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return chain;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@
|
|||
*
|
||||
*/
|
||||
ALWAYS_INLINE void MutexDummyImpl::
|
||||
acquire() {
|
||||
lock() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ALWAYS_INLINE bool MutexDummyImpl::
|
||||
try_acquire() {
|
||||
try_lock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -30,5 +30,5 @@ try_acquire() {
|
|||
*
|
||||
*/
|
||||
ALWAYS_INLINE void MutexDummyImpl::
|
||||
release() {
|
||||
unlock() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ private:
|
|||
MutexDummyImpl &operator = (const MutexDummyImpl ©) DELETED_ASSIGN;
|
||||
|
||||
public:
|
||||
ALWAYS_INLINE void acquire();
|
||||
ALWAYS_INLINE bool try_acquire();
|
||||
ALWAYS_INLINE void release();
|
||||
ALWAYS_INLINE void lock();
|
||||
ALWAYS_INLINE bool try_lock();
|
||||
ALWAYS_INLINE void unlock();
|
||||
};
|
||||
|
||||
#include "mutexDummyImpl.I"
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ INLINE MutexPosixImpl::
|
|||
*
|
||||
*/
|
||||
INLINE void MutexPosixImpl::
|
||||
acquire() {
|
||||
TAU_PROFILE("void MutexPosixImpl::acquire", " ", TAU_USER);
|
||||
lock() {
|
||||
TAU_PROFILE("void MutexPosixImpl::lock", " ", TAU_USER);
|
||||
int result = pthread_mutex_lock(&_lock);
|
||||
assert(result == 0);
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE bool MutexPosixImpl::
|
||||
try_acquire() {
|
||||
TAU_PROFILE("bool MutexPosixImpl::try_acquire", " ", TAU_USER);
|
||||
try_lock() {
|
||||
TAU_PROFILE("bool MutexPosixImpl::try_lock", " ", TAU_USER);
|
||||
int result = pthread_mutex_trylock(&_lock);
|
||||
assert(result == 0 || result == EBUSY);
|
||||
return (result == 0);
|
||||
|
|
@ -53,20 +53,12 @@ try_acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE void MutexPosixImpl::
|
||||
release() {
|
||||
TAU_PROFILE("void MutexPosixImpl::release", " ", TAU_USER);
|
||||
unlock() {
|
||||
TAU_PROFILE("void MutexPosixImpl::unlock", " ", TAU_USER);
|
||||
int result = pthread_mutex_unlock(&_lock);
|
||||
assert(result == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying Posix lock handle.
|
||||
*/
|
||||
INLINE pthread_mutex_t *MutexPosixImpl::
|
||||
get_posix_lock() {
|
||||
return &_lock;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -101,8 +93,8 @@ INLINE ReMutexPosixImpl::
|
|||
*
|
||||
*/
|
||||
INLINE void ReMutexPosixImpl::
|
||||
acquire() {
|
||||
TAU_PROFILE("void ReMutexPosixImpl::acquire", " ", TAU_USER);
|
||||
lock() {
|
||||
TAU_PROFILE("void ReMutexPosixImpl::lock", " ", TAU_USER);
|
||||
int result = pthread_mutex_lock(&_lock);
|
||||
assert(result == 0);
|
||||
}
|
||||
|
|
@ -111,8 +103,8 @@ acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE bool ReMutexPosixImpl::
|
||||
try_acquire() {
|
||||
TAU_PROFILE("bool ReMutexPosixImpl::try_acquire", " ", TAU_USER);
|
||||
try_lock() {
|
||||
TAU_PROFILE("bool ReMutexPosixImpl::try_lock", " ", TAU_USER);
|
||||
int result = pthread_mutex_trylock(&_lock);
|
||||
assert(result == 0 || result == EBUSY);
|
||||
return (result == 0);
|
||||
|
|
@ -122,16 +114,8 @@ try_acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE void ReMutexPosixImpl::
|
||||
release() {
|
||||
TAU_PROFILE("void ReMutexPosixImpl::release", " ", TAU_USER);
|
||||
unlock() {
|
||||
TAU_PROFILE("void ReMutexPosixImpl::unlock", " ", TAU_USER);
|
||||
int result = pthread_mutex_unlock(&_lock);
|
||||
assert(result == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying Posix lock handle.
|
||||
*/
|
||||
INLINE pthread_mutex_t *ReMutexPosixImpl::
|
||||
get_posix_lock() {
|
||||
return &_lock;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,9 @@ private:
|
|||
MutexPosixImpl &operator = (const MutexPosixImpl ©) DELETED_ASSIGN;
|
||||
|
||||
public:
|
||||
INLINE void acquire();
|
||||
INLINE bool try_acquire();
|
||||
INLINE void release();
|
||||
|
||||
INLINE pthread_mutex_t *get_posix_lock();
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
private:
|
||||
pthread_mutex_t _lock;
|
||||
|
|
@ -64,11 +62,9 @@ private:
|
|||
ReMutexPosixImpl &operator = (const ReMutexPosixImpl ©) DELETED;
|
||||
|
||||
public:
|
||||
INLINE void acquire();
|
||||
INLINE bool try_acquire();
|
||||
INLINE void release();
|
||||
|
||||
INLINE pthread_mutex_t *get_posix_lock();
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
private:
|
||||
pthread_mutex_t _lock;
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ MutexSpinlockImpl() : _lock(0) {
|
|||
*
|
||||
*/
|
||||
INLINE void MutexSpinlockImpl::
|
||||
acquire() {
|
||||
if (!try_acquire()) {
|
||||
lock() {
|
||||
if (!try_lock()) {
|
||||
do_lock();
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE bool MutexSpinlockImpl::
|
||||
try_acquire() {
|
||||
try_lock() {
|
||||
return (AtomicAdjust::compare_and_exchange(_lock, 0, 1) == 0);
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +40,6 @@ try_acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE void MutexSpinlockImpl::
|
||||
release() {
|
||||
unlock() {
|
||||
AtomicAdjust::set(_lock, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ private:
|
|||
MutexSpinlockImpl &operator = (const MutexSpinlockImpl ©) DELETED_ASSIGN;
|
||||
|
||||
public:
|
||||
INLINE void acquire();
|
||||
INLINE bool try_acquire();
|
||||
INLINE void release();
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
private:
|
||||
void do_lock();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ INLINE MutexWin32Impl::
|
|||
*
|
||||
*/
|
||||
INLINE void MutexWin32Impl::
|
||||
acquire() {
|
||||
lock() {
|
||||
EnterCriticalSection(&_lock);
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE bool MutexWin32Impl::
|
||||
try_acquire() {
|
||||
try_lock() {
|
||||
return (TryEnterCriticalSection(&_lock) != 0);
|
||||
}
|
||||
|
||||
|
|
@ -39,6 +39,6 @@ try_acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE void MutexWin32Impl::
|
||||
release() {
|
||||
unlock() {
|
||||
LeaveCriticalSection(&_lock);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ private:
|
|||
MutexWin32Impl &operator = (const MutexWin32Impl ©) DELETED_ASSIGN;
|
||||
|
||||
public:
|
||||
INLINE void acquire();
|
||||
INLINE bool try_acquire();
|
||||
INLINE void release();
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
private:
|
||||
CRITICAL_SECTION _lock;
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ get_total_used() {
|
|||
INLINE size_t NeverFreeMemory::
|
||||
get_total_unused() {
|
||||
NeverFreeMemory *global_ptr = get_global_ptr();
|
||||
global_ptr->_lock.acquire();
|
||||
global_ptr->_lock.lock();
|
||||
size_t total_unused = global_ptr->_total_alloc - global_ptr->_total_used;
|
||||
global_ptr->_lock.release();
|
||||
global_ptr->_lock.unlock();
|
||||
return total_unused;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ NeverFreeMemory() {
|
|||
*/
|
||||
void *NeverFreeMemory::
|
||||
ns_alloc(size_t size) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
//NB: we no longer do alignment here. The only class that uses this is
|
||||
// DeletedBufferChain, and we can do the alignment potentially more
|
||||
|
|
@ -55,7 +55,7 @@ ns_alloc(size_t size) {
|
|||
if (page._remaining >= min_page_remaining_size) {
|
||||
_pages.insert(page);
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ ns_alloc(size_t size) {
|
|||
if (page._remaining >= min_page_remaining_size) {
|
||||
_pages.insert(page);
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ TypeRegistry *TypeRegistry::_global_pointer = NULL;
|
|||
*/
|
||||
bool TypeRegistry::
|
||||
register_type(TypeHandle &type_handle, const string &name) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
if (type_handle != TypeHandle::none()) {
|
||||
// Here's a type that was already registered. Just make sure everything's
|
||||
|
|
@ -40,7 +40,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
TypeRegistryNode *rnode = look_up(type_handle, NULL);
|
||||
if (&type_handle == &rnode->_ref) {
|
||||
// No problem.
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
assert(rnode->_name == name);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
_derivations_fresh = false;
|
||||
|
||||
type_handle = new_handle;
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return true;
|
||||
}
|
||||
TypeRegistryNode *rnode = (*ri).second;
|
||||
|
|
@ -78,7 +78,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
|
||||
if (type_handle == rnode->_handle) {
|
||||
// No problem.
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return false;
|
||||
}
|
||||
// But wait--the type_handle has changed! We kept a reference to the
|
||||
|
|
@ -87,7 +87,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
// time, but now it's different! Bad juju.
|
||||
cerr << "Reregistering " << name << "\n";
|
||||
type_handle = rnode->_handle;
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
|
||||
type_handle = rnode->_handle;
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ register_type(TypeHandle &type_handle, const string &name) {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
register_dynamic_type(const string &name) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
NameRegistry::iterator ri;
|
||||
ri = _name_registry.find(name);
|
||||
|
|
@ -134,14 +134,14 @@ register_dynamic_type(const string &name) {
|
|||
_name_registry[name] = rnode;
|
||||
_derivations_fresh = false;
|
||||
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return *new_handle;
|
||||
}
|
||||
|
||||
// Return the TypeHandle previously obtained.
|
||||
TypeRegistryNode *rnode = (*ri).second;
|
||||
TypeHandle handle = rnode->_handle;
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ register_dynamic_type(const string &name) {
|
|||
*/
|
||||
void TypeRegistry::
|
||||
record_derivation(TypeHandle child, TypeHandle parent) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
TypeRegistryNode *cnode = look_up(child, NULL);
|
||||
assert(cnode != (TypeRegistryNode *)NULL);
|
||||
|
|
@ -171,7 +171,7 @@ record_derivation(TypeHandle child, TypeHandle parent) {
|
|||
_derivations_fresh = false;
|
||||
}
|
||||
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -182,7 +182,7 @@ record_derivation(TypeHandle child, TypeHandle parent) {
|
|||
*/
|
||||
void TypeRegistry::
|
||||
record_alternate_name(TypeHandle type, const string &name) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
TypeRegistryNode *rnode = look_up(type, (TypedObject *)NULL);
|
||||
if (rnode != (TypeRegistryNode *)NULL) {
|
||||
|
|
@ -190,7 +190,7 @@ record_alternate_name(TypeHandle type, const string &name) {
|
|||
_name_registry.insert(NameRegistry::value_type(name, rnode)).first;
|
||||
|
||||
if ((*ri).second != rnode) {
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
cerr
|
||||
<< "Name " << name << " already assigned to TypeHandle "
|
||||
<< rnode->_name << "; cannot reassign to " << type << "\n";
|
||||
|
|
@ -199,7 +199,7 @@ record_alternate_name(TypeHandle type, const string &name) {
|
|||
|
||||
}
|
||||
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -208,7 +208,7 @@ record_alternate_name(TypeHandle type, const string &name) {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
find_type(const string &name) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
TypeHandle handle = TypeHandle::none();
|
||||
NameRegistry::const_iterator ri;
|
||||
|
|
@ -216,7 +216,7 @@ find_type(const string &name) const {
|
|||
if (ri != _name_registry.end()) {
|
||||
handle = (*ri).second->_handle;
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
|
@ -248,11 +248,11 @@ find_type_by_id(int id) const {
|
|||
*/
|
||||
string TypeRegistry::
|
||||
get_name(TypeHandle type, TypedObject *object) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeRegistryNode *rnode = look_up(type, object);
|
||||
assert(rnode != (TypeRegistryNode *)NULL);
|
||||
string name = rnode->_name;
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
|
||||
return name;
|
||||
}
|
||||
|
|
@ -273,7 +273,7 @@ get_name(TypeHandle type, TypedObject *object) const {
|
|||
bool TypeRegistry::
|
||||
is_derived_from(TypeHandle child, TypeHandle base,
|
||||
TypedObject *child_object) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
const TypeRegistryNode *child_node = look_up(child, child_object);
|
||||
const TypeRegistryNode *base_node = look_up(base, (TypedObject *)NULL);
|
||||
|
|
@ -284,7 +284,7 @@ is_derived_from(TypeHandle child, TypeHandle base,
|
|||
freshen_derivations();
|
||||
|
||||
bool result = TypeRegistryNode::is_derived_from(child_node, base_node);
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -293,9 +293,9 @@ is_derived_from(TypeHandle child, TypeHandle base,
|
|||
*/
|
||||
int TypeRegistry::
|
||||
get_num_typehandles() {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
int num_types = (int)_handle_registry.size();
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return num_types;
|
||||
}
|
||||
|
||||
|
|
@ -304,12 +304,12 @@ get_num_typehandles() {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
get_typehandle(int n) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeRegistryNode *rnode = NULL;
|
||||
if (n >= 0 && n < (int)_handle_registry.size()) {
|
||||
rnode = _handle_registry[n];
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
|
||||
if (rnode != (TypeRegistryNode *)NULL) {
|
||||
return rnode->_handle;
|
||||
|
|
@ -324,10 +324,10 @@ get_typehandle(int n) {
|
|||
*/
|
||||
int TypeRegistry::
|
||||
get_num_root_classes() {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
freshen_derivations();
|
||||
int num_roots = (int)_root_classes.size();
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return num_roots;
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +336,7 @@ get_num_root_classes() {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
get_root_class(int n) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
freshen_derivations();
|
||||
TypeHandle handle;
|
||||
if (n >= 0 && n < (int)_root_classes.size()) {
|
||||
|
|
@ -344,7 +344,7 @@ get_root_class(int n) {
|
|||
} else {
|
||||
handle = TypeHandle::none();
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
|
@ -362,11 +362,11 @@ get_root_class(int n) {
|
|||
*/
|
||||
int TypeRegistry::
|
||||
get_num_parent_classes(TypeHandle child, TypedObject *child_object) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeRegistryNode *rnode = look_up(child, child_object);
|
||||
assert(rnode != (TypeRegistryNode *)NULL);
|
||||
int num_parents = (int)rnode->_parent_classes.size();
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return num_parents;
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +376,7 @@ get_num_parent_classes(TypeHandle child, TypedObject *child_object) const {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
get_parent_class(TypeHandle child, int index) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeHandle handle;
|
||||
TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL);
|
||||
assert(rnode != (TypeRegistryNode *)NULL);
|
||||
|
|
@ -385,7 +385,7 @@ get_parent_class(TypeHandle child, int index) const {
|
|||
} else {
|
||||
handle = TypeHandle::none();
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
@ -399,11 +399,11 @@ get_parent_class(TypeHandle child, int index) const {
|
|||
*/
|
||||
int TypeRegistry::
|
||||
get_num_child_classes(TypeHandle child, TypedObject *child_object) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeRegistryNode *rnode = look_up(child, child_object);
|
||||
assert(rnode != (TypeRegistryNode *)NULL);
|
||||
int num_children = (int)rnode->_child_classes.size();
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return num_children;
|
||||
}
|
||||
|
||||
|
|
@ -413,7 +413,7 @@ get_num_child_classes(TypeHandle child, TypedObject *child_object) const {
|
|||
*/
|
||||
TypeHandle TypeRegistry::
|
||||
get_child_class(TypeHandle child, int index) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeHandle handle;
|
||||
TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL);
|
||||
assert(rnode != (TypeRegistryNode *)NULL);
|
||||
|
|
@ -422,7 +422,7 @@ get_child_class(TypeHandle child, int index) const {
|
|||
} else {
|
||||
handle = TypeHandle::none();
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +439,7 @@ get_child_class(TypeHandle child, int index) const {
|
|||
TypeHandle TypeRegistry::
|
||||
get_parent_towards(TypeHandle child, TypeHandle base,
|
||||
TypedObject *child_object) {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
TypeHandle handle;
|
||||
const TypeRegistryNode *child_node = look_up(child, child_object);
|
||||
const TypeRegistryNode *base_node = look_up(base, NULL);
|
||||
|
|
@ -447,7 +447,7 @@ get_parent_towards(TypeHandle child, TypeHandle base,
|
|||
base_node != (TypeRegistryNode *)NULL);
|
||||
freshen_derivations();
|
||||
handle = TypeRegistryNode::get_parent_towards(child_node, base_node);
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
@ -462,7 +462,7 @@ get_parent_towards(TypeHandle child, TypeHandle base,
|
|||
void TypeRegistry::
|
||||
reregister_types() {
|
||||
init_lock();
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
HandleRegistry::iterator ri;
|
||||
TypeRegistry *reg = ptr();
|
||||
for (ri = reg->_handle_registry.begin();
|
||||
|
|
@ -473,7 +473,7 @@ reregister_types() {
|
|||
cerr << "Reregistering " << rnode->_name << "\n";
|
||||
}
|
||||
}
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -483,9 +483,9 @@ reregister_types() {
|
|||
*/
|
||||
void TypeRegistry::
|
||||
write(ostream &out) const {
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
do_write(out);
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -613,9 +613,9 @@ look_up_invalid(TypeHandle handle, TypedObject *object) const {
|
|||
// But we're lucky enough to have a TypedObject pointer handy! Maybe we
|
||||
// can use it to resolve the error. We have to drop the lock while we
|
||||
// do this, so we don't get a recursive lock.
|
||||
_lock->release();
|
||||
_lock->unlock();
|
||||
handle = object->force_init_type();
|
||||
_lock->acquire();
|
||||
_lock->lock();
|
||||
|
||||
if (handle._index == 0) {
|
||||
// Strange.
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ reload_cache() {
|
|||
// thread-safe manner. But chances are that the first time this is called
|
||||
// is at static init time, when there is no risk of data races.
|
||||
static MutexImpl lock;
|
||||
lock.acquire();
|
||||
lock.lock();
|
||||
|
||||
// We check again for cache validity since another thread may have beaten
|
||||
// us to the punch while we were waiting for the lock.
|
||||
|
|
@ -42,5 +42,5 @@ reload_cache() {
|
|||
|
||||
mark_cache_valid(_local_modified);
|
||||
}
|
||||
lock.release();
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ reload_cache() {
|
|||
// thread-safe manner. But chances are that the first time this is called
|
||||
// is at static init time, when there is no risk of data races.
|
||||
static MutexImpl lock;
|
||||
lock.acquire();
|
||||
lock.lock();
|
||||
|
||||
// We check again for cache validity since another thread may have beaten
|
||||
// us to the punch while we were waiting for the lock.
|
||||
|
|
@ -31,5 +31,5 @@ reload_cache() {
|
|||
mark_cache_valid(_local_modified);
|
||||
}
|
||||
|
||||
lock.release();
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ StreamWrapperBase() {
|
|||
*/
|
||||
INLINE void StreamWrapperBase::
|
||||
acquire() {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
#ifdef SIMPLE_THREADS
|
||||
while (_lock_flag) {
|
||||
thread_yield();
|
||||
|
|
@ -55,7 +55,7 @@ release() {
|
|||
assert(_lock_flag);
|
||||
_lock_flag = false;
|
||||
#endif
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -122,9 +122,9 @@ add_output(MultiplexStreamBuf::BufferType buffer_type,
|
|||
o._owns_obj = owns_obj;
|
||||
|
||||
// Ensure that we have the mutex while we fiddle with the list of outputs.
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
_outputs.push_back(o);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -133,9 +133,9 @@ add_output(MultiplexStreamBuf::BufferType buffer_type,
|
|||
*/
|
||||
void MultiplexStreamBuf::
|
||||
flush() {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
write_chars("", 0, true);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -144,7 +144,7 @@ flush() {
|
|||
*/
|
||||
int MultiplexStreamBuf::
|
||||
overflow(int ch) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
streamsize n = pptr() - pbase();
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ overflow(int ch) {
|
|||
write_chars(&c, 1, false);
|
||||
}
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ overflow(int ch) {
|
|||
*/
|
||||
int MultiplexStreamBuf::
|
||||
sync() {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
streamsize n = pptr() - pbase();
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ sync() {
|
|||
write_chars(pbase(), n, false);
|
||||
pbump(-n);
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return 0; // Return 0 for success, EOF to indicate write full.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ output(ostream &out) const {
|
|||
PT(HTTPChannel) VirtualFileMountHTTP::
|
||||
get_channel() {
|
||||
PT(HTTPChannel) channel;
|
||||
_channels_lock.acquire();
|
||||
_channels_lock.lock();
|
||||
|
||||
if (!_channels.empty()) {
|
||||
// If we have some channels sitting around, grab one. Grab the one on the
|
||||
|
|
@ -251,7 +251,7 @@ get_channel() {
|
|||
channel = _http->make_channel(true);
|
||||
}
|
||||
|
||||
_channels_lock.release();
|
||||
_channels_lock.unlock();
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
|
@ -262,9 +262,9 @@ get_channel() {
|
|||
*/
|
||||
void VirtualFileMountHTTP::
|
||||
recycle_channel(HTTPChannel *channel) {
|
||||
_channels_lock.acquire();
|
||||
_channels_lock.lock();
|
||||
_channels.push_back(channel);
|
||||
_channels_lock.release();
|
||||
_channels_lock.unlock();
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENSSL
|
||||
|
|
|
|||
|
|
@ -273,9 +273,9 @@ wake_task(AsyncTask *task) {
|
|||
}
|
||||
|
||||
{
|
||||
manager->_lock.release();
|
||||
manager->_lock.unlock();
|
||||
task->upon_birth(manager);
|
||||
manager->_lock.acquire();
|
||||
manager->_lock.lock();
|
||||
nassertv(task->_manager == nullptr &&
|
||||
task->_state == AsyncTask::S_inactive);
|
||||
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@ unlock_and_do_task() {
|
|||
#endif // __GNUC__
|
||||
|
||||
// It's important to release the lock while the task is being serviced.
|
||||
_manager->_lock.release();
|
||||
_manager->_lock.unlock();
|
||||
|
||||
double start = clock->get_real_time();
|
||||
_task_pcollector.start();
|
||||
|
|
@ -424,7 +424,7 @@ unlock_and_do_task() {
|
|||
double end = clock->get_real_time();
|
||||
|
||||
// Now reacquire the lock (so we can return with the lock held).
|
||||
_manager->_lock.acquire();
|
||||
_manager->_lock.lock();
|
||||
|
||||
_dt = end - start;
|
||||
_max_dt = max(_dt, _max_dt);
|
||||
|
|
|
|||
|
|
@ -596,11 +596,11 @@ do_cleanup() {
|
|||
nassertv(_num_tasks == 0 || _num_tasks == 1);
|
||||
|
||||
// Now go back and call the upon_death functions.
|
||||
_manager->_lock.release();
|
||||
_manager->_lock.unlock();
|
||||
for (ti = dead.begin(); ti != dead.end(); ++ti) {
|
||||
(*ti)->upon_death(_manager, false);
|
||||
}
|
||||
_manager->_lock.acquire();
|
||||
_manager->_lock.lock();
|
||||
|
||||
if (task_cat.is_spam()) {
|
||||
do_output(task_cat.spam());
|
||||
|
|
@ -791,9 +791,9 @@ cleanup_task(AsyncTask *task, bool upon_death, bool clean_exit) {
|
|||
task->_manager = nullptr;
|
||||
|
||||
if (upon_death) {
|
||||
_manager->_lock.release();
|
||||
_manager->_lock.unlock();
|
||||
task->upon_death(_manager, clean_exit);
|
||||
_manager->_lock.acquire();
|
||||
_manager->_lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1031,7 +1031,7 @@ do_stop_threads() {
|
|||
|
||||
// We have to release the lock while we join, so the threads can wake up
|
||||
// and see that we're shutting down.
|
||||
_manager->_lock.release();
|
||||
_manager->_lock.unlock();
|
||||
Threads::iterator ti;
|
||||
for (ti = wait_threads.begin(); ti != wait_threads.end(); ++ti) {
|
||||
if (task_cat.is_debug()) {
|
||||
|
|
@ -1046,7 +1046,7 @@ do_stop_threads() {
|
|||
<< *Thread::get_current_thread() << "\n";
|
||||
}
|
||||
}
|
||||
_manager->_lock.acquire();
|
||||
_manager->_lock.lock();
|
||||
|
||||
_state = S_initial;
|
||||
|
||||
|
|
|
|||
|
|
@ -200,9 +200,9 @@ add(AsyncTask *task) {
|
|||
task->_state == AsyncTask::S_inactive);
|
||||
nassertv(!do_has_task(task));
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
task->upon_birth(this);
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
nassertv(task->_manager == NULL &&
|
||||
task->_state == AsyncTask::S_inactive);
|
||||
nassertv(!do_has_task(task));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ get_short_time() {
|
|||
bool is_paranoid_clock = get_paranoid_clock();
|
||||
|
||||
if (is_paranoid_clock) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
}
|
||||
|
||||
double time = get_short_raw_time();
|
||||
|
|
@ -30,7 +30,7 @@ get_short_time() {
|
|||
// Check for rollforwards, rollbacks, and compensate for Speed Gear type
|
||||
// programs by verifying against the time of day clock.
|
||||
time = correct_time(time);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
return time;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ VirtualFileMountRamdisk() : _root("") {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
has_file(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -45,9 +45,9 @@ has_file(const Filename &file) const {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
create_file(const Filename &file) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(File) f = _root.do_create_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -58,9 +58,9 @@ create_file(const Filename &file) {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
delete_file(const Filename &file) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_delete_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -72,10 +72,10 @@ delete_file(const Filename &file) {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) orig_fb = _root.do_find_file(orig_filename);
|
||||
if (orig_fb == NULL) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
Directory *orig_d = DCAST(Directory, orig_fb);
|
||||
PT(Directory) new_d = _root.do_make_directory(new_filename);
|
||||
if (new_d == NULL || !new_d->_files.empty()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
|
||||
new_d->_files.swap(orig_d->_files);
|
||||
_root.do_delete_file(orig_filename);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
File *orig_f = DCAST(File, orig_fb);
|
||||
PT(File) new_f = _root.do_create_file(new_filename);
|
||||
if (new_f == NULL) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
new_f->_data.str(orig_f->_data.str());
|
||||
_root.do_delete_file(orig_filename);
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -127,10 +127,10 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
copy_file(const Filename &orig_filename, const Filename &new_filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) orig_fb = _root.do_find_file(orig_filename);
|
||||
if (orig_fb == NULL || orig_fb->is_directory()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
File *orig_f = DCAST(File, orig_fb);
|
||||
PT(File) new_f = _root.do_create_file(new_filename);
|
||||
if (new_f == NULL) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
|
||||
new_f->_data.str(orig_f->_data.str());
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -161,9 +161,9 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
make_directory(const Filename &file) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(Directory) f = _root.do_make_directory(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -173,9 +173,9 @@ make_directory(const Filename &file) {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
is_directory(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL && f->is_directory());
|
||||
}
|
||||
|
||||
|
|
@ -185,9 +185,9 @@ is_directory(const Filename &file) const {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
is_regular_file(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return (f != NULL && !f->is_directory());
|
||||
}
|
||||
|
||||
|
|
@ -207,9 +207,9 @@ is_writable(const Filename &file) const {
|
|||
*/
|
||||
istream *VirtualFileMountRamdisk::
|
||||
open_read_file(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -225,9 +225,9 @@ open_read_file(const Filename &file) const {
|
|||
*/
|
||||
ostream *VirtualFileMountRamdisk::
|
||||
open_write_file(const Filename &file, bool truncate) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(File) f = _root.do_create_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (File *)NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -254,9 +254,9 @@ open_write_file(const Filename &file, bool truncate) {
|
|||
*/
|
||||
ostream *VirtualFileMountRamdisk::
|
||||
open_append_file(const Filename &file) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(File) f = _root.do_create_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (File *)NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -271,9 +271,9 @@ open_append_file(const Filename &file) {
|
|||
*/
|
||||
iostream *VirtualFileMountRamdisk::
|
||||
open_read_write_file(const Filename &file, bool truncate) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(File) f = _root.do_create_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (File *)NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -296,9 +296,9 @@ open_read_write_file(const Filename &file, bool truncate) {
|
|||
*/
|
||||
iostream *VirtualFileMountRamdisk::
|
||||
open_read_append_file(const Filename &file) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -314,9 +314,9 @@ open_read_append_file(const Filename &file) {
|
|||
*/
|
||||
streamsize VirtualFileMountRamdisk::
|
||||
get_file_size(const Filename &file, istream *stream) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -331,9 +331,9 @@ get_file_size(const Filename &file, istream *stream) const {
|
|||
*/
|
||||
streamsize VirtualFileMountRamdisk::
|
||||
get_file_size(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -354,14 +354,14 @@ get_file_size(const Filename &file) const {
|
|||
*/
|
||||
time_t VirtualFileMountRamdisk::
|
||||
get_timestamp(const Filename &file) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
if (f.is_null()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return 0;
|
||||
}
|
||||
time_t timestamp = f->_timestamp;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
|
@ -372,17 +372,17 @@ get_timestamp(const Filename &file) const {
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
scan_directory(vector_string &contents, const Filename &dir) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(dir);
|
||||
if (f == (FileBase *)NULL || !f->is_directory()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
Directory *f2 = DCAST(Directory, f);
|
||||
bool result = f2->do_scan_directory(contents);
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -393,10 +393,10 @@ bool VirtualFileMountRamdisk::
|
|||
atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents,
|
||||
const string &old_contents,
|
||||
const string &new_contents) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents
|
|||
retval = true;
|
||||
}
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -418,17 +418,17 @@ atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents
|
|||
*/
|
||||
bool VirtualFileMountRamdisk::
|
||||
atomic_read_contents(const Filename &file, string &contents) const {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(FileBase) f = _root.do_find_file(file);
|
||||
if (f == (FileBase *)NULL || f->is_directory()) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
File *f2 = DCAST(File, f);
|
||||
contents = f2->_data.str();
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,9 +190,9 @@ mount(VirtualFileMount *mount, const Filename &mount_point, int flags) {
|
|||
<< "mount " << *mount << " under " << mount_point << "\n";
|
||||
}
|
||||
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
bool result = do_mount(mount, mount_point, flags);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ mount(VirtualFileMount *mount, const Filename &mount_point, int flags) {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
unmount(Multifile *multifile) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Mounts::iterator ri, wi;
|
||||
wi = ri = _mounts.begin();
|
||||
while (ri != _mounts.end()) {
|
||||
|
|
@ -234,7 +234,7 @@ unmount(Multifile *multifile) {
|
|||
int num_removed = _mounts.end() - wi;
|
||||
_mounts.erase(wi, _mounts.end());
|
||||
++_mount_seq;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return num_removed;
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ unmount(Multifile *multifile) {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
unmount(const Filename &physical_filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Mounts::iterator ri, wi;
|
||||
wi = ri = _mounts.begin();
|
||||
while (ri != _mounts.end()) {
|
||||
|
|
@ -293,7 +293,7 @@ unmount(const Filename &physical_filename) {
|
|||
int num_removed = _mounts.end() - wi;
|
||||
_mounts.erase(wi, _mounts.end());
|
||||
++_mount_seq;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return num_removed;
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ unmount(const Filename &physical_filename) {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
unmount(VirtualFileMount *mount) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Mounts::iterator ri, wi;
|
||||
wi = ri = _mounts.begin();
|
||||
while (ri != _mounts.end()) {
|
||||
|
|
@ -326,7 +326,7 @@ unmount(VirtualFileMount *mount) {
|
|||
int num_removed = _mounts.end() - wi;
|
||||
_mounts.erase(wi, _mounts.end());
|
||||
++_mount_seq;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return num_removed;
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +336,7 @@ unmount(VirtualFileMount *mount) {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
unmount_point(const Filename &mount_point) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Filename nmp = normalize_mount_point(mount_point);
|
||||
Mounts::iterator ri, wi;
|
||||
wi = ri = _mounts.begin();
|
||||
|
|
@ -362,7 +362,7 @@ unmount_point(const Filename &mount_point) {
|
|||
int num_removed = _mounts.end() - wi;
|
||||
_mounts.erase(wi, _mounts.end());
|
||||
++_mount_seq;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return num_removed;
|
||||
}
|
||||
|
||||
|
|
@ -372,7 +372,7 @@ unmount_point(const Filename &mount_point) {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
unmount_all() {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Mounts::iterator ri;
|
||||
for (ri = _mounts.begin(); ri != _mounts.end(); ++ri) {
|
||||
VirtualFileMount *mount = (*ri);
|
||||
|
|
@ -386,7 +386,7 @@ unmount_all() {
|
|||
int num_removed = _mounts.size();
|
||||
_mounts.clear();
|
||||
++_mount_seq;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return num_removed;
|
||||
}
|
||||
|
||||
|
|
@ -395,9 +395,9 @@ unmount_all() {
|
|||
*/
|
||||
int VirtualFileSystem::
|
||||
get_num_mounts() const {
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
int result = _mounts.size();
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -406,13 +406,13 @@ get_num_mounts() const {
|
|||
*/
|
||||
PT(VirtualFileMount) VirtualFileSystem::
|
||||
get_mount(int n) const {
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
nassertd(n >= 0 && n < (int)_mounts.size()) {
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return NULL;
|
||||
}
|
||||
PT(VirtualFileMount) result = _mounts[n];
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -423,21 +423,21 @@ get_mount(int n) const {
|
|||
*/
|
||||
bool VirtualFileSystem::
|
||||
chdir(const Filename &new_directory) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
if (new_directory == "/") {
|
||||
// We can always return to the root.
|
||||
_cwd = new_directory;
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
PT(VirtualFile) file = do_get_file(new_directory, OF_status_only);
|
||||
if (file != (VirtualFile *)NULL && file->is_directory()) {
|
||||
_cwd = file->get_filename();
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return true;
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -446,9 +446,9 @@ chdir(const Filename &new_directory) {
|
|||
*/
|
||||
Filename VirtualFileSystem::
|
||||
get_cwd() const {
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
Filename result = _cwd;
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -460,9 +460,9 @@ get_cwd() const {
|
|||
*/
|
||||
bool VirtualFileSystem::
|
||||
make_directory(const Filename &filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(VirtualFile) result = do_get_file(filename, OF_make_directory);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
nassertr_always(result != NULL, false);
|
||||
return result->is_directory();
|
||||
}
|
||||
|
|
@ -474,7 +474,7 @@ make_directory(const Filename &filename) {
|
|||
*/
|
||||
bool VirtualFileSystem::
|
||||
make_directory_full(const Filename &filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
// First, make sure everything up to the last path is known. We don't care
|
||||
// too much if any of these fail; maybe they failed because the directory
|
||||
|
|
@ -489,7 +489,7 @@ make_directory_full(const Filename &filename) {
|
|||
|
||||
// Now make the last one, and check the return value.
|
||||
PT(VirtualFile) result = do_get_file(filename, OF_make_directory);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
nassertr_always(result != NULL, false);
|
||||
return result->is_directory();
|
||||
}
|
||||
|
|
@ -508,9 +508,9 @@ make_directory_full(const Filename &filename) {
|
|||
PT(VirtualFile) VirtualFileSystem::
|
||||
get_file(const Filename &filename, bool status_only) const {
|
||||
int open_flags = status_only ? OF_status_only : 0;
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(VirtualFile) result = do_get_file(filename, open_flags);
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -522,9 +522,9 @@ get_file(const Filename &filename, bool status_only) const {
|
|||
*/
|
||||
PT(VirtualFile) VirtualFileSystem::
|
||||
create_file(const Filename &filename) {
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(VirtualFile) result = do_get_file(filename, OF_create_file);
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -588,20 +588,20 @@ delete_file(const Filename &filename) {
|
|||
*/
|
||||
bool VirtualFileSystem::
|
||||
rename_file(const Filename &orig_filename, const Filename &new_filename) {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
PT(VirtualFile) orig_file = do_get_file(orig_filename, OF_status_only);
|
||||
if (orig_file == (VirtualFile *)NULL) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
PT(VirtualFile) new_file = do_get_file(new_filename, OF_status_only | OF_allow_nonexist);
|
||||
if (new_file == (VirtualFile *)NULL) {
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
return orig_file->rename_file(new_file);
|
||||
}
|
||||
|
|
@ -712,13 +712,13 @@ find_all_files(const Filename &filename, const DSearchPath &searchpath,
|
|||
*/
|
||||
void VirtualFileSystem::
|
||||
write(ostream &out) const {
|
||||
((VirtualFileSystem *)this)->_lock.acquire();
|
||||
_lock.lock();
|
||||
Mounts::const_iterator mi;
|
||||
for (mi = _mounts.begin(); mi != _mounts.end(); ++mi) {
|
||||
VirtualFileMount *mount = (*mi);
|
||||
mount->write(out);
|
||||
}
|
||||
((VirtualFileSystem *)this)->_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ private:
|
|||
int open_flags) const;
|
||||
bool consider_mount_mf(const Filename &filename);
|
||||
|
||||
MutexImpl _lock;
|
||||
mutable MutexImpl _lock;
|
||||
typedef pvector<PT(VirtualFileMount) > Mounts;
|
||||
Mounts _mounts;
|
||||
unsigned int _mount_seq;
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ lock() const {
|
|||
WeakReferenceList *weak_ref = this->_weak_ref;
|
||||
if (weak_ref != nullptr) {
|
||||
PointerTo<T> ptr;
|
||||
weak_ref->_lock.acquire();
|
||||
weak_ref->_lock.lock();
|
||||
if (!weak_ref->was_deleted()) {
|
||||
ptr = (To *)WeakPointerToBase<T>::_void_ptr;
|
||||
}
|
||||
weak_ref->_lock.release();
|
||||
weak_ref->_lock.unlock();
|
||||
return ptr;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
@ -237,11 +237,11 @@ lock() const {
|
|||
WeakReferenceList *weak_ref = this->_weak_ref;
|
||||
if (weak_ref != nullptr) {
|
||||
ConstPointerTo<T> ptr;
|
||||
weak_ref->_lock.acquire();
|
||||
weak_ref->_lock.lock();
|
||||
if (!weak_ref->was_deleted()) {
|
||||
ptr = (const To *)WeakPointerToBase<T>::_void_ptr;
|
||||
}
|
||||
weak_ref->_lock.release();
|
||||
weak_ref->_lock.unlock();
|
||||
return ptr;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ WeakReferenceList::
|
|||
void WeakReferenceList::
|
||||
add_callback(WeakPointerCallback *callback, void *data) {
|
||||
nassertv(callback != nullptr);
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
// We need to check again whether the object is deleted after grabbing the
|
||||
// lock, despite having already done this in weakPointerTo.I, since it may
|
||||
// have been deleted in the meantime.
|
||||
|
|
@ -49,7 +49,7 @@ add_callback(WeakPointerCallback *callback, void *data) {
|
|||
if (!deleted) {
|
||||
_callbacks.insert(make_pair(callback, data));
|
||||
}
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
if (deleted) {
|
||||
callback->wp_callback(data);
|
||||
|
|
@ -65,9 +65,9 @@ add_callback(WeakPointerCallback *callback, void *data) {
|
|||
void WeakReferenceList::
|
||||
remove_callback(WeakPointerCallback *callback) {
|
||||
nassertv(callback != nullptr);
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
_callbacks.erase(callback);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,7 +76,7 @@ remove_callback(WeakPointerCallback *callback) {
|
|||
*/
|
||||
void WeakReferenceList::
|
||||
mark_deleted() {
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
Callbacks::iterator ci;
|
||||
for (ci = _callbacks.begin(); ci != _callbacks.end(); ++ci) {
|
||||
(*ci).first->wp_callback((*ci).second);
|
||||
|
|
@ -86,7 +86,7 @@ mark_deleted() {
|
|||
// Decrement the special offset added to the weak pointer count to indicate
|
||||
// that it can be deleted when all the weak references have gone.
|
||||
AtomicAdjust::Integer result = AtomicAdjust::add(_count, -_alive_offset);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
if (result == 0) {
|
||||
// There are no weak references remaining either, so delete this.
|
||||
delete this;
|
||||
|
|
|
|||
|
|
@ -360,9 +360,9 @@ do_evict_to(size_t target_size, bool hard_evict) {
|
|||
|
||||
} else {
|
||||
// We must release the lock while we call evict_lru().
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
page->evict_lru();
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
if (_total_size <= target_size) {
|
||||
// We've evicted enough to satisfy our target.
|
||||
|
|
|
|||
|
|
@ -169,9 +169,9 @@ do_evict_to(size_t target_size, bool hard_evict) {
|
|||
SimpleLruPage *next = (SimpleLruPage *)node->_next;
|
||||
|
||||
// We must release the lock while we call evict_lru().
|
||||
_global_lock.release();
|
||||
_global_lock.unlock();
|
||||
node->evict_lru();
|
||||
_global_lock.acquire();
|
||||
_global_lock.lock();
|
||||
|
||||
if (node == end || node == _prev) {
|
||||
// If we reach the original tail of the list, stop.
|
||||
|
|
|
|||
|
|
@ -5239,14 +5239,14 @@ unlocked_ensure_ram_image(bool allow_compression) {
|
|||
|
||||
PT(Texture) tex = do_make_copy(cdata);
|
||||
_cycler.release_read(cdata);
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
|
||||
// Perform the actual reload in a copy of the texture, while our own mutex
|
||||
// is left unlocked.
|
||||
CDWriter cdata_tex(tex->_cycler, true);
|
||||
tex->do_reload_ram_image(cdata_tex, allow_compression);
|
||||
|
||||
_lock.acquire();
|
||||
_lock.lock();
|
||||
|
||||
CData *cdataw = _cycler.write_upstream(false, current_thread);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ ConditionVarDebug::
|
|||
*/
|
||||
void ConditionVarDebug::
|
||||
wait() {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ wait() {
|
|||
ostr << *current_thread << " attempted to wait on "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +80,9 @@ wait() {
|
|||
}
|
||||
current_thread->_waiting_on_cvar = this;
|
||||
|
||||
_mutex.do_release();
|
||||
_mutex.do_unlock();
|
||||
_impl.wait(); // temporarily releases _global_lock
|
||||
_mutex.do_acquire(current_thread);
|
||||
_mutex.do_lock(current_thread);
|
||||
|
||||
nassertd(current_thread->_waiting_on_cvar == this) {
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ wait() {
|
|||
<< *current_thread << " awake on " << *this << "\n";
|
||||
}
|
||||
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +106,7 @@ wait() {
|
|||
*/
|
||||
void ConditionVarDebug::
|
||||
wait(double timeout) {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ wait(double timeout) {
|
|||
ostr << *current_thread << " attempted to wait on "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -130,9 +130,9 @@ wait(double timeout) {
|
|||
}
|
||||
current_thread->_waiting_on_cvar = this;
|
||||
|
||||
_mutex.do_release();
|
||||
_mutex.do_unlock();
|
||||
_impl.wait(timeout); // temporarily releases _global_lock
|
||||
_mutex.do_acquire(current_thread);
|
||||
_mutex.do_lock(current_thread);
|
||||
|
||||
nassertd(current_thread->_waiting_on_cvar == this) {
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ wait(double timeout) {
|
|||
<< *current_thread << " awake on " << *this << "\n";
|
||||
}
|
||||
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,7 +160,7 @@ wait(double timeout) {
|
|||
*/
|
||||
void ConditionVarDebug::
|
||||
notify() {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ notify() {
|
|||
ostr << *current_thread << " attempted to notify "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ notify() {
|
|||
}
|
||||
|
||||
_impl.notify();
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ ConditionVarFullDebug::
|
|||
*/
|
||||
void ConditionVarFullDebug::
|
||||
wait() {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ wait() {
|
|||
ostr << *current_thread << " attempted to wait on "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +80,9 @@ wait() {
|
|||
}
|
||||
current_thread->_waiting_on_cvar_full = this;
|
||||
|
||||
_mutex.do_release();
|
||||
_mutex.do_unlock();
|
||||
_impl.wait(); // temporarily releases _global_lock
|
||||
_mutex.do_acquire(current_thread);
|
||||
_mutex.do_lock(current_thread);
|
||||
|
||||
nassertd(current_thread->_waiting_on_cvar_full == this) {
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ wait() {
|
|||
<< *current_thread << " awake on " << *this << "\n";
|
||||
}
|
||||
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +106,7 @@ wait() {
|
|||
*/
|
||||
void ConditionVarFullDebug::
|
||||
wait(double timeout) {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ wait(double timeout) {
|
|||
ostr << *current_thread << " attempted to wait on "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -130,9 +130,9 @@ wait(double timeout) {
|
|||
}
|
||||
current_thread->_waiting_on_cvar_full = this;
|
||||
|
||||
_mutex.do_release();
|
||||
_mutex.do_unlock();
|
||||
_impl.wait(timeout); // temporarily releases _global_lock
|
||||
_mutex.do_acquire(current_thread);
|
||||
_mutex.do_lock(current_thread);
|
||||
|
||||
nassertd(current_thread->_waiting_on_cvar_full == this) {
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ wait(double timeout) {
|
|||
<< *current_thread << " awake on " << *this << "\n";
|
||||
}
|
||||
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,7 +160,7 @@ wait(double timeout) {
|
|||
*/
|
||||
void ConditionVarFullDebug::
|
||||
notify() {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ notify() {
|
|||
ostr << *current_thread << " attempted to notify "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ notify() {
|
|||
}
|
||||
|
||||
_impl.notify();
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +193,7 @@ notify() {
|
|||
*/
|
||||
void ConditionVarFullDebug::
|
||||
notify_all() {
|
||||
_mutex._global_lock->acquire();
|
||||
_mutex._global_lock->lock();
|
||||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ notify_all() {
|
|||
ostr << *current_thread << " attempted to notify "
|
||||
<< *this << " without holding " << _mutex;
|
||||
nassert_raise(ostr.str());
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ notify_all() {
|
|||
}
|
||||
|
||||
_impl.notify_all();
|
||||
_mutex._global_lock->release();
|
||||
_mutex._global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@
|
|||
*/
|
||||
void ConditionVarSimpleImpl::
|
||||
wait() {
|
||||
_mutex.release_quietly();
|
||||
_mutex.unlock_quietly();
|
||||
|
||||
ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
|
||||
ThreadSimpleImpl *thread = manager->get_current_thread();
|
||||
manager->enqueue_block(thread, this);
|
||||
manager->next_context();
|
||||
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +38,7 @@ wait() {
|
|||
*/
|
||||
void ConditionVarSimpleImpl::
|
||||
wait(double timeout) {
|
||||
_mutex.release_quietly();
|
||||
_mutex.unlock_quietly();
|
||||
|
||||
// TODO. For now this will release every frame, since we don't have an
|
||||
// interface yet on ThreadSimpleManager to do a timed wait. Maybe that's
|
||||
|
|
@ -49,7 +49,7 @@ wait(double timeout) {
|
|||
manager->enqueue_ready(thread, true);
|
||||
manager->next_context();
|
||||
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,6 +41,36 @@ operator = (const LightMutexDirect ©) {
|
|||
nassertv(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for acquire() to match C++11 semantics.
|
||||
* @see acquire()
|
||||
*/
|
||||
INLINE void LightMutexDirect::
|
||||
lock() {
|
||||
TAU_PROFILE("void LightMutexDirect::acquire()", " ", TAU_USER);
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for try_acquire() to match C++11 semantics.
|
||||
* @see try_acquire()
|
||||
*/
|
||||
INLINE bool LightMutexDirect::
|
||||
try_lock() {
|
||||
TAU_PROFILE("void LightMutexDirect::try_acquire()", " ", TAU_USER);
|
||||
return _impl.try_lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for release() to match C++11 semantics.
|
||||
* @see release()
|
||||
*/
|
||||
INLINE void LightMutexDirect::
|
||||
unlock() {
|
||||
TAU_PROFILE("void LightMutexDirect::unlock()", " ", TAU_USER);
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the lightMutex if it is available. If it is not available, blocks
|
||||
* until it becomes available, then grabs it. In either case, the function
|
||||
|
|
@ -55,7 +85,7 @@ operator = (const LightMutexDirect ©) {
|
|||
INLINE void LightMutexDirect::
|
||||
acquire() const {
|
||||
TAU_PROFILE("void LightMutexDirect::acquire()", " ", TAU_USER);
|
||||
((LightMutexDirect *)this)->_impl.acquire();
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,7 +98,7 @@ acquire() const {
|
|||
INLINE void LightMutexDirect::
|
||||
release() const {
|
||||
TAU_PROFILE("void LightMutexDirect::release()", " ", TAU_USER);
|
||||
((LightMutexDirect *)this)->_impl.release();
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ private:
|
|||
INLINE LightMutexDirect(const LightMutexDirect ©);
|
||||
INLINE void operator = (const LightMutexDirect ©);
|
||||
|
||||
public:
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
PUBLISHED:
|
||||
BLOCKING INLINE void acquire() const;
|
||||
INLINE void release() const;
|
||||
|
|
@ -54,9 +59,9 @@ private:
|
|||
// even in the SIMPLE_THREADS case. We have to do this since any PStatTimer
|
||||
// call may trigger a context switch, and any low-level context switch
|
||||
// requires all containing mutexes to be true mutexes.
|
||||
MutexTrueImpl _impl;
|
||||
mutable MutexTrueImpl _impl;
|
||||
#else
|
||||
MutexImpl _impl;
|
||||
mutable MutexImpl _impl;
|
||||
#endif // DO_PSTATS
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,36 @@ operator = (const LightReMutexDirect ©) {
|
|||
nassertv(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for acquire() to match C++11 semantics.
|
||||
* @see acquire()
|
||||
*/
|
||||
INLINE void LightReMutexDirect::
|
||||
lock() {
|
||||
TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER);
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for try_acquire() to match C++11 semantics.
|
||||
* @see try_acquire()
|
||||
*/
|
||||
INLINE bool LightReMutexDirect::
|
||||
try_lock() {
|
||||
TAU_PROFILE("void LightReMutexDirect::try_acquire()", " ", TAU_USER);
|
||||
return _impl.try_lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for release() to match C++11 semantics.
|
||||
* @see release()
|
||||
*/
|
||||
INLINE void LightReMutexDirect::
|
||||
unlock() {
|
||||
TAU_PROFILE("void LightReMutexDirect::unlock()", " ", TAU_USER);
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the lightReMutex if it is available. If it is not available, blocks
|
||||
* until it becomes available, then grabs it. In either case, the function
|
||||
|
|
@ -67,7 +97,11 @@ operator = (const LightReMutexDirect ©) {
|
|||
INLINE void LightReMutexDirect::
|
||||
acquire() const {
|
||||
TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER);
|
||||
((LightReMutexDirect *)this)->_impl.acquire();
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
_impl.lock();
|
||||
#else
|
||||
_impl.do_lock(Thread::get_current_thread());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,10 +111,10 @@ acquire() const {
|
|||
INLINE void LightReMutexDirect::
|
||||
acquire(Thread *current_thread) const {
|
||||
TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXIMPL
|
||||
((LightReMutexDirect *)this)->_impl.acquire();
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
_impl.lock();
|
||||
#else
|
||||
((LightReMutexDirect *)this)->_impl.do_lock(current_thread);
|
||||
_impl.do_lock(current_thread);
|
||||
#endif // HAVE_REMUTEXIMPL
|
||||
}
|
||||
|
||||
|
|
@ -97,10 +131,10 @@ acquire(Thread *current_thread) const {
|
|||
INLINE void LightReMutexDirect::
|
||||
elevate_lock() const {
|
||||
TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXIMPL
|
||||
((LightReMutexDirect *)this)->_impl.acquire();
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
_impl.lock();
|
||||
#else
|
||||
((LightReMutexDirect *)this)->_impl.do_elevate_lock();
|
||||
_impl.do_elevate_lock();
|
||||
#endif // HAVE_REMUTEXIMPL
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +148,11 @@ elevate_lock() const {
|
|||
INLINE void LightReMutexDirect::
|
||||
release() const {
|
||||
TAU_PROFILE("void LightReMutexDirect::release()", " ", TAU_USER);
|
||||
((LightReMutexDirect *)this)->_impl.release();
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
_impl.unlock();
|
||||
#else
|
||||
_impl.do_unlock(Thread::get_current_thread());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ private:
|
|||
INLINE LightReMutexDirect(const LightReMutexDirect ©);
|
||||
INLINE void operator = (const LightReMutexDirect ©);
|
||||
|
||||
public:
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
PUBLISHED:
|
||||
BLOCKING INLINE void acquire() const;
|
||||
BLOCKING INLINE void acquire(Thread *current_thread) const;
|
||||
|
|
@ -51,13 +56,13 @@ PUBLISHED:
|
|||
void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
#if defined(HAVE_REMUTEXIMPL) && !defined(DO_PSTATS)
|
||||
ReMutexImpl _impl;
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
mutable ReMutexImpl _impl;
|
||||
|
||||
#else
|
||||
// If we don't have a reentrant mutex, use the one we hand-rolled in
|
||||
// ReMutexDirect.
|
||||
ReMutexDirect _impl;
|
||||
mutable ReMutexDirect _impl;
|
||||
#endif // HAVE_REMUTEXIMPL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,43 @@ operator = (const MutexDebug ©) {
|
|||
nassertv(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for acquire() to match C++11 semantics.
|
||||
* @see acquire()
|
||||
*/
|
||||
INLINE void MutexDebug::
|
||||
lock() {
|
||||
TAU_PROFILE("void MutexDebug::acquire()", " ", TAU_USER);
|
||||
_global_lock->lock();
|
||||
((MutexDebug *)this)->do_lock(Thread::get_current_thread());
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for try_acquire() to match C++11 semantics.
|
||||
* @see try_acquire()
|
||||
*/
|
||||
INLINE bool MutexDebug::
|
||||
try_lock() {
|
||||
TAU_PROFILE("void MutexDebug::try_lock()", " ", TAU_USER);
|
||||
_global_lock->lock();
|
||||
bool acquired = ((MutexDebug *)this)->do_try_lock(Thread::get_current_thread());
|
||||
_global_lock->unlock();
|
||||
return acquired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for release() to match C++11 semantics.
|
||||
* @see release()
|
||||
*/
|
||||
INLINE void MutexDebug::
|
||||
unlock() {
|
||||
TAU_PROFILE("void MutexDebug::unlock()", " ", TAU_USER);
|
||||
_global_lock->lock();
|
||||
((MutexDebug *)this)->do_unlock();
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the mutex if it is available. If it is not available, blocks until
|
||||
* it becomes available, then grabs it. In either case, the function does not
|
||||
|
|
@ -41,9 +78,9 @@ INLINE void MutexDebug::
|
|||
acquire(Thread *current_thread) const {
|
||||
TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER);
|
||||
nassertv(current_thread == Thread::get_current_thread());
|
||||
_global_lock->acquire();
|
||||
((MutexDebug *)this)->do_acquire(current_thread);
|
||||
_global_lock->release();
|
||||
_global_lock->lock();
|
||||
((MutexDebug *)this)->do_lock(current_thread);
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,11 +89,11 @@ acquire(Thread *current_thread) const {
|
|||
*/
|
||||
INLINE bool MutexDebug::
|
||||
try_acquire(Thread *current_thread) const {
|
||||
TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER);
|
||||
TAU_PROFILE("void MutexDebug::try_acquire(Thread *)", " ", TAU_USER);
|
||||
nassertr(current_thread == Thread::get_current_thread(), false);
|
||||
_global_lock->acquire();
|
||||
bool acquired = ((MutexDebug *)this)->do_try_acquire(current_thread);
|
||||
_global_lock->release();
|
||||
_global_lock->lock();
|
||||
bool acquired = ((MutexDebug *)this)->do_try_lock(current_thread);
|
||||
_global_lock->unlock();
|
||||
return acquired;
|
||||
}
|
||||
|
||||
|
|
@ -93,9 +130,9 @@ elevate_lock() const {
|
|||
INLINE void MutexDebug::
|
||||
release() const {
|
||||
TAU_PROFILE("void MutexDebug::release()", " ", TAU_USER);
|
||||
_global_lock->acquire();
|
||||
((MutexDebug *)this)->do_release();
|
||||
_global_lock->release();
|
||||
_global_lock->lock();
|
||||
((MutexDebug *)this)->do_unlock();
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,9 +144,9 @@ release() const {
|
|||
INLINE bool MutexDebug::
|
||||
debug_is_locked() const {
|
||||
TAU_PROFILE("bool MutexDebug::debug_is_locked()", " ", TAU_USER);
|
||||
_global_lock->acquire();
|
||||
_global_lock->lock();
|
||||
bool is_locked = do_debug_is_locked();
|
||||
_global_lock->release();
|
||||
_global_lock->unlock();
|
||||
return is_locked;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,12 +84,12 @@ output(ostream &out) const {
|
|||
*/
|
||||
void MutexDebug::
|
||||
output_with_holder(ostream &out) const {
|
||||
_global_lock->acquire();
|
||||
_global_lock->lock();
|
||||
output(out);
|
||||
if (_locking_thread != (Thread *)NULL) {
|
||||
out << " (held by " << *_locking_thread << ")\n";
|
||||
}
|
||||
_global_lock->release();
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,9 +99,9 @@ output_with_holder(ostream &out) const {
|
|||
*/
|
||||
void MutexDebug::
|
||||
increment_pstats() {
|
||||
_global_lock->acquire();
|
||||
_global_lock->lock();
|
||||
++_pstats_count;
|
||||
_global_lock->release();
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,16 +110,16 @@ increment_pstats() {
|
|||
*/
|
||||
void MutexDebug::
|
||||
decrement_pstats() {
|
||||
_global_lock->acquire();
|
||||
_global_lock->lock();
|
||||
--_pstats_count;
|
||||
_global_lock->release();
|
||||
_global_lock->unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* The private implementation of acquire() assumes that _lock_impl is held.
|
||||
*/
|
||||
void MutexDebug::
|
||||
do_acquire(Thread *current_thread) {
|
||||
do_lock(Thread *current_thread) {
|
||||
// If this assertion is triggered, you tried to lock a recently-destructed
|
||||
// mutex.
|
||||
nassertd(_lock_count != -100) {
|
||||
|
|
@ -235,7 +235,7 @@ do_acquire(Thread *current_thread) {
|
|||
* held.
|
||||
*/
|
||||
bool MutexDebug::
|
||||
do_try_acquire(Thread *current_thread) {
|
||||
do_try_lock(Thread *current_thread) {
|
||||
// If this assertion is triggered, you tried to lock a recently-destructed
|
||||
// mutex.
|
||||
nassertd(_lock_count != -100) {
|
||||
|
|
@ -301,7 +301,7 @@ do_try_acquire(Thread *current_thread) {
|
|||
* The private implementation of acquire() assumes that _lock_impl is held.
|
||||
*/
|
||||
void MutexDebug::
|
||||
do_release() {
|
||||
do_unlock() {
|
||||
// If this assertion is triggered, you tried to release a recently-
|
||||
// destructed mutex.
|
||||
nassertd(_lock_count != -100) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ private:
|
|||
INLINE MutexDebug(const MutexDebug ©);
|
||||
INLINE void operator = (const MutexDebug ©);
|
||||
|
||||
public:
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
PUBLISHED:
|
||||
BLOCKING INLINE void acquire(Thread *current_thread = Thread::get_current_thread()) const;
|
||||
BLOCKING INLINE bool try_acquire(Thread *current_thread = Thread::get_current_thread()) const;
|
||||
|
|
@ -52,9 +57,9 @@ public:
|
|||
static void decrement_pstats();
|
||||
|
||||
private:
|
||||
void do_acquire(Thread *current_thread);
|
||||
bool do_try_acquire(Thread *current_thread);
|
||||
void do_release();
|
||||
void do_lock(Thread *current_thread);
|
||||
bool do_try_lock(Thread *current_thread);
|
||||
void do_unlock();
|
||||
bool do_debug_is_locked() const;
|
||||
|
||||
void report_deadlock(Thread *current_thread);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,36 @@ operator = (const MutexDirect ©) {
|
|||
nassertv(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for acquire() to match C++11 semantics.
|
||||
* @see acquire()
|
||||
*/
|
||||
INLINE void MutexDirect::
|
||||
lock() {
|
||||
TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER);
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for try_acquire() to match C++11 semantics.
|
||||
* @see try_acquire()
|
||||
*/
|
||||
INLINE bool MutexDirect::
|
||||
try_lock() {
|
||||
TAU_PROFILE("void MutexDirect::try_acquire()", " ", TAU_USER);
|
||||
return _impl.try_lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for release() to match C++11 semantics.
|
||||
* @see release()
|
||||
*/
|
||||
INLINE void MutexDirect::
|
||||
unlock() {
|
||||
TAU_PROFILE("void MutexDirect::unlock()", " ", TAU_USER);
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the mutex if it is available. If it is not available, blocks until
|
||||
* it becomes available, then grabs it. In either case, the function does not
|
||||
|
|
@ -54,7 +84,7 @@ operator = (const MutexDirect ©) {
|
|||
INLINE void MutexDirect::
|
||||
acquire() const {
|
||||
TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER);
|
||||
((MutexDirect *)this)->_impl.acquire();
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,7 +94,7 @@ acquire() const {
|
|||
INLINE bool MutexDirect::
|
||||
try_acquire() const {
|
||||
TAU_PROFILE("void MutexDirect::acquire(bool)", " ", TAU_USER);
|
||||
return ((MutexDirect *)this)->_impl.try_acquire();
|
||||
return _impl.try_lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,7 +107,7 @@ try_acquire() const {
|
|||
INLINE void MutexDirect::
|
||||
release() const {
|
||||
TAU_PROFILE("void MutexDirect::release()", " ", TAU_USER);
|
||||
((MutexDirect *)this)->_impl.release();
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ private:
|
|||
INLINE MutexDirect(const MutexDirect ©);
|
||||
INLINE void operator = (const MutexDirect ©);
|
||||
|
||||
public:
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
PUBLISHED:
|
||||
BLOCKING INLINE void acquire() const;
|
||||
BLOCKING INLINE bool try_acquire() const;
|
||||
|
|
@ -49,7 +54,7 @@ PUBLISHED:
|
|||
void output(ostream &out) const;
|
||||
|
||||
private:
|
||||
MutexTrueImpl _impl;
|
||||
mutable MutexTrueImpl _impl;
|
||||
|
||||
friend class ConditionVarDirect;
|
||||
friend class ConditionVarFullDirect;
|
||||
|
|
|
|||
|
|
@ -11,27 +11,13 @@
|
|||
* @date 2007-06-19
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE MutexSimpleImpl::
|
||||
MutexSimpleImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE MutexSimpleImpl::
|
||||
~MutexSimpleImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE void MutexSimpleImpl::
|
||||
acquire() {
|
||||
if (!try_acquire()) {
|
||||
do_acquire();
|
||||
lock() {
|
||||
if (!try_lock()) {
|
||||
do_lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +25,7 @@ acquire() {
|
|||
*
|
||||
*/
|
||||
INLINE bool MutexSimpleImpl::
|
||||
try_acquire() {
|
||||
try_lock() {
|
||||
if ((_flags & F_lock_count) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -52,12 +38,12 @@ try_acquire() {
|
|||
* waiters on the mutex.
|
||||
*/
|
||||
INLINE void MutexSimpleImpl::
|
||||
release() {
|
||||
unlock() {
|
||||
nassertv((_flags & F_lock_count) != 0);
|
||||
_flags &= ~F_lock_count;
|
||||
|
||||
if (_flags & F_has_waiters) {
|
||||
do_release();
|
||||
do_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,11 +51,11 @@ release() {
|
|||
* Releases the mutex, without allowing a context switch to occur.
|
||||
*/
|
||||
INLINE void MutexSimpleImpl::
|
||||
release_quietly() {
|
||||
unlock_quietly() {
|
||||
nassertv((_flags & F_lock_count) != 0);
|
||||
_flags &= ~F_lock_count;
|
||||
|
||||
if (_flags & F_has_waiters) {
|
||||
do_release_quietly();
|
||||
do_unlock_quietly();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
void MutexSimpleImpl::
|
||||
do_acquire() {
|
||||
do_lock() {
|
||||
// By the time we get here, we already know that someone else is holding the
|
||||
// lock: (_flags & F_lock_count) != 0.
|
||||
ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
|
||||
|
|
@ -41,7 +41,7 @@ do_acquire() {
|
|||
*
|
||||
*/
|
||||
void MutexSimpleImpl::
|
||||
do_release() {
|
||||
do_unlock() {
|
||||
// By the time we get here, we already know that someone else is blocked on
|
||||
// this mutex: (_flags & F_waiters) != 0.
|
||||
ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
|
||||
|
|
@ -58,7 +58,7 @@ do_release() {
|
|||
*
|
||||
*/
|
||||
void MutexSimpleImpl::
|
||||
do_release_quietly() {
|
||||
do_unlock_quietly() {
|
||||
ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
|
||||
manager->unblock_one(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,18 +36,17 @@
|
|||
*/
|
||||
class EXPCL_PANDA_PIPELINE MutexSimpleImpl : public BlockerSimple {
|
||||
public:
|
||||
INLINE MutexSimpleImpl();
|
||||
INLINE ~MutexSimpleImpl();
|
||||
CONSTEXPR MutexSimpleImpl() DEFAULT_CTOR;
|
||||
|
||||
INLINE void acquire();
|
||||
INLINE bool try_acquire();
|
||||
INLINE void release();
|
||||
INLINE void release_quietly();
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
INLINE void unlock_quietly();
|
||||
|
||||
private:
|
||||
void do_acquire();
|
||||
void do_release();
|
||||
void do_release_quietly();
|
||||
void do_lock();
|
||||
void do_unlock();
|
||||
void do_unlock_quietly();
|
||||
|
||||
friend class ThreadSimpleManager;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ cycle() {
|
|||
while (link != &prev_dirty) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link;
|
||||
|
||||
if (!cycler->_lock.try_acquire()) {
|
||||
if (!cycler->_lock.try_lock()) {
|
||||
// No big deal, just move on to the next one for now, and we'll
|
||||
// come back around to it. It's important not to block here in
|
||||
// order to prevent one cycler from deadlocking another.
|
||||
|
|
@ -144,7 +144,7 @@ cycle() {
|
|||
} else {
|
||||
// Well, we are the last cycler left, so we might as well wait.
|
||||
// This is necessary to trigger the deadlock detection code.
|
||||
cycler->_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ cycle() {
|
|||
#ifdef DEBUG_THREADS
|
||||
inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1);
|
||||
#endif
|
||||
cycler->_lock.release();
|
||||
cycler->_lock.unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ cycle() {
|
|||
while (link != &prev_dirty) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link;
|
||||
|
||||
if (!cycler->_lock.try_acquire()) {
|
||||
if (!cycler->_lock.try_lock()) {
|
||||
// No big deal, just move on to the next one for now, and we'll
|
||||
// come back around to it. It's important not to block here in
|
||||
// order to prevent one cycler from deadlocking another.
|
||||
|
|
@ -184,7 +184,7 @@ cycle() {
|
|||
} else {
|
||||
// Well, we are the last cycler left, so we might as well wait.
|
||||
// This is necessary to trigger the deadlock detection code.
|
||||
cycler->_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ cycle() {
|
|||
inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1);
|
||||
#endif
|
||||
}
|
||||
cycler->_lock.release();
|
||||
cycler->_lock.unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ cycle() {
|
|||
while (link != &prev_dirty) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link;
|
||||
|
||||
if (!cycler->_lock.try_acquire()) {
|
||||
if (!cycler->_lock.try_lock()) {
|
||||
// No big deal, just move on to the next one for now, and we'll
|
||||
// come back around to it. It's important not to block here in
|
||||
// order to prevent one cycler from deadlocking another.
|
||||
|
|
@ -228,7 +228,7 @@ cycle() {
|
|||
} else {
|
||||
// Well, we are the last cycler left, so we might as well wait.
|
||||
// This is necessary to trigger the deadlock detection code.
|
||||
cycler->_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ cycle() {
|
|||
inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1);
|
||||
#endif
|
||||
}
|
||||
cycler->_lock.release();
|
||||
cycler->_lock.unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -293,11 +293,11 @@ set_num_stages(int num_stages) {
|
|||
PipelineCyclerLinks *links;
|
||||
for (links = _clean._next; links != &_clean; links = links->_next) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links;
|
||||
cycler->_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
}
|
||||
for (links = _dirty._next; links != &_dirty; links = links->_next) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links;
|
||||
cycler->_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
}
|
||||
|
||||
_num_stages = num_stages;
|
||||
|
|
@ -315,12 +315,12 @@ set_num_stages(int num_stages) {
|
|||
int count = 0;
|
||||
for (links = _clean._next; links != &_clean; links = links->_next) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links;
|
||||
cycler->_lock.release();
|
||||
cycler->_lock.unlock();
|
||||
++count;
|
||||
}
|
||||
for (links = _dirty._next; links != &_dirty; links = links->_next) {
|
||||
PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links;
|
||||
cycler->_lock.release();
|
||||
cycler->_lock.unlock();
|
||||
++count;
|
||||
}
|
||||
nassertv(count == _num_cyclers);
|
||||
|
|
@ -402,7 +402,7 @@ remove_cycler(PipelineCyclerTrueImpl *cycler) {
|
|||
// during cycle only if it's 0 (clean) or _next_cycle_seq (scheduled for the
|
||||
// next cycle, so not owned by the current one).
|
||||
while (cycler->_dirty != 0 && cycler->_dirty != _next_cycle_seq) {
|
||||
if (_cycle_lock.try_acquire()) {
|
||||
if (_cycle_lock.try_lock()) {
|
||||
// OK, great, we got the lock, so it finished cycling already.
|
||||
nassertv(!_cycling);
|
||||
|
||||
|
|
@ -417,16 +417,16 @@ remove_cycler(PipelineCyclerTrueImpl *cycler) {
|
|||
inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1);
|
||||
#endif
|
||||
|
||||
_cycle_lock.release();
|
||||
_cycle_lock.unlock();
|
||||
return;
|
||||
} else {
|
||||
// It's possibly currently being cycled. We will wait for the cycler
|
||||
// to be done with it, so that we can safely remove it.
|
||||
_lock.release();
|
||||
cycler->_lock.release();
|
||||
_lock.unlock();
|
||||
cycler->_lock.unlock();
|
||||
Thread::force_yield();
|
||||
cycler->_lock.acquire();
|
||||
_lock.acquire();
|
||||
cycler->_lock.lock();
|
||||
_lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,36 @@ operator = (const ReMutexDirect ©) {
|
|||
nassertv(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for acquire() to match C++11 semantics.
|
||||
* @see acquire()
|
||||
*/
|
||||
INLINE void ReMutexDirect::
|
||||
lock() {
|
||||
TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER);
|
||||
_impl.lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for try_acquire() to match C++11 semantics.
|
||||
* @see try_acquire()
|
||||
*/
|
||||
INLINE bool ReMutexDirect::
|
||||
try_lock() {
|
||||
TAU_PROFILE("void ReMutexDirect::try_acquire()", " ", TAU_USER);
|
||||
return _impl.try_lock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for release() to match C++11 semantics.
|
||||
* @see release()
|
||||
*/
|
||||
INLINE void ReMutexDirect::
|
||||
unlock() {
|
||||
TAU_PROFILE("void ReMutexDirect::unlock()", " ", TAU_USER);
|
||||
_impl.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the reMutex if it is available. If it is not available, blocks until
|
||||
* it becomes available, then grabs it. In either case, the function does not
|
||||
|
|
@ -67,9 +97,9 @@ INLINE void ReMutexDirect::
|
|||
acquire() const {
|
||||
TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
((ReMutexDirect *)this)->_impl.acquire();
|
||||
_impl.lock();
|
||||
#else
|
||||
((ReMutexDirect *)this)->do_acquire();
|
||||
((ReMutexDirect *)this)->do_lock();
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +111,9 @@ INLINE void ReMutexDirect::
|
|||
acquire(Thread *current_thread) const {
|
||||
TAU_PROFILE("void ReMutexDirect::acquire(Thread *)", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
((ReMutexDirect *)this)->_impl.acquire();
|
||||
_impl.lock();
|
||||
#else
|
||||
((ReMutexDirect *)this)->do_acquire(current_thread);
|
||||
((ReMutexDirect *)this)->do_lock(current_thread);
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
}
|
||||
|
||||
|
|
@ -95,9 +125,9 @@ INLINE bool ReMutexDirect::
|
|||
try_acquire() const {
|
||||
TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
return ((ReMutexDirect *)this)->_impl.try_acquire();
|
||||
return _impl.try_lock();
|
||||
#else
|
||||
return ((ReMutexDirect *)this)->do_try_acquire();
|
||||
return ((ReMutexDirect *)this)->do_try_lock();
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
}
|
||||
|
||||
|
|
@ -109,9 +139,9 @@ INLINE bool ReMutexDirect::
|
|||
try_acquire(Thread *current_thread) const {
|
||||
TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
return ((ReMutexDirect *)this)->_impl.try_acquire();
|
||||
return _impl.try_lock();
|
||||
#else
|
||||
return ((ReMutexDirect *)this)->do_try_acquire(current_thread);
|
||||
return ((ReMutexDirect *)this)->do_try_lock(current_thread);
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +159,7 @@ INLINE void ReMutexDirect::
|
|||
elevate_lock() const {
|
||||
TAU_PROFILE("void ReMutexDirect::elevate_lock()", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
((ReMutexDirect *)this)->_impl.acquire();
|
||||
_impl.lock();
|
||||
#else
|
||||
((ReMutexDirect *)this)->do_elevate_lock();
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
|
|
@ -146,9 +176,9 @@ INLINE void ReMutexDirect::
|
|||
release() const {
|
||||
TAU_PROFILE("void ReMutexDirect::release()", " ", TAU_USER);
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
((ReMutexDirect *)this)->_impl.release();
|
||||
_impl.unlock();
|
||||
#else
|
||||
((ReMutexDirect *)this)->do_release();
|
||||
((ReMutexDirect *)this)->do_unlock();
|
||||
#endif // HAVE_REMUTEXTRUEIMPL
|
||||
}
|
||||
|
||||
|
|
@ -201,8 +231,8 @@ get_name() const {
|
|||
* mutex).
|
||||
*/
|
||||
INLINE void ReMutexDirect::
|
||||
do_acquire() {
|
||||
do_acquire(Thread::get_current_thread());
|
||||
do_lock() {
|
||||
do_lock(Thread::get_current_thread());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -214,7 +244,7 @@ do_acquire() {
|
|||
* mutex).
|
||||
*/
|
||||
INLINE bool ReMutexDirect::
|
||||
do_try_acquire() {
|
||||
return do_try_acquire(Thread::get_current_thread());
|
||||
do_try_lock() {
|
||||
return do_try_lock(Thread::get_current_thread());
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ output(ostream &out) const {
|
|||
* mutex).
|
||||
*/
|
||||
void ReMutexDirect::
|
||||
do_acquire(Thread *current_thread) {
|
||||
_lock_impl.acquire();
|
||||
do_lock(Thread *current_thread) {
|
||||
_lock_impl.lock();
|
||||
|
||||
if (_locking_thread == (Thread *)NULL) {
|
||||
// The mutex is not already locked by anyone. Lock it.
|
||||
|
|
@ -61,7 +61,7 @@ do_acquire(Thread *current_thread) {
|
|||
nassertd(_lock_count == 1) {
|
||||
}
|
||||
}
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
}
|
||||
#endif // !HAVE_REMUTEXTRUEIMPL
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ do_acquire(Thread *current_thread) {
|
|||
* mutex).
|
||||
*/
|
||||
bool ReMutexDirect::
|
||||
do_try_acquire(Thread *current_thread) {
|
||||
do_try_lock(Thread *current_thread) {
|
||||
bool acquired = true;
|
||||
_lock_impl.acquire();
|
||||
_lock_impl.lock();
|
||||
|
||||
if (_locking_thread == (Thread *)NULL) {
|
||||
// The mutex is not already locked by anyone. Lock it.
|
||||
|
|
@ -94,7 +94,7 @@ do_try_acquire(Thread *current_thread) {
|
|||
// The mutex is locked by some other thread. Return false.
|
||||
acquired = false;
|
||||
}
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
|
||||
return acquired;
|
||||
}
|
||||
|
|
@ -109,16 +109,16 @@ do_try_acquire(Thread *current_thread) {
|
|||
*/
|
||||
void ReMutexDirect::
|
||||
do_elevate_lock() {
|
||||
_lock_impl.acquire();
|
||||
_lock_impl.lock();
|
||||
|
||||
#ifdef _DEBUG
|
||||
nassertd(_locking_thread == Thread::get_current_thread()) {
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
return;
|
||||
}
|
||||
#elif !defined(NDEBUG)
|
||||
nassertd(_locking_thread != (Thread *)NULL) {
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
return;
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
|
@ -129,7 +129,7 @@ do_elevate_lock() {
|
|||
nassertd(_lock_count > 0) {
|
||||
}
|
||||
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
}
|
||||
#endif // !HAVE_REMUTEXTRUEIMPL
|
||||
|
||||
|
|
@ -141,8 +141,8 @@ do_elevate_lock() {
|
|||
* mutex).
|
||||
*/
|
||||
void ReMutexDirect::
|
||||
do_release() {
|
||||
_lock_impl.acquire();
|
||||
do_unlock() {
|
||||
_lock_impl.lock();
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (_locking_thread != Thread::get_current_thread()) {
|
||||
|
|
@ -150,7 +150,7 @@ do_release() {
|
|||
ostr << *_locking_thread << " attempted to release "
|
||||
<< *this << " which it does not own";
|
||||
nassert_raise(ostr.str());
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
return;
|
||||
}
|
||||
#endif // _DEBUG
|
||||
|
|
@ -164,7 +164,7 @@ do_release() {
|
|||
_locking_thread = (Thread *)NULL;
|
||||
_cvar_impl.notify();
|
||||
}
|
||||
_lock_impl.release();
|
||||
_lock_impl.unlock();
|
||||
}
|
||||
#endif // !HAVE_REMUTEXTRUEIMPL
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ private:
|
|||
INLINE ReMutexDirect(const ReMutexDirect ©);
|
||||
INLINE void operator = (const ReMutexDirect ©);
|
||||
|
||||
public:
|
||||
INLINE void lock();
|
||||
INLINE bool try_lock();
|
||||
INLINE void unlock();
|
||||
|
||||
PUBLISHED:
|
||||
BLOCKING INLINE void acquire() const;
|
||||
BLOCKING INLINE void acquire(Thread *current_thread) const;
|
||||
|
|
@ -54,16 +59,16 @@ PUBLISHED:
|
|||
|
||||
private:
|
||||
#ifdef HAVE_REMUTEXTRUEIMPL
|
||||
ReMutexImpl _impl;
|
||||
mutable ReMutexImpl _impl;
|
||||
|
||||
#else
|
||||
// If we don't have a reentrant mutex, we have to hand-roll one.
|
||||
INLINE void do_acquire();
|
||||
void do_acquire(Thread *current_thread);
|
||||
INLINE bool do_try_acquire();
|
||||
bool do_try_acquire(Thread *current_thread);
|
||||
INLINE void do_lock();
|
||||
void do_lock(Thread *current_thread);
|
||||
INLINE bool do_try_lock();
|
||||
bool do_try_lock(Thread *current_thread);
|
||||
void do_elevate_lock();
|
||||
void do_release();
|
||||
void do_unlock();
|
||||
|
||||
Thread *_locking_thread;
|
||||
int _lock_count;
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ public:
|
|||
double start = clock->get_short_time();
|
||||
double end = start + thread_duration;
|
||||
while (clock->get_short_time() < end) {
|
||||
_m1.acquire();
|
||||
_m1.lock();
|
||||
Thread::sleep(_period);
|
||||
_m1.release();
|
||||
_m1.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,8 +47,8 @@ int
|
|||
main(int argc, char *argv[]) {
|
||||
MutexImpl _m1;
|
||||
|
||||
_m1.acquire();
|
||||
_m1.release();
|
||||
_m1.lock();
|
||||
_m1.unlock();
|
||||
|
||||
cerr << "Making threads.\n";
|
||||
MyThread *a = new MyThread("a", _m1, 1.0);
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ ThreadPosixImpl::
|
|||
<< "Deleting thread " << _parent_obj->get_name() << "\n";
|
||||
}
|
||||
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
|
||||
if (!_detached) {
|
||||
pthread_detach(_thread);
|
||||
_detached = true;
|
||||
}
|
||||
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,13 +65,13 @@ setup_main_thread() {
|
|||
*/
|
||||
bool ThreadPosixImpl::
|
||||
start(ThreadPriority priority, bool joinable) {
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
if (thread_cat->is_debug()) {
|
||||
thread_cat.debug() << "Starting " << *_parent_obj << "\n";
|
||||
}
|
||||
|
||||
nassertd(_status == S_new) {
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -148,12 +148,12 @@ start(ThreadPriority priority, bool joinable) {
|
|||
// Oops, we couldn't start the thread. Be sure to decrement the reference
|
||||
// count we incremented above, and return false to indicate failure.
|
||||
unref_delete(_parent_obj);
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Thread was successfully started.
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -163,15 +163,15 @@ start(ThreadPriority priority, bool joinable) {
|
|||
*/
|
||||
void ThreadPosixImpl::
|
||||
join() {
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
if (!_detached) {
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
void *return_val;
|
||||
pthread_join(_thread, &return_val);
|
||||
_detached = true;
|
||||
return;
|
||||
}
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -246,14 +246,14 @@ root_func(void *data) {
|
|||
nassertr(result == 0, NULL);
|
||||
|
||||
{
|
||||
self->_mutex.acquire();
|
||||
self->_mutex.lock();
|
||||
nassertd(self->_status == S_start_called) {
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->_status = S_running;
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
|
|
@ -270,13 +270,13 @@ root_func(void *data) {
|
|||
}
|
||||
|
||||
{
|
||||
self->_mutex.acquire();
|
||||
self->_mutex.lock();
|
||||
nassertd(self->_status == S_running) {
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
return NULL;
|
||||
}
|
||||
self->_status = S_finished;
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ setup_main_thread() {
|
|||
*/
|
||||
bool ThreadWin32Impl::
|
||||
start(ThreadPriority priority, bool joinable) {
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
if (thread_cat->is_debug()) {
|
||||
thread_cat.debug() << "Starting " << *_parent_obj << "\n";
|
||||
}
|
||||
|
||||
nassertd(_status == S_new && _thread == 0) {
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ start(ThreadPriority priority, bool joinable) {
|
|||
// Oops, we couldn't start the thread. Be sure to decrement the reference
|
||||
// count we incremented above, and return false to indicate failure.
|
||||
unref_delete(_parent_obj);
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ start(ThreadPriority priority, bool joinable) {
|
|||
break;
|
||||
}
|
||||
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -110,16 +110,16 @@ start(ThreadPriority priority, bool joinable) {
|
|||
*/
|
||||
void ThreadWin32Impl::
|
||||
join() {
|
||||
_mutex.acquire();
|
||||
_mutex.lock();
|
||||
nassertd(_joinable && _status != S_new) {
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
while (_status != S_finished) {
|
||||
_cv.wait();
|
||||
}
|
||||
_mutex.release();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -147,14 +147,14 @@ root_func(LPVOID data) {
|
|||
nassertr(result, 1);
|
||||
|
||||
{
|
||||
self->_mutex.acquire();
|
||||
self->_mutex.lock();
|
||||
nassertd(self->_status == S_start_called) {
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
return 1;
|
||||
}
|
||||
self->_status = S_running;
|
||||
self->_cv.notify();
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
}
|
||||
|
||||
self->_parent_obj->thread_main();
|
||||
|
|
@ -166,14 +166,14 @@ root_func(LPVOID data) {
|
|||
}
|
||||
|
||||
{
|
||||
self->_mutex.acquire();
|
||||
self->_mutex.lock();
|
||||
nassertd(self->_status == S_running) {
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
return 1;
|
||||
}
|
||||
self->_status = S_finished;
|
||||
self->_cv.notify();
|
||||
self->_mutex.release();
|
||||
self->_mutex.unlock();
|
||||
}
|
||||
|
||||
// Now drop the parent object reference that we grabbed in start(). This
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ emergency_read_only() {
|
|||
void BamCache::
|
||||
consider_flush_index() {
|
||||
#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
|
||||
if (!_lock.try_acquire()) {
|
||||
if (!_lock.try_lock()) {
|
||||
// If we can't grab the lock, no big deal. We don't want to hold up
|
||||
// the frame waiting for a cache operation. We can try again later.
|
||||
return;
|
||||
|
|
@ -326,7 +326,7 @@ consider_flush_index() {
|
|||
}
|
||||
|
||||
#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
|
||||
_lock.release();
|
||||
_lock.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ get_write_pointer() {
|
|||
|
||||
Thread *current_thread = Thread::get_current_thread();
|
||||
|
||||
_cow_object->_lock_mutex.acquire();
|
||||
_cow_object->_lock_mutex.lock();
|
||||
while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write &&
|
||||
_cow_object->_locking_thread != current_thread) {
|
||||
if (util_cat.is_debug()) {
|
||||
|
|
@ -89,7 +89,7 @@ get_write_pointer() {
|
|||
|
||||
PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
|
||||
_cow_object->CachedTypedWritableReferenceCount::cache_unref();
|
||||
_cow_object->_lock_mutex.release();
|
||||
_cow_object->_lock_mutex.unlock();
|
||||
|
||||
MutexHolder holder(new_object->_lock_mutex);
|
||||
_cow_object = new_object;
|
||||
|
|
@ -112,7 +112,7 @@ get_write_pointer() {
|
|||
|
||||
PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy();
|
||||
_cow_object->CachedTypedWritableReferenceCount::cache_unref();
|
||||
_cow_object->_lock_mutex.release();
|
||||
_cow_object->_lock_mutex.unlock();
|
||||
|
||||
MutexHolder holder(new_object->_lock_mutex);
|
||||
_cow_object = new_object;
|
||||
|
|
@ -132,7 +132,7 @@ get_write_pointer() {
|
|||
// reference.
|
||||
_cow_object->_lock_status = CopyOnWriteObject::LS_locked_write;
|
||||
_cow_object->_locking_thread = current_thread;
|
||||
_cow_object->_lock_mutex.release();
|
||||
_cow_object->_lock_mutex.unlock();
|
||||
}
|
||||
|
||||
return _cow_object;
|
||||
|
|
|
|||
Loading…
Reference in New Issue