Important Update:
- CItemBuffer: - Rename CItemBufferCore -> CItemBuffer - Add item count and GetCount() method - Bug fix: Reset LastItem on DeleteAll() - TimingCore: - Bug fix: Handle buffer overflow on 32-bit processors
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
|
||||
//***** Function Prototypes *****//
|
||||
|
||||
CItemBufferCore::CItemBufferCore( bool pCopyEntries )
|
||||
CItemBuffer::CItemBuffer( bool pCopyEntries )
|
||||
{
|
||||
// Parameters
|
||||
CopyEntries = pCopyEntries;
|
||||
Count = 0;
|
||||
|
||||
// Clear Event list
|
||||
FirstItem = NULL;
|
||||
@@ -27,14 +28,14 @@ CItemBufferCore::CItemBufferCore( bool pCopyEntries )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CItemBufferCore::~ CItemBufferCore()
|
||||
CItemBuffer::~ CItemBuffer()
|
||||
{
|
||||
// Free Event List
|
||||
DeleteAll();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
TBufferItem * CItemBufferCore::CreateItem( void * Entry, int Size )
|
||||
TBufferItem * CItemBuffer::CreateItem( void * Entry, int Size )
|
||||
{
|
||||
TBufferItem * BufferItem;
|
||||
|
||||
@@ -68,7 +69,7 @@ TBufferItem * CItemBufferCore::CreateItem( void * Entry, int Size )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CItemBufferCore::DestroyItem( TBufferItem ** BufferItem )
|
||||
bool CItemBuffer::DestroyItem( TBufferItem ** BufferItem )
|
||||
{
|
||||
// Check if valid pointer
|
||||
if (!BufferItem || !*BufferItem)
|
||||
@@ -86,7 +87,7 @@ bool CItemBufferCore::DestroyItem( TBufferItem ** BufferItem )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CItemBufferCore::DestroyEntry( void ** Entry )
|
||||
bool CItemBuffer::DestroyEntry( void ** Entry )
|
||||
{
|
||||
// Verify pointer
|
||||
if (!Entry || !*Entry)
|
||||
@@ -100,7 +101,7 @@ bool CItemBufferCore::DestroyEntry( void ** Entry )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CItemBufferCore::Push( void * Entry, int Size )
|
||||
bool CItemBuffer::Push( void * Entry, int Size )
|
||||
{
|
||||
// Verify pointer
|
||||
if (!Entry || !Size)
|
||||
@@ -112,11 +113,12 @@ bool CItemBufferCore::Push( void * Entry, int Size )
|
||||
|
||||
// Move Next entry reference
|
||||
LastItem = &((*LastItem)->NextItem);
|
||||
Count++;
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void * CItemBufferCore::Pop( int * Size )
|
||||
void * CItemBuffer::Pop( int * Size )
|
||||
{
|
||||
void * Entry;
|
||||
|
||||
@@ -124,13 +126,11 @@ void * CItemBufferCore::Pop( int * Size )
|
||||
if ((Entry = Peek( Size ))) {
|
||||
Delete();
|
||||
}
|
||||
|
||||
// return event
|
||||
return Entry;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void * CItemBufferCore::Peek( int * Size )
|
||||
void * CItemBuffer::Peek( int * Size )
|
||||
{
|
||||
void * Entry;
|
||||
|
||||
@@ -149,7 +149,7 @@ void * CItemBufferCore::Peek( int * Size )
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool CItemBufferCore::Delete()
|
||||
bool CItemBuffer::Delete()
|
||||
{
|
||||
TBufferItem * BufferItem;
|
||||
|
||||
@@ -170,11 +170,12 @@ bool CItemBufferCore::Delete()
|
||||
DestroyEntry( &(BufferItem->Entry) );
|
||||
free( BufferItem );
|
||||
|
||||
Count--;
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CItemBufferCore::DeleteAll()
|
||||
void CItemBuffer::DeleteAll()
|
||||
{
|
||||
TBufferItem * NextItem;
|
||||
|
||||
@@ -184,5 +185,7 @@ void CItemBufferCore::DeleteAll()
|
||||
DestroyItem( &FirstItem );
|
||||
FirstItem = NextItem;
|
||||
}
|
||||
LastItem = &FirstItem;
|
||||
Count = 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -31,13 +31,14 @@ struct SBufferItem {
|
||||
|
||||
//***** Function Prototypes *****//
|
||||
|
||||
class CItemBufferCore
|
||||
class CItemBuffer
|
||||
{
|
||||
protected:
|
||||
// Parameters
|
||||
bool CopyEntries; // Make copies of entries and destroy them when done?
|
||||
int Count;
|
||||
|
||||
// Events
|
||||
// Items
|
||||
TBufferItem * FirstItem;
|
||||
TBufferItem ** LastItem;
|
||||
|
||||
@@ -49,8 +50,8 @@ class CItemBufferCore
|
||||
|
||||
public:
|
||||
// Initiate object
|
||||
CItemBufferCore( bool pCopyEntries );
|
||||
virtual ~CItemBufferCore();
|
||||
CItemBuffer( bool pCopyEntries );
|
||||
virtual ~CItemBuffer();
|
||||
|
||||
// Buffer Operations
|
||||
bool Push( void * Entry, int Size );
|
||||
@@ -58,6 +59,9 @@ class CItemBufferCore
|
||||
void * Peek( int * Size = NULL );
|
||||
bool Delete();
|
||||
void DeleteAll();
|
||||
|
||||
// Misc
|
||||
int GetCount() { return Count; };
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
// redA Libraries
|
||||
#include "TimingCore.h"
|
||||
@@ -43,15 +44,17 @@ void ClearStartTime( timeval * StartTime )
|
||||
// Calculate TimePassed from Start Time (in milli-seconds)
|
||||
long TimePassed( timeval StartTime )
|
||||
{
|
||||
timeval CurrTime;
|
||||
long Duration;
|
||||
timeval CurrTime;
|
||||
long Duration;
|
||||
|
||||
// Get current time
|
||||
gettimeofday( &CurrTime, NULL );
|
||||
|
||||
// Get time passed in milli-seconds
|
||||
Duration = (CurrTime.tv_sec - StartTime.tv_sec) * 1000 +
|
||||
(CurrTime.tv_usec - StartTime.tv_usec) / 1000;
|
||||
Duration = (CurrTime.tv_sec - StartTime.tv_sec) * (time_t)1000 +
|
||||
(CurrTime.tv_usec - StartTime.tv_usec) / (time_t)1000;
|
||||
if (Duration < 0)
|
||||
Duration = LONG_MAX;
|
||||
|
||||
return Duration;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user