21 #include <ndb_global.h>
60 Uint32 BlockSize = 128,
61 Uint32 MinRead = 1024,
62 Uint32 MaxRead = 1024,
63 Uint32 MaxWrite = 1024);
68 const char * valid()
const;
70 Uint32 getBufferSize()
const;
71 Uint32 getUsableSize()
const;
72 Uint32 * getStart()
const;
98 void updateWritePtr(Uint32 sz);
109 Uint32 getMinRead()
const {
return m_minRead;}
111 Uint32 getFreeSize()
const {
return m_free; }
146 m_minRead = m_maxRead = m_maxWrite = m_size = m_bufSize = m_free = 0;
147 m_buffer = m_start = 0;
152 align(Uint32 * ptr, Uint32 alignment,
bool downwards){
154 const UintPtr a = (UintPtr)ptr;
155 const UintPtr b = a % alignment;
158 return (Uint32 *)(a - b);
160 return (Uint32 *)(a + (b == 0 ? 0 : (alignment - b)));
181 m_minRead = (MinRead / Block) * Block;
182 m_maxRead = (MaxRead / Block) * Block;
183 m_maxWrite = MaxWrite;
185 m_start = align(Buffer, Block*4,
false);
186 Uint32 * stop = align(Buffer + Size - MaxWrite, Block*4,
true);
188 assert(((Uint64(stop) - Uint64(m_start)) >> 32) == 0);
189 m_size = Uint32(stop - m_start);
197 m_size = (m_size / m_minRead) * m_minRead;
200 ndbout_c(
"Block = %d MinRead = %d -> %d", Block*4, MinRead*4, m_minRead*4);
201 ndbout_c(
"Block = %d MaxRead = %d -> %d", Block*4, MaxRead*4, m_maxRead*4);
203 ndbout_c(
"Buffer = %d -> %d", Buffer, m_start);
204 ndbout_c(
"Buffer = %d Size = %d MaxWrite = %d -> %d",
205 Buffer, Size*4, MaxWrite*4, m_size*4);
208 m_readIndex = m_writeIndex = m_eof = 0;
217 m_readIndex = m_writeIndex = 0;
224 FsBuffer::valid()
const {
225 if(m_buffer == 0)
return "Null pointer buffer";
226 if(m_bufSize == 0)
return "Zero size buffer";
227 if(m_blockSize == 0)
return "Zero block size";
228 if(m_minRead < m_blockSize)
return "Min read less than block size";
229 if(m_maxRead < m_blockSize)
return "Max read less than block size";
230 if(m_maxRead < m_minRead)
return "Max read less than min read";
231 if(m_size == 0)
return "Zero usable space";
237 FsBuffer::getBufferSize()
const {
243 FsBuffer::getUsableSize()
const {
249 FsBuffer::getStart()
const {
257 Uint32 * Tp = m_start;
258 const Uint32 Tr = m_readIndex;
259 const Uint32 Tm = m_minRead;
260 const Uint32 Ts = m_size;
261 const Uint32 Tmw = m_maxRead;
263 Uint32 sz1 = m_size - m_free;
272 * sz = sz1 - (sz1 % Tm);
276 DEBUG(ndbout_c(
"getReadPtr() Tr: %d Tmw: %d Ts: %d Tm: %d sz1: %d -> %d",
277 Tr, Tmw, Ts, Tm, sz1, * sz));
285 DEBUG(ndbout_c(
"getReadPtr() Tr: %d Tmw: %d Ts: %d Tm: %d sz1: %d -> false",
286 Tr, Tmw, Ts, Tm, sz1));
295 DEBUG(ndbout_c(
"getReadPtr() Tr: %d Tmw: %d Ts: %d Tm: %d sz1: %d -> %d eof",
296 Tr, Tmw, Ts, Tm, sz1, * sz));
304 const Uint32 Tr = m_readIndex;
305 const Uint32 Ts = m_size;
308 m_readIndex = (Tr + sz) % Ts;
314 assert(sz <= m_maxWrite);
315 Uint32 * Tp = m_start;
316 const Uint32 Tw = m_writeIndex;
317 const Uint32 sz1 = m_free;
322 DEBUG(ndbout_c(
"getWritePtr(%d) Tw: %d sz1: %d -> true",
327 DEBUG(ndbout_c(
"getWritePtr(%d) Tw: %d sz1: %d -> false",
335 FsBuffer::updateWritePtr(Uint32 sz){
336 assert(sz <= m_maxWrite);
337 Uint32 * Tp = m_start;
338 const Uint32 Tw = m_writeIndex;
339 const Uint32 Ts = m_size;
341 const Uint32 Tnew = (Tw + sz);
345 DEBUG(ndbout_c(
"updateWritePtr(%d) m_writeIndex: %d",
350 memcpy(Tp, &Tp[Ts], (Tnew - Ts) << 2);
351 m_writeIndex = Tnew - Ts;
352 DEBUG(ndbout_c(
"updateWritePtr(%d) m_writeIndex: %d",