Merge pull request #1108 from gaul/lock/diskspace

Always hold lock when accessing free_disk_space
This commit is contained in:
Takeshi Nakatani 2019-08-03 22:01:31 +09:00 committed by GitHub
commit 3d70e8966f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -1994,8 +1994,15 @@ bool FdManager::CheckCacheDirExist()
return true;
}
off_t FdManager::GetEnsureFreeDiskSpace()
{
AutoLock auto_lock(&FdManager::reserved_diskspace_lock);
return FdManager::free_disk_space;
}
off_t FdManager::SetEnsureFreeDiskSpace(off_t size)
{
AutoLock auto_lock(&FdManager::reserved_diskspace_lock);
off_t old = FdManager::free_disk_space;
FdManager::free_disk_space = size;
return old;
@ -2350,8 +2357,8 @@ void FdManager::CleanupCacheDirInternal(const std::string &path)
bool FdManager::ReserveDiskSpace(off_t size)
{
AutoLock auto_lock(&FdManager::reserved_diskspace_lock);
if(IsSafeDiskSpace(NULL, size)){
AutoLock auto_lock(&FdManager::reserved_diskspace_lock);
free_disk_space += size;
return true;
}

View File

@ -221,7 +221,7 @@ class FdManager
static bool SetCheckCacheDirExist(bool is_check);
static bool CheckCacheDirExist(void);
static off_t GetEnsureFreeDiskSpace(void) { return FdManager::free_disk_space; }
static off_t GetEnsureFreeDiskSpace();
static off_t SetEnsureFreeDiskSpace(off_t size);
static bool IsSafeDiskSpace(const char* path, off_t size);
static void FreeReservedDiskSpace(off_t size);