fix mutex_spinlock

This commit is contained in:
David Rose 2007-11-27 01:08:46 +00:00
parent 701baa9f31
commit 2e8fec7683
6 changed files with 38 additions and 23 deletions

View File

@ -42,12 +42,6 @@ typedef MutexWin32Impl MutexImpl;
typedef MutexWin32Impl ReMutexImpl; // Win32 Mutexes are always reentrant. typedef MutexWin32Impl ReMutexImpl; // Win32 Mutexes are always reentrant.
#define HAVE_REMUTEXIMPL 1 #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) #elif defined(THREAD_POSIX_IMPL)
#include "mutexPosixImpl.h" #include "mutexPosixImpl.h"

View File

@ -39,7 +39,7 @@ freshen_derivations() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void TypeRegistry:: INLINE void TypeRegistry::
init_lock() { init_lock() {
if (_lock == (ReMutexImpl *)NULL) { if (_lock == (MutexImpl *)NULL) {
_lock = new ReMutexImpl; _lock = new MutexImpl;
} }
} }

View File

@ -25,7 +25,7 @@
#include <algorithm> #include <algorithm>
ReMutexImpl *TypeRegistry::_lock = NULL; MutexImpl *TypeRegistry::_lock = NULL;
TypeRegistry *TypeRegistry::_global_pointer = NULL; TypeRegistry *TypeRegistry::_global_pointer = NULL;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -524,17 +524,7 @@ reregister_types() {
void TypeRegistry:: void TypeRegistry::
write(ostream &out) const { write(ostream &out) const {
_lock->lock(); _lock->lock();
// Recursively write out the tree, starting from each node that has do_write(out);
// 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);
}
}
_lock->release(); _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 // Function: TypeRegistry::write_node
// Access: Private // Access: Private
// Description: Writes a single TypeRegistryNode out, along with all of // Description: Writes a single TypeRegistryNode out, along with all of
// its descendants. // its descendants. Assumes the lock is already held.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TypeRegistry:: void TypeRegistry::
write_node(ostream &out, int indent_level, const TypeRegistryNode *node) const { 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 // the object that owns the handle, if available. It is
// only used in an error condition, if for some reason // only used in an error condition, if for some reason
// the handle was uninitialized. // the handle was uninitialized.
//
// Assumes the lock is already held.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TypeRegistryNode *TypeRegistry:: TypeRegistryNode *TypeRegistry::
look_up(TypeHandle handle, TypedObject *object) const { look_up(TypeHandle handle, TypedObject *object) const {
@ -675,8 +688,11 @@ look_up(TypeHandle handle, TypedObject *object) const {
if (object != NULL) { if (object != NULL) {
// But we're lucky enough to have a TypedObject pointer handy! // 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(); handle = object->force_init_type();
_lock->lock();
if (handle._index == 0) { if (handle._index == 0) {
// Strange. // Strange.
cerr cerr

View File

@ -95,6 +95,8 @@ private:
INLINE void freshen_derivations(); INLINE void freshen_derivations();
void rebuild_derivations(); void rebuild_derivations();
void do_write(ostream &out) const;
void write_node(ostream &out, int indent_level, void write_node(ostream &out, int indent_level,
const TypeRegistryNode *node) const; const TypeRegistryNode *node) const;
@ -111,7 +113,7 @@ private:
bool _derivations_fresh; bool _derivations_fresh;
static ReMutexImpl *_lock; static MutexImpl *_lock;
static TypeRegistry *_global_pointer; static TypeRegistry *_global_pointer;
friend class TypeHandle; friend class TypeHandle;

View File

@ -26,6 +26,7 @@
typedef bool BOOL; typedef bool BOOL;
typedef long DWORD; typedef long DWORD;
typedef long LONG;
typedef unsigned long ULONG; typedef unsigned long ULONG;
typedef long HRESULT; typedef long HRESULT;
typedef int CRITICAL_SECTION; typedef int CRITICAL_SECTION;

View File

@ -47,7 +47,9 @@ typedef ReMutexSimpleImpl ReMutexTrueImpl;
#else #else
typedef MutexImpl MutexTrueImpl; typedef MutexImpl MutexTrueImpl;
#if HAVE_REMUTEXIMPL
typedef ReMutexImpl ReMutexTrueImpl; typedef ReMutexImpl ReMutexTrueImpl;
#endif // HAVE_REMUTEXIMPL
#endif #endif