merged set_settings race condition fix into trunk

This commit is contained in:
Arvid Norberg 2012-04-06 03:02:50 +00:00
parent d7a3e823b5
commit 9024209d51
4 changed files with 11 additions and 10 deletions

View File

@ -44,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/shared_array.hpp> #include <boost/shared_array.hpp>
#include <deque> #include <deque>
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/thread.hpp" #include "libtorrent/thread.hpp"
#include "libtorrent/disk_buffer_pool.hpp" #include "libtorrent/disk_buffer_pool.hpp"

View File

@ -1751,20 +1751,22 @@ namespace libtorrent
m_log << log_time() << " update_settings " << std::endl; m_log << log_time() << " update_settings " << std::endl;
#endif #endif
TORRENT_ASSERT(j.buffer); TORRENT_ASSERT(j.buffer);
session_settings const& s = *((session_settings*)j.buffer); session_settings const* s = ((session_settings*)j.buffer);
TORRENT_ASSERT(s.cache_size >= 0); TORRENT_ASSERT(s->cache_size >= 0);
TORRENT_ASSERT(s.cache_expiry > 0); TORRENT_ASSERT(s->cache_expiry > 0);
#if defined TORRENT_WINDOWS #if defined TORRENT_WINDOWS
if (m_settings.low_prio_disk != s.low_prio_disk) if (m_settings.low_prio_disk != s->low_prio_disk)
{ {
m_file_pool.set_low_prio_io(s.low_prio_disk); m_file_pool.set_low_prio_io(s->low_prio_disk);
// we need to close all files, since the prio // we need to close all files, since the prio
// only takes affect when files are opened // only takes affect when files are opened
m_file_pool.release(0); m_file_pool.release(0);
} }
#endif #endif
m_settings = s; m_settings = *s;
delete s;
m_file_pool.resize(m_settings.file_pool_size); m_file_pool.resize(m_settings.file_pool_size);
#if defined __APPLE__ && defined __MACH__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 #if defined __APPLE__ && defined __MACH__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD

View File

@ -1865,7 +1865,7 @@ namespace aux {
void session_impl::update_disk_thread_settings() void session_impl::update_disk_thread_settings()
{ {
disk_io_job j; disk_io_job j;
j.buffer = (char*)&m_settings; j.buffer = (char*)new session_settings(m_settings);
j.action = disk_io_job::update_settings; j.action = disk_io_job::update_settings;
m_disk_thread.add_job(j); m_disk_thread.add_job(j);
} }

View File

@ -317,7 +317,7 @@ void run_elevator_test()
session_settings set; session_settings set;
set.use_read_cache = false; set.use_read_cache = false;
disk_io_job j; disk_io_job j;
j.buffer = (char*)&set; j.buffer = (char*)new session_settings(set);
j.action = disk_io_job::update_settings; j.action = disk_io_job::update_settings;
dio.add_job(j); dio.add_job(j);
@ -382,7 +382,7 @@ void run_elevator_test()
// test disabling disk-reordering // test disabling disk-reordering
set.allow_reordered_disk_operations = false; set.allow_reordered_disk_operations = false;
j.buffer = (char*)&set; j.buffer = (char*)new session_settings(set);
j.action = disk_io_job::update_settings; j.action = disk_io_job::update_settings;
dio.add_job(j); dio.add_job(j);