fix race condition in disk I/O storage class

This commit is contained in:
arvidn 2017-05-07 11:01:42 -04:00 committed by Arvid Norberg
parent fe9f877087
commit 14dbd1c92d
3 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,4 @@
* fix race condition in disk I/O storage class
* fix http connection timeout on multi-homed hosts * fix http connection timeout on multi-homed hosts
* removed depdendency on boost::uintptr_t for better compatibility * removed depdendency on boost::uintptr_t for better compatibility
* fix memory leak in the disk cache * fix memory leak in the disk cache

View File

@ -476,6 +476,7 @@ namespace libtorrent
// whose bit is 0, we set the file size, to make the file allocated // whose bit is 0, we set the file size, to make the file allocated
// on disk (in full allocation mode) and just sparsely allocated in // on disk (in full allocation mode) and just sparsely allocated in
// case of sparse allocation mode // case of sparse allocation mode
mutable mutex m_file_created_mutex;
mutable bitfield m_file_created; mutable bitfield m_file_created;
bool m_allocate_files; bool m_allocate_files;

View File

@ -524,7 +524,10 @@ namespace libtorrent
m_allocate_files = false; m_allocate_files = false;
#endif #endif
m_file_created.resize(files().num_files(), false); {
mutex::scoped_lock l(m_file_created_mutex);
m_file_created.resize(files().num_files(), false);
}
// first, create all missing directories // first, create all missing directories
std::string last_path; std::string last_path;
@ -1494,6 +1497,7 @@ namespace libtorrent
if (m_allocate_files && (mode & file::rw_mask) != file::read_only) if (m_allocate_files && (mode & file::rw_mask) != file::read_only)
{ {
mutex::scoped_lock l(m_file_created_mutex);
if (m_file_created.size() != files().num_files()) if (m_file_created.size() != files().num_files())
m_file_created.resize(files().num_files(), false); m_file_created.resize(files().num_files(), false);
@ -1504,10 +1508,11 @@ namespace libtorrent
// the file right away, to allocate it on the filesystem. // the file right away, to allocate it on the filesystem.
if (m_file_created[file] == false) if (m_file_created[file] == false)
{ {
m_file_created.set_bit(file);
l.unlock();
error_code e; error_code e;
boost::int64_t const size = files().file_size(file); boost::int64_t const size = files().file_size(file);
h->set_size(size, e); h->set_size(size, e);
m_file_created.set_bit(file);
if (e) if (e)
{ {
ec.ec = e; ec.ec = e;