79 #if !defined( CBUF_H ) 90 #define CBUF_Init( cbuf ) cbuf.m_getIdx = cbuf.m_putIdx = 0 97 #define CBUF_Len( cbuf ) ((typeof( cbuf.m_putIdx ))(( cbuf.m_putIdx ) - ( cbuf.m_getIdx ))) 103 #define CBUF_Push( cbuf, elem ) (cbuf.m_entry)[ cbuf.m_putIdx++ & (( cbuf##_SIZE ) - 1 )] = (elem) 109 #define CBUF_Pop( cbuf ) (cbuf.m_entry)[ cbuf.m_getIdx++ & (( cbuf##_SIZE ) - 1 )] 115 #define CBUF_Get( cbuf, idx ) (cbuf.m_entry)[( cbuf.m_getIdx + idx ) & (( cbuf##_SIZE ) - 1 )] 121 #define CBUF_GetEnd( cbuf, idx ) (cbuf.m_entry)[( cbuf.m_putIdx - idx - 1 ) & (( cbuf##_SIZE ) - 1 )] 127 #define CBUF_IsEmpty( cbuf ) ( CBUF_Len( cbuf ) == 0 ) 133 #define CBUF_IsFull( cbuf ) ( CBUF_Len( cbuf ) == ( cbuf##_SIZE )) 139 #define CBUF_Error( cbuf ) ( CBUF_Len( cbuf ) > cbuf##_SIZE ) 145 #define CBUF_GetPtr( cbuf, idx ) ((typeof( &cbuf.m_entry[0]))( cbuf.m_entry + (( cbuf.m_getIdx + idx ) & (( cbuf##_SIZE ) - 1 )))) 151 #define CBUF_Remove( cbuf, idx ) ({cbuf.m_getIdx += ( idx );}) 153 #if defined( __cplusplus ) 155 template <
class IndexType,
unsigned Size,
class EntryType >
162 m_getIdx = m_putIdx = 0;
165 IndexType Len()
const {
return m_putIdx - m_getIdx; }
167 bool IsEmpty()
const {
return Len() == 0; }
168 bool IsFull()
const {
return Len() == Size; }
169 bool Error()
const {
return Len() > Size; }
171 void Push( EntryType val )
173 m_entry[ m_putIdx++ & ( Size - 1 )] = val;
178 return m_entry[ m_getIdx++ & ( Size - 1 )];
183 volatile IndexType m_getIdx;
184 volatile IndexType m_putIdx;
185 EntryType m_entry[ Size ];
189 #endif // __cplusplus