changeset 120:9a0d24a0706e main

Do not clear the buffer itself, its good enough to initialize the head/tail. Do not accept new values on push() if full.
author Bob Cook <bob@bobcookdev.com>
date Sat, 03 Dec 2011 16:33:39 -0800
parents 7f101cf9e62b
children e65210fe1cb0
files main/packages/common/util/cbuffer.h main/packages/common/util/cbuffer.inl
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/main/packages/common/util/cbuffer.h	Sat Dec 03 16:31:41 2011 -0800
+++ b/main/packages/common/util/cbuffer.h	Sat Dec 03 16:33:39 2011 -0800
@@ -93,8 +93,8 @@
 private:
 
         T_ELEM_TYPE m_buffer[ T_SIZE ];
-        volatile T_SIZE_TYPE m_head;
-        volatile T_SIZE_TYPE m_tail;
+        T_SIZE_TYPE m_head;
+        T_SIZE_TYPE m_tail;
 };
 
 // ----------------------------------------------------------------------------------------
--- a/main/packages/common/util/cbuffer.inl	Sat Dec 03 16:31:41 2011 -0800
+++ b/main/packages/common/util/cbuffer.inl	Sat Dec 03 16:33:39 2011 -0800
@@ -33,8 +33,7 @@
 
 template< typename T_ELEM_TYPE, typename T_SIZE_TYPE, int T_SIZE >
 inline cbuffer< T_ELEM_TYPE, T_SIZE_TYPE, T_SIZE >::cbuffer()
-    :   m_buffer()
-    ,   m_head( 0 )
+    :   m_head( 0 )
     ,   m_tail( 0 )
 {
 }
@@ -61,6 +60,11 @@
 template< typename T_ELEM_TYPE, typename T_SIZE_TYPE, int T_SIZE >
 inline void cbuffer< T_ELEM_TYPE, T_SIZE_TYPE, T_SIZE >::push( const T_ELEM_TYPE& element )
 {
+    if ( is_full() )
+    {
+        return;
+    }
+
     T_SIZE_TYPE tmp_head = ( m_head + 1 ) & ( T_SIZE - 1 );
 
     m_buffer[ tmp_head ] = element;
@@ -86,7 +90,10 @@
 template< typename T_ELEM_TYPE, typename T_SIZE_TYPE, int T_SIZE >
 inline T_ELEM_TYPE cbuffer< T_ELEM_TYPE, T_SIZE_TYPE, T_SIZE >::pop()
 {
-    m_tail = ( m_tail + 1 ) & ( T_SIZE - 1 );
+    if ( ! is_empty() )
+    {
+        m_tail = ( m_tail + 1 ) & ( T_SIZE - 1 );
+    }
     return m_buffer[ m_tail ];
 }
 
@@ -109,6 +116,5 @@
     m_tail = 0;
 }
 
-
 // ----------------------------------------------------------------------------------------