~ubuntu-branches/debian/experimental/libtorrent/experimental

« back to all changes in this revision

Viewing changes to src/data/chunk.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-03-31 10:31:05 UTC
  • mto: (4.1.4 gutsy) (6.2.1 squeeze) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070331103105-jzpp1rml6ud0ff75
Tags: upstream-0.11.4
ImportĀ upstreamĀ versionĀ 0.11.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
#include "config.h"
38
38
 
 
39
#include <algorithm>
39
40
#include <functional>
40
41
 
41
42
#include "torrent/exceptions.h"
140
141
}
141
142
 
142
143
void
143
 
Chunk::preload(uint32_t position, uint32_t length) {
 
144
Chunk::preload(uint32_t position, uint32_t length, bool useAdvise) {
144
145
  if (position >= m_chunkSize)
145
146
    throw internal_error("Chunk::preload(...) position > m_chunkSize.");
146
147
 
153
154
  do {
154
155
    data = itr.data();
155
156
 
156
 
    for (char* first = (char*)data.first, *last = (char*)data.first + data.second; first < last; first += 4096)
157
 
      volatile char __UNUSED touchChunk = *(char*)data.first;
 
157
    if (useAdvise) {
 
158
      itr.memory_chunk()->advise(itr.memory_chunk_first(), data.second, MemoryChunk::advice_willneed);
 
159
 
 
160
    } else {
 
161
      for (char* first = (char*)data.first, *last = (char*)data.first + data.second; first < last; first += 4096)
 
162
        volatile char __UNUSED touchChunk = *(char*)data.first;
 
163
 
 
164
      // Make sure we touch the last page in the range.
 
165
      volatile char __UNUSED touchChunk = *((char*)data.first + data.second - 1);
 
166
    }
158
167
 
159
168
  } while (itr.next());
160
169
}