Browse Source

Mingw fixes for pnUtils.

Darryl Pogue 14 years ago
parent
commit
c4044cbf06
  1. 123
      Sources/Plasma/NucleusLib/pnUtils/Private/pnUtHash.h
  2. 2
      Sources/Plasma/NucleusLib/pnUtils/Private/pnUtMisc.h
  3. 43
      Sources/Plasma/NucleusLib/pnUtils/Private/pnUtRef.h

123
Sources/Plasma/NucleusLib/pnUtils/Private/pnUtHash.h

@ -63,6 +63,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define HASHTABLEDECLSIZE(object,key,link,size) THashTableDecl<object, key, offsetof(object,link), size >
#if defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline inline
#endif
/****************************************************************************
*
* Forward declarations
@ -76,6 +83,64 @@ template<class T>
class TBaseHashTable;
/****************************************************************************
*
* CHashValue
*
***/
class CHashValue {
private:
static const dword s_hashTable[];
dword m_result;
inline void Construct () { m_result = 0x325d1eae; }
public:
static dword LookupHashBits (unsigned value) { ASSERT(value < 0x100); return s_hashTable[value]; }
inline CHashValue () { Construct() ; }
inline CHashValue (const CHashValue & source) { m_result = source.m_result; }
inline CHashValue (const void * data, unsigned bytes) { Construct(); Hash(data, bytes); }
inline CHashValue & operator= (const CHashValue & source) { m_result = source.m_result; return *this; }
inline bool operator== (const CHashValue & source) const { return (m_result == source.m_result); }
inline dword GetHash () const { return m_result; }
forceinline void Hash (const void * data, unsigned bytes);
forceinline void Hash8 (unsigned data);
forceinline void Hash16 (unsigned data);
forceinline void Hash32 (unsigned data);
};
//===========================================================================
void CHashValue::Hash (const void * data, unsigned bytes) {
for (const byte * curr = (const byte *)data, * term = curr + bytes; curr != term; ++curr)
Hash8(*curr);
}
//===========================================================================
void CHashValue::Hash8 (unsigned data) {
m_result += s_hashTable[m_result >> 24] ^ (m_result >> 6) ^ s_hashTable[data & 0xff];
}
//===========================================================================
void CHashValue::Hash16 (unsigned data) {
Hash8(data);
Hash8(data >> 8);
}
//===========================================================================
void CHashValue::Hash32 (unsigned data) {
Hash8(data);
Hash8(data >> 8);
Hash8(data >> 16);
Hash8(data >> 24);
}
/****************************************************************************
*
* THashLink
@ -661,61 +726,3 @@ typedef THashKeyStr< wchar, THashKeyStrCmp<wchar> > CHashKeyStr;
typedef THashKeyStr< wchar, THashKeyStrCmpI<wchar> > CHashKeyStrI;
typedef THashKeyStr< char, THashKeyStrCmp<char> > CHashKeyStrChar;
typedef THashKeyStr< char, THashKeyStrCmpI<char> > CHashKeyStrCharI;
/****************************************************************************
*
* CHashValue
*
***/
class CHashValue {
private:
static const dword s_hashTable[];
dword m_result;
inline void Construct () { m_result = 0x325d1eae; }
public:
static dword LookupHashBits (unsigned value) { ASSERT(value < 0x100); return s_hashTable[value]; }
inline CHashValue () { Construct() ; }
inline CHashValue (const CHashValue & source) { m_result = source.m_result; }
inline CHashValue (const void * data, unsigned bytes) { Construct(); Hash(data, bytes); }
inline CHashValue & operator= (const CHashValue & source) { m_result = source.m_result; return *this; }
inline bool operator== (const CHashValue & source) const { return (m_result == source.m_result); }
inline dword GetHash () const { return m_result; }
__forceinline void Hash (const void * data, unsigned bytes);
__forceinline void Hash8 (unsigned data);
__forceinline void Hash16 (unsigned data);
__forceinline void Hash32 (unsigned data);
};
//===========================================================================
void CHashValue::Hash (const void * data, unsigned bytes) {
for (const byte * curr = (const byte *)data, * term = curr + bytes; curr != term; ++curr)
Hash8(*curr);
}
//===========================================================================
void CHashValue::Hash8 (unsigned data) {
m_result += s_hashTable[m_result >> 24] ^ (m_result >> 6) ^ s_hashTable[data & 0xff];
}
//===========================================================================
void CHashValue::Hash16 (unsigned data) {
Hash8(data);
Hash8(data >> 8);
}
//===========================================================================
void CHashValue::Hash32 (unsigned data) {
Hash8(data);
Hash8(data >> 8);
Hash8(data >> 16);
Hash8(data >> 24);
}

2
Sources/Plasma/NucleusLib/pnUtils/Private/pnUtMisc.h

@ -79,7 +79,7 @@ void MachineGetName (wchar * computerName, unsigned length = 32);
***/
// used to dump the internal state of a module
typedef void (__cdecl * FStateDump)(
typedef void (CDECL * FStateDump)(
void * param,
const wchar fmt[],
...

43
Sources/Plasma/NucleusLib/pnUtils/Private/pnUtRef.h

@ -35,19 +35,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTREF_H
/*****************************************************************************
*
* Debug macros
*
***/
#ifdef REFCOUNT_DEBUGGING
#define REFTRACE DEBUG_MSG
#else
#define REFTRACE NULL_STMT
#endif
/****************************************************************************
*
* AtomicRef
@ -78,7 +65,9 @@ public:
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, 1);
REFTRACE("Inc %p: %u", this, prev+1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p: %u", this, prev+1);
#endif
return prev+1;
}
inline long IncRef (const char tag[]) {
@ -86,7 +75,9 @@ public:
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, 1);
REFTRACE("Inc %p %s: %u", this, tag, prev+1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: %u", this, tag, prev+1);
#endif
return prev+1;
}
inline long IncRef (unsigned n) {
@ -94,7 +85,9 @@ public:
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, n);
REFTRACE("Inc %p: %u", this, prev+n);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p: %u", this, prev+n);
#endif
return prev+n;
}
inline long IncRef (unsigned n, const char tag[]) {
@ -102,7 +95,9 @@ public:
ASSERT(!zeroed);
#endif
long prev = AtomicAdd(&m_ref, n);
REFTRACE("Inc %p %s: %u", this, tag, prev+n);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: %u", this, tag, prev+n);
#endif
return prev+n;
}
@ -117,7 +112,9 @@ public:
#endif
OnZeroRef();
}
REFTRACE("Dec %p: %u", this, prev-1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Dec %p: %u", this, prev-1);
#endif
return prev-1;
}
inline long DecRef (const char tag[]) {
@ -131,7 +128,9 @@ public:
#endif
OnZeroRef();
}
REFTRACE("Dec %p %s: %u", this, tag, prev-1);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Dec %p %s: %u", this, tag, prev-1);
#endif
return prev-1;
}
@ -142,8 +141,10 @@ public:
#ifdef HS_DEBUGGING
ASSERT(!zeroed);
#endif
REFTRACE("Inc %p %s: (xfer)", this, newTag);
REFTRACE("Dec %p %s: (xfer)", this, oldTag);
#ifdef REFCOUNT_DEBUGGING
DEBUG_MSG("Inc %p %s: (xfer)", this, newTag);
DEBUG_MSG("Dec %p %s: (xfer)", this, oldTag);
#endif
}
inline unsigned GetRefCount () {

Loading…
Cancel
Save