18 #ifndef DATA_BUFFER_HPP
19 #define DATA_BUFFER_HPP
21 #include "ArrayPool.hpp"
35 NdbOut& print(NdbOut& out){
36 out <<
"[DataBuffer<" << sz <<
">::Segment this="
37 <<
this << dec <<
" nextPool= "
88 void print(FILE*)
const;
98 void print(FILE* out) {
99 fprintf(out,
"[DataBufferIterator curr.i=%d, data=%p, ind=%d, pos=%d]\n",
100 curr.i, (
void*) data, ind, pos);
103 inline bool isNull()
const {
return curr.isNull();}
104 inline void setNull() { curr.setNull(); data = 0; ind = pos = RNIL;}
114 inline bool isNull()
const {
return curr.isNull();}
115 inline void setNull() { curr.setNull(); data = 0; ind = pos = RNIL;}
158 bool append(
const Uint32* src, Uint32 len);
169 bool import(Uint32 pos,
const Uint32* src, Uint32 len);
200 return (it.pos + len < head.used);
221 const Uint32* src, Uint32 len){
227 for(; len > 0; len--){
235 Uint32 ind = (it.pos % sz);
236 Uint32 left = sz - ind;
240 memcpy(&p->data[ind], src, 4 * left);
245 p = thePool.
getPtr(p->nextPool);
248 memcpy(&p->data[ind], src, 4 * len);
260 Uint32 pos = head.used;
267 if ((b0 =
position(it, pos)) && (b1 =
import(it, src, len)))
272 ndbout_c(
"%u %u", b0, b1);
280 fprintf(out,
"[DataBuffer used=%d words, segmentsize=%d words",
283 if (head.firstItem == RNIL) {
284 fprintf(out,
": No segments seized.]\n");
291 ptr.i = head.firstItem;
294 for(; ptr.i != RNIL; ){
296 const Uint32 * rest = ptr.p->data;
297 for(Uint32
i = 0;
i<sz;
i++){
298 fprintf(out,
" H'%.8x", rest[
i]);
304 ptr.i = ptr.p->nextPool;
306 fprintf(out,
" ]\n");
320 Uint32 used = head.used;
321 Uint32 last = used % sz;
322 Uint32 rest = last ? sz - last : 0;
329 head.used = used +
n;
338 Uint32 free = thePool.getNoOfFree() * sz;
345 thePool.seize(firstPtr);
352 lastPtr.p->nextPool = tmp.i;
356 lastPtr.p->nextPool = RNIL;
358 head.used = used + req;
359 if (head.firstItem == RNIL)
361 head.firstItem = firstPtr.i;
362 assert(head.lastItem == RNIL);
366 Segment* tail = thePool.getPtr(head.lastItem);
367 assert(tail->nextPool == RNIL);
368 tail->nextPool = firstPtr.i;
370 head.lastItem = lastPtr.i;
374 ndbout_c(
"Before validate - %d", head.used);
376 assert(head.firstItem == RNIL);
377 assert(head.lastItem == RNIL);
380 tmp.i = head.firstItem;
381 for(Uint32
i = head.used;
i > sz;
i -= sz){
382 ndbout << tmp.i <<
" ";
383 tmp.p = thePool.getPtr(tmp.i);
384 tmp.i = tmp.p->nextPool;
386 ndbout_c(
"%d", tmp.i);
387 assert(head.lastItem == tmp.i);
389 ndbout_c(
"After validate");
399 Uint32 used = head.used + sz - 1;
400 if(head.firstItem != RNIL){
401 thePool.releaseList(used / sz, head.firstItem, head.lastItem);
403 head.firstItem = RNIL;
404 head.lastItem = RNIL;
419 it.curr.i = head.firstItem;
420 if(it.curr.i == RNIL){
424 thePool.getPtr(it.curr);
425 it.data = &it.curr.p->data[0];
438 if(it.ind < sz && it.pos < head.used){
442 if(it.pos < head.used){
443 it.curr.i = it.curr.p->nextPool;
445 if(it.curr.i == RNIL){
455 ErrorReporter::handleAssert(
"DataBuffer<sz>::next", __FILE__, __LINE__);
458 thePool.getPtr(it.curr);
459 it.data = &it.curr.p->data[0];
472 for (Uint32
i=0;
i<hops;
i++) {
478 if(it.pos + hops < head.used){
480 it.curr.i = it.curr.p->nextPool;
481 thePool.getPtr(it.curr);
489 it.data = &it.curr.p->data[it.ind];
493 it.curr.i = it.curr.p->nextPool;
494 thePool.getPtr(it.curr);
496 it.data = &it.curr.p->data[it.ind];
508 it.curr.i = head.firstItem;
509 if(it.curr.i == RNIL){
513 thePool.getPtr(it.curr);
514 it.data = &it.curr.p->data[0];
527 if(it.ind < sz && it.pos < head.used){
531 if(it.pos < head.used){
532 it.curr.i = it.curr.p->nextPool;
534 if(it.curr.i == RNIL){
544 ErrorReporter::handleAssert(
"DataBuffer<sz>::next", __FILE__, __LINE__);
547 thePool.getPtr(it.curr);
548 it.data = &it.curr.p->data[0];
561 for (Uint32
i=0;
i<hops;
i++) {
567 if(it.pos + hops < head.used){
569 it.curr.i = it.curr.p->nextPool;
570 thePool.getPtr(it.curr);
578 it.data = &it.curr.p->data[it.ind];
582 it.curr.i = it.curr.p->nextPool;
583 thePool.getPtr(it.curr);
585 it.data = &it.curr.p->data[it.ind];
604 return (head.used == 0);