From e09348c05d188979c490a9a22d39a1203cacc797 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 24 Dec 2014 09:13:58 +0100 Subject: ByteBuffer: SingleThreadAccessChecker is request-only. It slows the server down way too much, so it can't be turned on by default. --- src/ByteBuffer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 080176dcd..b441d61ca 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -13,6 +13,15 @@ +/** When defined, each access to a cByteBuffer object is checked whether it's done in the same thread. +cByteBuffer assumes that it is not used by multiple threads at once, this macro adds a runtime check for that. +Unfortunately it is very slow, so it is disabled even for regular DEBUG builds. */ +// #define DEBUG_SINGLE_THREAD_ACCESS + + + + + // Try to determine endianness: #if ( \ defined(__i386__) || defined(__alpha__) || \ @@ -109,7 +118,7 @@ public: -#ifdef _DEBUG +#ifdef DEBUG_SINGLE_THREAD_ACCESS /** Simple RAII class that is used for checking that no two threads are using an object simultanously. It requires the monitored object to provide the storage for a thread ID. -- cgit v1.2.3 From 35a3a1b9f4fd52b37106271964157fc3b7a9ee84 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 3 Jan 2015 22:20:30 +0100 Subject: cByteBuffer: Improved SingleThreadAccessChecker performance. But it's still poor and unusable for regular testing. --- src/ByteBuffer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index b441d61ca..e1e5867a9 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -131,7 +131,7 @@ public: { ASSERT( (*a_ThreadID == std::this_thread::get_id()) || // Either the object is used by current thread... - (*a_ThreadID == std::thread::id()) // ... or by no thread at all + (*a_ThreadID == m_EmptyThreadID) // ... or by no thread at all ); // Mark as being used by this thread: @@ -147,8 +147,13 @@ public: protected: /** Points to the storage used for ID of the thread using the object. */ std::thread::id * m_ThreadID; + + /** The value of an unassigned thread ID, used to speed up checking. */ + static std::thread::id m_EmptyThreadID; }; + std::thread::id cSingleThreadAccessChecker::m_EmptyThreadID; + #define CHECK_THREAD cSingleThreadAccessChecker Checker(&m_ThreadID); #else -- cgit v1.2.3 From adf3b3a56944dfa3a0204707e2ccc94c3a0d043c Mon Sep 17 00:00:00 2001 From: Matyas Dolak Date: Wed, 21 Jan 2015 12:12:22 +0100 Subject: ByteBuffer: Added support for reading unsigned shorts and ints. --- src/ByteBuffer.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index e1e5867a9..f3dc44d91 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -344,12 +344,28 @@ bool cByteBuffer::ReadByte(unsigned char & a_Value) bool cByteBuffer::ReadBEShort(short & a_Value) +{ + CHECK_THREAD + CheckValid(); + NEEDBYTES(2); + Int16 val; + ReadBuf(&val, 2); + val = ntohs(val); + a_Value = *(reinterpret_cast(&val)); + return true; +} + + + + + +bool cByteBuffer::ReadBEUInt16(UInt16 & a_Value) { CHECK_THREAD CheckValid(); NEEDBYTES(2); ReadBuf(&a_Value, 2); - a_Value = (short)ntohs((u_short)a_Value); + a_Value = ntohs(a_Value); return true; } @@ -371,6 +387,20 @@ bool cByteBuffer::ReadBEInt(int & a_Value) +bool cByteBuffer::ReadBEUInt32(UInt32 & a_Value) +{ + CHECK_THREAD + CheckValid(); + NEEDBYTES(4); + ReadBuf(&a_Value, 4); + a_Value = ntohl(a_Value); + return true; +} + + + + + bool cByteBuffer::ReadBEInt64(Int64 & a_Value) { CHECK_THREAD -- cgit v1.2.3