mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
fix mutex_spinlock
This commit is contained in:
parent
701baa9f31
commit
2e8fec7683
@ -42,12 +42,6 @@ typedef MutexWin32Impl MutexImpl;
|
||||
typedef MutexWin32Impl ReMutexImpl; // Win32 Mutexes are always reentrant.
|
||||
#define HAVE_REMUTEXIMPL 1
|
||||
|
||||
#elif defined(THREAD_LINUX_IMPL)
|
||||
|
||||
#include "mutexLinuxImpl.h"
|
||||
typedef MutexLinuxImpl MutexImpl;
|
||||
#undef HAVE_REMUTEXIMPL // The futex implementation is non-reentrant.
|
||||
|
||||
#elif defined(THREAD_POSIX_IMPL)
|
||||
|
||||
#include "mutexPosixImpl.h"
|
||||
|
@ -39,7 +39,7 @@ freshen_derivations() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void TypeRegistry::
|
||||
init_lock() {
|
||||
if (_lock == (ReMutexImpl *)NULL) {
|
||||
_lock = new ReMutexImpl;
|
||||
if (_lock == (MutexImpl *)NULL) {
|
||||
_lock = new MutexImpl;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
ReMutexImpl *TypeRegistry::_lock = NULL;
|
||||
MutexImpl *TypeRegistry::_lock = NULL;
|
||||
TypeRegistry *TypeRegistry::_global_pointer = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -524,17 +524,7 @@ reregister_types() {
|
||||
void TypeRegistry::
|
||||
write(ostream &out) const {
|
||||
_lock->lock();
|
||||
// Recursively write out the tree, starting from each node that has
|
||||
// no parent.
|
||||
HandleRegistry::const_iterator hi;
|
||||
for (hi = _handle_registry.begin();
|
||||
hi != _handle_registry.end();
|
||||
++hi) {
|
||||
const TypeRegistryNode *root = *hi;
|
||||
if (root != NULL && root->_parent_classes.empty()) {
|
||||
write_node(out, 2, root);
|
||||
}
|
||||
}
|
||||
do_write(out);
|
||||
_lock->release();
|
||||
}
|
||||
|
||||
@ -632,11 +622,32 @@ rebuild_derivations() {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TypeRegistry::do_write
|
||||
// Access: Private
|
||||
// Description: The private implementation of write(), this assumes
|
||||
// the lock is already held.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void TypeRegistry::
|
||||
do_write(ostream &out) const {
|
||||
// Recursively write out the tree, starting from each node that has
|
||||
// no parent.
|
||||
HandleRegistry::const_iterator hi;
|
||||
for (hi = _handle_registry.begin();
|
||||
hi != _handle_registry.end();
|
||||
++hi) {
|
||||
const TypeRegistryNode *root = *hi;
|
||||
if (root != NULL && root->_parent_classes.empty()) {
|
||||
write_node(out, 2, root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TypeRegistry::write_node
|
||||
// Access: Private
|
||||
// Description: Writes a single TypeRegistryNode out, along with all of
|
||||
// its descendants.
|
||||
// its descendants. Assumes the lock is already held.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void TypeRegistry::
|
||||
write_node(ostream &out, int indent_level, const TypeRegistryNode *node) const {
|
||||
@ -666,6 +677,8 @@ write_node(ostream &out, int indent_level, const TypeRegistryNode *node) const {
|
||||
// the object that owns the handle, if available. It is
|
||||
// only used in an error condition, if for some reason
|
||||
// the handle was uninitialized.
|
||||
//
|
||||
// Assumes the lock is already held.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TypeRegistryNode *TypeRegistry::
|
||||
look_up(TypeHandle handle, TypedObject *object) const {
|
||||
@ -675,8 +688,11 @@ look_up(TypeHandle handle, TypedObject *object) const {
|
||||
|
||||
if (object != NULL) {
|
||||
// But we're lucky enough to have a TypedObject pointer handy!
|
||||
// Maybe we can use it to resolve the error.
|
||||
// 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();
|
||||
handle = object->force_init_type();
|
||||
_lock->lock();
|
||||
if (handle._index == 0) {
|
||||
// Strange.
|
||||
cerr
|
||||
|
@ -95,6 +95,8 @@ private:
|
||||
|
||||
INLINE void freshen_derivations();
|
||||
void rebuild_derivations();
|
||||
|
||||
void do_write(ostream &out) const;
|
||||
void write_node(ostream &out, int indent_level,
|
||||
const TypeRegistryNode *node) const;
|
||||
|
||||
@ -111,7 +113,7 @@ private:
|
||||
|
||||
bool _derivations_fresh;
|
||||
|
||||
static ReMutexImpl *_lock;
|
||||
static MutexImpl *_lock;
|
||||
static TypeRegistry *_global_pointer;
|
||||
|
||||
friend class TypeHandle;
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
typedef bool BOOL;
|
||||
typedef long DWORD;
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef long HRESULT;
|
||||
typedef int CRITICAL_SECTION;
|
||||
|
@ -47,7 +47,9 @@ typedef ReMutexSimpleImpl ReMutexTrueImpl;
|
||||
#else
|
||||
|
||||
typedef MutexImpl MutexTrueImpl;
|
||||
#if HAVE_REMUTEXIMPL
|
||||
typedef ReMutexImpl ReMutexTrueImpl;
|
||||
#endif // HAVE_REMUTEXIMPL
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user