summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-08-11 23:38:58 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-08-11 23:38:58 +0900
commite2fcd6d72c577688160ce2ae3886edb67416525d (patch)
tree441af2d4f4729f0bd2c7a7f44859770545f07d5b /src
parent27e44439eaa94ec76abc79742d1bd8d122786cda (diff)
Use enum to select file allocation method
Diffstat (limited to 'src')
-rw-r--r--src/AbstractSingleDiskAdaptor.cc18
-rw-r--r--src/DefaultPieceStorage.cc2
-rw-r--r--src/DiskAdaptor.cc2
-rw-r--r--src/DiskAdaptor.h25
-rw-r--r--src/MultiFileAllocationIterator.cc18
5 files changed, 35 insertions, 30 deletions
diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc
index a6d23d74..2f92655c 100644
--- a/src/AbstractSingleDiskAdaptor.cc
+++ b/src/AbstractSingleDiskAdaptor.cc
@@ -98,20 +98,22 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length)
SharedHandle<FileAllocationIterator>
AbstractSingleDiskAdaptor::fileAllocationIterator()
{
+ switch(getFileAllocationMethod()) {
#ifdef HAVE_SOME_FALLOCATE
- if(doesFallocate()) {
+ case(DiskAdaptor::FILE_ALLOC_FALLOC): {
SharedHandle<FallocFileAllocationIterator> h
(new FallocFileAllocationIterator
(diskWriter_.get(), size() ,totalLength_));
return h;
- } else
+ }
#endif // HAVE_SOME_FALLOCATE
- {
- SharedHandle<AdaptiveFileAllocationIterator> h
- (new AdaptiveFileAllocationIterator
- (diskWriter_.get(), size(), totalLength_));
- return h;
- }
+ default: {
+ SharedHandle<AdaptiveFileAllocationIterator> h
+ (new AdaptiveFileAllocationIterator
+ (diskWriter_.get(), size(), totalLength_));
+ return h;
+ }
+ }
}
void AbstractSingleDiskAdaptor::enableReadOnly()
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 929359d3..036e9e10 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -634,7 +634,7 @@ void DefaultPieceStorage::initStorage()
diskAdaptor_ = multiDiskAdaptor;
}
if(option_->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
- diskAdaptor_->enableFallocate();
+ diskAdaptor_->setFileAllocationMethod(DiskAdaptor::FILE_ALLOC_FALLOC);
}
}
diff --git a/src/DiskAdaptor.cc b/src/DiskAdaptor.cc
index 12b42f66..abc70c6e 100644
--- a/src/DiskAdaptor.cc
+++ b/src/DiskAdaptor.cc
@@ -38,7 +38,7 @@
namespace aria2 {
DiskAdaptor::DiskAdaptor()
- : fallocate_(false)
+ : fileAllocationMethod_(FILE_ALLOC_ADAPTIVE)
{}
DiskAdaptor::~DiskAdaptor() {}
diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h
index 962f42d0..f81c8894 100644
--- a/src/DiskAdaptor.h
+++ b/src/DiskAdaptor.h
@@ -48,11 +48,12 @@ class FileEntry;
class FileAllocationIterator;
class DiskAdaptor:public BinaryStream {
-private:
- std::vector<SharedHandle<FileEntry> > fileEntries_;
-
- bool fallocate_;
public:
+ enum FileAllocationMethod {
+ FILE_ALLOC_ADAPTIVE,
+ FILE_ALLOC_FALLOC
+ };
+
DiskAdaptor();
virtual ~DiskAdaptor();
@@ -100,20 +101,20 @@ public:
// successfully changed.
virtual size_t utime(const Time& actime, const Time& modtime) = 0;
- void enableFallocate()
+ void setFileAllocationMethod(FileAllocationMethod method)
{
- fallocate_ = true;
+ fileAllocationMethod_ = method;
}
- void disableFallocate()
+ int getFileAllocationMethod() const
{
- fallocate_ = false;
+ return fileAllocationMethod_;
}
- bool doesFallocate() const
- {
- return fallocate_;
- }
+private:
+ std::vector<SharedHandle<FileEntry> > fileEntries_;
+
+ FileAllocationMethod fileAllocationMethod_;
};
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;
diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc
index e45c71e6..f17115fe 100644
--- a/src/MultiFileAllocationIterator.cc
+++ b/src/MultiFileAllocationIterator.cc
@@ -67,20 +67,22 @@ void MultiFileAllocationIterator::allocateChunk()
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
// Calling private function of MultiDiskAdaptor.
+ switch(diskAdaptor_->getFileAllocationMethod()) {
#ifdef HAVE_SOME_FALLOCATE
- if(diskAdaptor_->doesFallocate()) {
+ case(DiskAdaptor::FILE_ALLOC_FALLOC):
fileAllocationIterator_.reset
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(),
fileEntry->getLength()));
- } else
+ break;
#endif // HAVE_SOME_FALLOCATE
- {
- fileAllocationIterator_.reset
- (new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
- entry->size(),
- fileEntry->getLength()));
- }
+ default:
+ fileAllocationIterator_.reset
+ (new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
+ entry->size(),
+ fileEntry->getLength()));
+ break;
+ }
}
}
if(finished()) {