gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9752: Add support to load more than


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9752: Add support to load more than one pagesize. This is used to load files
Date: Wed, 19 Nov 2008 19:30:01 -0700
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9752
committer: address@hidden
branch nick: rtmp
timestamp: Wed 2008-11-19 19:30:01 -0700
message:
  Add support to load more than one pagesize. This is used to load files
  below the CACHE_LIMIT entirely into memory to prevent reloading.
modified:
  libnet/diskstream.cpp
  libnet/diskstream.h
=== modified file 'libnet/diskstream.cpp'
--- a/libnet/diskstream.cpp     2008-11-19 20:13:25 +0000
+++ b/libnet/diskstream.cpp     2008-11-20 02:30:01 +0000
@@ -135,13 +135,22 @@
 ///    than read(), which add buffering we don't need.
 ///    This offset must be a multipe of the pagesize.
 ///
-/// @param size The location in bytes in the file of the desired data.
+/// @param size The amount of bytes to read, often the filesize
+///            for smaller files below CACHE_LIMIT.
+///
+/// @param offset The location in bytes in the file of the desired data.
 ///
 /// @return A real pointer to the location of the data at the
 ///    location pointed to by the offset.
 boost::uint8_t *
 DiskStream::loadChunk(off_t offset)
 {
+    return loadChunk(_pagesize, offset);
+}
+
+boost::uint8_t *
+DiskStream::loadChunk(size_t size, off_t offset)
+{
 //    GNASH_REPORT_FUNCTION;
 
     log_debug("%s: offset is: %d", __FUNCTION__, offset);
@@ -151,6 +160,7 @@
        log_error("Bad pointer to memory for file %s!", _filespec);
        return 0;
     }
+
 #if 0
     /// We only map pages of pagesize, so if the offset is smaller
     /// than that, don't use it.
@@ -165,6 +175,7 @@
            log_debug("Adjusting offset from %d to %d so it's page aligned.",
                      offset, _offset);
        }
+       log_debug("Offset is page aligned already");
     }
 #endif
     
@@ -173,23 +184,22 @@
        /// to mmap() a new one. If we're still in the current mapped
        /// page, then just return the existing data pointer.
        if (_dataptr != 0) {
+           munmap(_dataptr, _pagesize);
+           _dataptr = 0;
+       }
+
 #if 0
-           // If the offset is less than what we already mmapped, we
-           boost::uint32_t diff = *reinterpret_cast<boost::uint32_t 
*>(_dataptr + offset);
-           if (diff < _pagesize) {
-               return _dataptr + _offset;
-               // unmap the old data before allocating a new chunk
-           } else {
-               munmap(_dataptr, _pagesize);
-               _dataptr = 0;
-           }
-#else
-               munmap(_dataptr, _pagesize);
-               _dataptr = 0;
+       // See if the page has alady been mapped in;
+       unsigned char vec[_pagesize];
+       mincore(offset, _pagesize, vec);
+       if (vec[i] & 0x1) {
+           // cached page is in memory
+       }
 #endif
+       if (size <= _pagesize) {
+           size = _pagesize;
        }
-       
-       _dataptr = static_cast<unsigned char *>(mmap(0, _pagesize,
+       _dataptr = static_cast<unsigned char *>(mmap(0, size,
                                                     PROT_READ, MAP_SHARED, 
_filefd, offset));
     } else {
        log_error (_("Couldn't load file %s"), _filespec);

=== modified file 'libnet/diskstream.h'
--- a/libnet/diskstream.h       2008-11-17 17:09:02 +0000
+++ b/libnet/diskstream.h       2008-11-20 02:30:01 +0000
@@ -164,10 +164,14 @@
     /// \brief Load a chunk of the file into memory
     ///                This offset must be a multipe of the pagesize.
     ///
-    /// @param size The location in bytes in the file of the desired data.
+    /// @param size The amount of bytes to read, often the filesize
+    ///                for smaller files below CACHE_LIMIT.
+    ///
+    /// @param offset The location in bytes in the file of the desired data.
     ///
     /// @return A real pointer to the location of the data at the
     ///                location pointed to by the offset.
+    boost::uint8_t *loadChunk(size_t size, off_t offset);
     boost::uint8_t *loadChunk(off_t size);
     boost::uint8_t *loadChunk() { return loadChunk(_offset); };
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]