List:Commits« Previous MessageNext Message »
From:Jonas Oreland Date:October 27 2010 6:47am
Subject:bzr push into mysql-5.1-telco-7.1 branch (jonas:3922 to 3923)
View as plain text  
 3923 Jonas Oreland	2010-10-27 [merge]
      ndb - merge 70 to 71

    modified:
      storage/ndb/src/kernel/vm/DataBuffer.hpp
 3922 John David Duncan	2010-10-26 [merge]
      Merge

    modified:
      storage/ndb/src/ndbjtie/jtie/test/myapi/myapi_test.cpp
      storage/ndb/src/ndbjtie/mysql/test/mysql_utils_test.cpp
      storage/ndb/src/ndbjtie/test/test/MySqlUtilsCharsetMapTest.java
=== modified file 'storage/ndb/src/kernel/vm/DataBuffer.hpp'
--- a/storage/ndb/src/kernel/vm/DataBuffer.hpp	2009-12-18 13:55:40 +0000
+++ b/storage/ndb/src/kernel/vm/DataBuffer.hpp	2010-10-27 06:45:29 +0000
@@ -315,57 +315,60 @@ DataBuffer<sz>::DataBuffer(DataBufferPoo
 template<Uint32 sz>
 inline
 bool
-DataBuffer<sz>::seize(Uint32 n){
-  Uint32 rest; // Free space in last segment (currently)
-  Segment* prevPtr;
-
-  if(head.firstItem == RNIL){
-    rest = 0;
-    prevPtr = (Segment*)&head.firstItem;
-  } else {
-    rest = (sz - (head.used % sz)) % sz;
-    prevPtr = thePool.getPtr(head.lastItem);
+DataBuffer<sz>::seize(Uint32 n)
+{
+  Uint32 req = n;
+  Uint32 used = head.used;
+  Uint32 last = used % sz;            // (almost) used in last segment
+  Uint32 rest = last ? sz - last : 0; // Free in last segment
+
+  if (rest >= n)
+  {
+    /**
+     * No extra allocation needed
+     */
+    head.used = used + n;
+    return true;
   }
-  
+
+  n -= rest;
+
   /**
    * Check for space
    */
-  Uint32 free = thePool.getNoOfFree() * sz + rest;
-  if(n > free){
+  Uint32 free = thePool.getNoOfFree() * sz;
+  if (n > free)
+  {
     return false;
   }
-    
-  Uint32 used = head.used + n;
-  Ptr<Segment> currPtr; 
-  currPtr.i = head.lastItem;
   
-  while(n >= sz){
-    if(0)
-      ndbout_c("n(%d) %c sz(%d)", n, (n>sz?'>':(n<sz?'<':'=')), sz);    
-
-    thePool.seize(currPtr); assert(currPtr.i != RNIL);
-    prevPtr->nextPool = currPtr.i;
-	     
-    prevPtr = currPtr.p;
-    prevPtr->nextPool = RNIL;
+  Ptr<Segment> firstPtr;
+  thePool.seize(firstPtr);
+  Ptr<Segment> lastPtr = firstPtr;
+  
+  while (n > sz)
+  {
+    Ptr<Segment> tmp;
+    thePool.seize(tmp);
+    lastPtr.p->nextPool = tmp.i;
+    lastPtr = tmp;
     n -= sz;
   }
+  lastPtr.p->nextPool = RNIL;
   
-  if(0){
-    Uint32 pos = rest + n;
-    ndbout_c("rest(%d), n(%d) pos=%d %c sz(%d)", 
-	     rest, n, pos, (pos>sz?'>':(pos<sz?'<':'=')), sz);
+  head.used = used + req;
+  if (head.firstItem == RNIL)
+  {
+    head.firstItem = firstPtr.i;
+    assert(head.lastItem == RNIL);
   }
-  
-  if(n > rest){
-    thePool.seize(currPtr);
-    assert(currPtr.i != RNIL);
-    prevPtr->nextPool = currPtr.i;
-    currPtr.p->nextPool = RNIL;
+  else
+  {
+    Segment* tail = thePool.getPtr(head.lastItem);
+    assert(tail->nextPool == RNIL);
+    tail->nextPool = firstPtr.i;
   }
-  
-  head.used = used;
-  head.lastItem = currPtr.i;
+  head.lastItem = lastPtr.i;
   
 #if 0
   {


Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20101027064659-lcnxonnrq3kc4eo8.bundle
Thread
bzr push into mysql-5.1-telco-7.1 branch (jonas:3922 to 3923) Jonas Oreland27 Oct