minor fixes

waio: ensure error is disk_full on failure
cache_adt: scaffolding code wrongly used std::remove_if instead of
list::remove. thanks to Echelon9 for catching this! fixes #1063

This was SVN commit r10818.
This commit is contained in:
janwas 2011-12-28 11:21:05 +00:00
parent 4946b079f3
commit c134221739
2 changed files with 15 additions and 19 deletions

View File

@ -538,8 +538,6 @@ public:
}
};
// TODO: use SSE/3DNow RCP instruction? not yet, because not all systems
// support it and overhead of detecting this support eats into any gains.
// initial implementation for testing purposes; quite inefficient.
template<typename Key, typename Entry>
@ -558,7 +556,7 @@ public:
bool find(const Key& key, const Entry** pentry) const
{
CIt it = std::find_if(lru.begin(), lru.end(), KeyEq(key));
CIt it = std::find(lru.begin(), lru.end(), KeyAndEntry(key));
if(it == lru.end())
return false;
*pentry = &it->entry;
@ -567,7 +565,7 @@ public:
void remove(const Key& key)
{
std::remove_if(lru.begin(), lru.end(), KeyEq(key));
lru.remove(KeyAndEntry(key));
}
void on_access(Entry& entry)
@ -593,20 +591,14 @@ public:
private:
struct KeyAndEntry
{
KeyAndEntry(const Key& key): key(key) {}
KeyAndEntry(const Key& key, const Entry& entry): key(key), entry(entry) {}
bool operator==(const KeyAndEntry& rhs) const { return key == rhs.key; }
bool operator!=(const KeyAndEntry& rhs) const { return !operator==(rhs); }
Key key;
Entry entry;
KeyAndEntry(const Key& key_, const Entry& entry_)
: key(key_), entry(entry_) {}
};
class KeyEq
{
Key key;
public:
KeyEq(const Key& key_) : key(key_) {}
bool operator()(const KeyAndEntry& ke) const
{
return ke.key == key;
}
};
typedef std::list<KeyAndEntry> List;

View File

@ -436,6 +436,8 @@ Status waio_close(int fd)
Status waio_Preallocate(int fd, off_t size)
{
WinScopedPreserveLastError s;
HANDLE hFile; // from FileControlBlock OR lowio
{
FileControlBlock* fcb = fileControlBlocks.FromDescriptor(fd);
@ -457,8 +459,11 @@ Status waio_Preallocate(int fd, off_t size)
WARN_IF_FALSE(SetFilePointerEx(hFile, size64, 0, FILE_BEGIN));
if(!SetEndOfFile(hFile))
{
debug_printf(L"Preallocate(%lld) failed: %d\n", size, GetLastError());
return ERR::FAIL; // NOWARN (probably not enough disk space)
if(GetLastError() == ERROR_DISK_FULL)
SetLastError(0);
else
debug_printf(L"waio_Preallocate(%lld) failed: %d\n", size, GetLastError());
return ERR::FAIL; // NOWARN (either out of disk space, or error was printed)
}
// avoid synchronous zero-fill (see discussion in header)
@ -472,7 +477,6 @@ Status waio_Preallocate(int fd, off_t size)
// verifying the filesystem is indeed FAT would be overkill; we'll just
// ignore the return code. however, GetLastError can be used to check
// whether other problems arose.
WinScopedPreserveLastError s;
(void)pSetFileValidData(hFile, alignedSize);
ENSURE(GetLastError() == 0);
}