Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef BT_DOUBLE_BUFFER_H
00018 #define BT_DOUBLE_BUFFER_H
00019
00020 #include "SpuFakeDma.h"
00021 #include "LinearMath/btScalar.h"
00022
00023
00025 template<class T, int size>
00026 class DoubleBuffer
00027 {
00028 #if defined(__SPU__) || defined(USE_LIBSPE2)
00029 ATTRIBUTE_ALIGNED128( T m_buffer0[size] ) ;
00030 ATTRIBUTE_ALIGNED128( T m_buffer1[size] ) ;
00031 #else
00032 T m_buffer0[size];
00033 T m_buffer1[size];
00034 #endif
00035
00036 T *m_frontBuffer;
00037 T *m_backBuffer;
00038
00039 unsigned int m_dmaTag;
00040 bool m_dmaPending;
00041 public:
00042 bool isPending() const { return m_dmaPending;}
00043 DoubleBuffer();
00044
00045 void init ();
00046
00047
00048 void backBufferDmaGet(uint64_t ea, unsigned int numBytes, unsigned int tag);
00049 void backBufferDmaPut(uint64_t ea, unsigned int numBytes, unsigned int tag);
00050
00051
00052 T *getFront();
00053 T *getBack();
00054
00055
00056
00057 T *swapBuffers();
00058 };
00059
00060 template<class T, int size>
00061 DoubleBuffer<T,size>::DoubleBuffer()
00062 {
00063 init ();
00064 }
00065
00066 template<class T, int size>
00067 void DoubleBuffer<T,size>::init()
00068 {
00069 this->m_dmaPending = false;
00070 this->m_frontBuffer = &this->m_buffer0[0];
00071 this->m_backBuffer = &this->m_buffer1[0];
00072 }
00073
00074 template<class T, int size>
00075 void
00076 DoubleBuffer<T,size>::backBufferDmaGet(uint64_t ea, unsigned int numBytes, unsigned int tag)
00077 {
00078 m_dmaPending = true;
00079 m_dmaTag = tag;
00080 if (numBytes)
00081 {
00082 m_backBuffer = (T*)cellDmaLargeGetReadOnly(m_backBuffer, ea, numBytes, tag, 0, 0);
00083 }
00084 }
00085
00086 template<class T, int size>
00087 void
00088 DoubleBuffer<T,size>::backBufferDmaPut(uint64_t ea, unsigned int numBytes, unsigned int tag)
00089 {
00090 m_dmaPending = true;
00091 m_dmaTag = tag;
00092 cellDmaLargePut(m_backBuffer, ea, numBytes, tag, 0, 0);
00093 }
00094
00095 template<class T, int size>
00096 T *
00097 DoubleBuffer<T,size>::getFront()
00098 {
00099 return m_frontBuffer;
00100 }
00101
00102 template<class T, int size>
00103 T *
00104 DoubleBuffer<T,size>::getBack()
00105 {
00106 return m_backBuffer;
00107 }
00108
00109 template<class T, int size>
00110 T *
00111 DoubleBuffer<T,size>::swapBuffers()
00112 {
00113 if (m_dmaPending)
00114 {
00115 cellDmaWaitTagStatusAll(1<<m_dmaTag);
00116 m_dmaPending = false;
00117 }
00118
00119 T *tmp = m_backBuffer;
00120 m_backBuffer = m_frontBuffer;
00121 m_frontBuffer = tmp;
00122
00123 return m_frontBuffer;
00124 }
00125
00126 #endif