OpenBarnyard
 
Loading...
Searching...
No Matches
TGenericFifo Class Reference

#include <TFifo.h>

Inheritance diagram for TGenericFifo:
TFifo< TFileStreamJob *, 32 > TFifo< T, MaxItems >

Protected Types

enum  Flags_ : Flags { Flags_None = 0 , Flags_PollSemaphore = BITFLAG( 0 ) , Flags_NoSemaphore = BITFLAG( 1 ) }
 
typedef uint8_t Flags
 

Protected Member Functions

 TGenericFifo ()=default
 
TBOOL Create (TCHAR *a_pBuffer, TINT a_iMaxItems, TINT a_iItemSize)
 
TBOOL Destroy ()
 
TBOOL Push (void *a_pItem, Flags a_iFlags)
 
TBOOL Pop (void *a_pOut, Flags a_iFlags)
 

Detailed Description

Definition at line 10 of file TFifo.h.

Member Typedef Documentation

◆ Flags

typedef uint8_t TGenericFifo::Flags
protected

Definition at line 13 of file TFifo.h.

Member Enumeration Documentation

◆ Flags_

enum TGenericFifo::Flags_ : Flags
protected
Enumerator
Flags_None 
Flags_PollSemaphore 
Flags_NoSemaphore 

Definition at line 14 of file TFifo.h.

15 {
16 Flags_None = 0,
19 };
#define BITFLAG(x)
Definition Defines.h:10
@ Flags_None
Definition TFifo.h:16
@ Flags_NoSemaphore
Definition TFifo.h:18
@ Flags_PollSemaphore
Definition TFifo.h:17

Constructor & Destructor Documentation

◆ TGenericFifo()

TGenericFifo::TGenericFifo ( )
protecteddefault

Member Function Documentation

◆ Create()

TBOOL TGenericFifo::Create ( TCHAR * a_pBuffer,
TINT a_iMaxItems,
TINT a_iItemSize )
protected

Definition at line 12 of file TFifo.cpp.

13{
14 TASSERT( a_iMaxItems > 0, "Max items is less than zero" );
15 TASSERT( a_iItemSize > 0, "Item size is less than zero" );
16
17 m_iItemSize = a_iItemSize;
18 m_iMaxItems = a_iMaxItems;
19 m_pDataPopCursor = a_pBuffer;
20 m_pDataPushCursor = a_pBuffer;
21 m_pDataBegin = a_pBuffer;
22 m_pDataEnd = a_pBuffer + ( a_iMaxItems * a_iItemSize );
23
24 TBOOL bResult;
25 bResult = m_Semaphore1.Create( m_iMaxItems, m_iMaxItems );
26 TASSERT( bResult != TFALSE, "Unable to create semaphore for TGenericFifo" );
27 bResult = m_Semaphore2.Create( 0, m_iMaxItems );
28 TASSERT( bResult != TFALSE, "Unable to create semaphore for TGenericFifo" );
29
30 InitializeCriticalSection( &m_CriticalSection );
31 return TTRUE;
32}
#define TASSERT(X,...)
Definition Defines.h:138
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6

◆ Destroy()

TBOOL TGenericFifo::Destroy ( )
protected

Definition at line 34 of file TFifo.cpp.

35{
36 DeleteCriticalSection( &m_CriticalSection );
37 m_Semaphore1.Destroy();
38 m_Semaphore2.Destroy();
39 return TTRUE;
40}

◆ Pop()

TBOOL TGenericFifo::Pop ( void * a_pOut,
Flags a_iFlags )
protected

Definition at line 67 of file TFifo.cpp.

68{
69 TBOOL bResult = ( a_iFlags & Flags_PollSemaphore ) ? m_Semaphore2.Poll() : m_Semaphore2.Wait();
70 if ( !bResult ) return TFALSE;
71
72 EnterCriticalSection( &m_CriticalSection );
73
74 // Copy data to the output and move cursor
75 TUtil::MemCopy( a_pOut, m_pDataPopCursor, m_iItemSize );
76 m_pDataPopCursor += m_iItemSize;
77
78 if ( m_pDataPopCursor == m_pDataEnd )
79 {
80 // Set cursor to the beginning if reached the end
81 m_pDataPopCursor = m_pDataBegin;
82 }
83
84 LeaveCriticalSection( &m_CriticalSection );
85
86 bResult = m_Semaphore1.Signal();
87 TASSERT( bResult != TFALSE, "TSemaphore::Signal returned TFALSE" );
88
89 return TTRUE;
90}
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

◆ Push()

TBOOL TGenericFifo::Push ( void * a_pItem,
Flags a_iFlags )
protected

Definition at line 42 of file TFifo.cpp.

43{
44 TBOOL bResult = ( a_iFlags & Flags_PollSemaphore ) ? m_Semaphore1.Poll() : m_Semaphore1.Wait();
45 if ( !bResult ) return TFALSE;
46
47 EnterCriticalSection( &m_CriticalSection );
48
49 // Copy data to the buffer and move cursor
50 Toshi::TUtil::MemCopy( m_pDataPushCursor, a_pItem, m_iItemSize );
51 m_pDataPushCursor += m_iItemSize;
52
53 if ( m_pDataPushCursor == m_pDataEnd )
54 {
55 // Set cursor to the beginning if reached the end
56 m_pDataPushCursor = m_pDataBegin;
57 }
58
59 LeaveCriticalSection( &m_CriticalSection );
60
61 bResult = m_Semaphore2.Signal();
62 TASSERT( bResult != TFALSE, "TSemaphore::Signal returned TFALSE" );
63
64 return TTRUE;
65}

The documentation for this class was generated from the following files: