Move buffer into Session
authorPhil Miller <mille121@illinois.edu>
Mon, 8 Jul 2013 19:41:25 +0000 (14:41 -0500)
committerPhil Miller <mille121@illinois.edu>
Tue, 20 Aug 2013 23:28:23 +0000 (18:28 -0500)
src/libs/ck-libs/io/ckio.C
src/libs/ck-libs/io/ckio.h

index a83e6d9137a07cebbad3a17243ddce4d015b3e73..9c02c72a326c72aa65fc06d1ba335ea741a06a50 100644 (file)
@@ -136,17 +136,41 @@ namespace Ck { namespace IO {
 
       class WriteSession : public CBase_WriteSession {
         FileToken file;
-        size_t sessionOffset;
+        size_t sessionOffset, myOffset;
         size_t sessionBytes, myBytes, myBytesWritten;
         CkCallback complete;
 
+        struct buffer {
+          std::vector<char> array;
+          int bytes_filled_so_far;
+
+          buffer() {
+            bytes_filled_so_far = 0;
+          }
+
+          void expect(size_t bytes) {
+            array.resize(bytes);
+          }
+
+          void insertData(const char *data, size_t length, size_t offset) {
+            char *dest = &array[offset];
+            memcpy(dest, data, length);
+
+            bytes_filled_so_far += length;
+          }
+
+          bool isFull() {
+            return bytes_filled_so_far == array.size();
+          }
+        };
+        std::map<size_t, struct buffer> bufferMap;
+
       public:
         WriteSession(FileToken file_, size_t offset_, size_t bytes_, CkCallback complete_)
           : file(file_), offset(offset_), bytes(bytes_), complete(complete_)
         { }
 
-        void forwardData(SessionToken token, const char *data, size_t bytes,
-                         size_t offset) {
+        void forwardData(const char *data, size_t bytes, size_t offset) {
           //files[token].bufferMap[(offset/stripeSize)*stripeSize] is the buffer to which this char should write to.
           CkAssert(offset + bytes <= files[token].bytes);
           // XXX: CkAssert(this is the right processor to receive this data)
@@ -155,7 +179,7 @@ namespace Ck { namespace IO {
           while(bytes > 0) {
             size_t stripeOffset = (offset/stripeSize)*stripeSize;
             size_t expectedBufferSize = std::min(files[token].bytes - stripeOffset, stripeSize);
-            struct impl::buffer & currentBuffer = files[token].bufferMap[stripeOffset];
+            buffer& currentBuffer = files[token].bufferMap[stripeOffset];
             size_t bytesInCurrentStripe = std::min(expectedBufferSize - offset%stripeSize, bytes);
 
             //check if buffer this element already exists in map. If not, insert and resize buffer to stripe size
index ca4fac3d6d95d8c8d531622d11f23655a184a05d..4589354a0897a09ffee5e5aeae6a0a42dff5b4ce 100644 (file)
@@ -57,41 +57,12 @@ namespace Ck { namespace IO {
   };
 
   namespace impl {  
-    struct buffer
-    {
-      std::vector<char> array;
-      int bytes_filled_so_far;
-    
-      buffer()
-      {
-       bytes_filled_so_far = 0;
-      }
-
-      void expect(size_t bytes)
-      {
-       array.resize(bytes);
-      }
-    
-      void insertData(const char *data, size_t length, size_t offset)
-      {
-       char *dest = &array[offset];
-       memcpy(dest, data, length);
-
-       bytes_filled_so_far += length;
-      }
-
-      bool isFull()
-      {
-       return bytes_filled_so_far == array.size();
-      }
-    };
     
     struct SessionInfo {
       FileToken file;
       size_t bytes, offset, total_written;
       int pesReady;
       CkCallback complete;
-      std::map<size_t, struct buffer> bufferMap;
 
       SessionInfo(FileToken file_, size_t bytes_, size_t offset_, CkCallback complete_)
         : file(file_), bytes(bytes_), offset(offset_), complete(complete_)