forked from premiere/premiere-libtorrent
Threads (#671)
use std::thread, std::mutex, std::condition_variable instead of pulling them in from boost.asio internals.
This commit is contained in:
parent
98fb7df56f
commit
20b41ad0b9
|
@ -107,7 +107,6 @@ set(sources
|
|||
magnet_uri
|
||||
parse_url
|
||||
ConvertUTF
|
||||
thread
|
||||
xml_parse
|
||||
version
|
||||
|
||||
|
|
1
Jamfile
1
Jamfile
|
@ -650,7 +650,6 @@ SOURCES =
|
|||
magnet_uri
|
||||
parse_url
|
||||
ConvertUTF
|
||||
thread
|
||||
xml_parse
|
||||
version
|
||||
peer_class
|
||||
|
|
|
@ -97,7 +97,6 @@ category_mapping = {
|
|||
'sha1_hash.hpp': 'Utility',
|
||||
'hasher.hpp': 'Utility',
|
||||
'identify_client.hpp': 'Utility',
|
||||
'thread.hpp': 'Utility',
|
||||
'ip_filter.hpp': 'Filter',
|
||||
'session_settings.hpp': 'Settings',
|
||||
'settings_pack.hpp': 'Settings',
|
||||
|
|
|
@ -37,12 +37,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
#include <boost/array.hpp>
|
||||
|
@ -801,10 +801,10 @@ void generate_torrent(std::vector<char>& buf, int size, int num_files
|
|||
libtorrent::create_torrent t(fs, piece_size);
|
||||
|
||||
// generate the hashes in 4 threads
|
||||
thread t1(boost::bind(&hasher_thread, &t, 0, 1 * num_pieces / 4, piece_size, false));
|
||||
thread t2(boost::bind(&hasher_thread, &t, 1 * num_pieces / 4, 2 * num_pieces / 4, piece_size, false));
|
||||
thread t3(boost::bind(&hasher_thread, &t, 2 * num_pieces / 4, 3 * num_pieces / 4, piece_size, false));
|
||||
thread t4(boost::bind(&hasher_thread, &t, 3 * num_pieces / 4, 4 * num_pieces / 4, piece_size, true));
|
||||
std::thread t1(&hasher_thread, &t, 0, 1 * num_pieces / 4, piece_size, false);
|
||||
std::thread t2(&hasher_thread, &t, 1 * num_pieces / 4, 2 * num_pieces / 4, piece_size, false);
|
||||
std::thread t3(&hasher_thread, &t, 2 * num_pieces / 4, 3 * num_pieces / 4, piece_size, false);
|
||||
std::thread t4(&hasher_thread, &t, 3 * num_pieces / 4, 4 * num_pieces / 4, piece_size, true);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
@ -1045,7 +1045,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
std::vector<peer_conn*> conns;
|
||||
conns.reserve(num_connections);
|
||||
const int num_threads = 2;
|
||||
int const num_threads = 2;
|
||||
io_service ios[num_threads];
|
||||
for (int i = 0; i < num_connections; ++i)
|
||||
{
|
||||
|
@ -1064,8 +1064,8 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
thread t1(boost::bind(&io_thread, &ios[0]));
|
||||
thread t2(boost::bind(&io_thread, &ios[1]));
|
||||
std::thread t1(&io_thread, &ios[0]);
|
||||
std::thread t2(&io_thread, &ios[1]);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
|
|
@ -128,7 +128,6 @@ nobase_include_HEADERS = \
|
|||
storage_defs.hpp \
|
||||
tailqueue.hpp \
|
||||
string_util.hpp \
|
||||
thread.hpp \
|
||||
thread_pool.hpp \
|
||||
time.hpp \
|
||||
timestamp_history.hpp \
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/alert.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/heterogeneous_queue.hpp"
|
||||
#include "libtorrent/stack_allocator.hpp"
|
||||
|
||||
|
@ -49,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/config.hpp>
|
||||
#include <list>
|
||||
#include <utility> // for std::forward
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
|
@ -74,7 +75,7 @@ namespace libtorrent {
|
|||
template <class T, typename... Args>
|
||||
void emplace_alert(Args&&... args)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (m_dispatch)
|
||||
{
|
||||
|
@ -102,7 +103,7 @@ namespace libtorrent {
|
|||
template <class T>
|
||||
bool should_post() const
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_alerts[m_generation].size() >= m_queue_size_limit
|
||||
* (1 + T::priority))
|
||||
{
|
||||
|
@ -115,13 +116,13 @@ namespace libtorrent {
|
|||
|
||||
void set_alert_mask(boost::uint32_t m)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_alert_mask = m;
|
||||
}
|
||||
|
||||
boost::uint32_t alert_mask() const
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_alert_mask;
|
||||
}
|
||||
|
||||
|
@ -144,10 +145,10 @@ namespace libtorrent {
|
|||
alert_manager(alert_manager const&);
|
||||
alert_manager& operator=(alert_manager const&);
|
||||
|
||||
void maybe_notify(alert* a, mutex::scoped_lock& lock);
|
||||
void maybe_notify(alert* a, std::unique_lock<std::mutex>& lock);
|
||||
|
||||
mutable mutex m_mutex;
|
||||
condition_variable m_condition;
|
||||
mutable std::mutex m_mutex;
|
||||
std::condition_variable m_condition;
|
||||
boost::uint32_t m_alert_mask;
|
||||
int m_queue_size_limit;
|
||||
|
||||
|
@ -171,7 +172,7 @@ namespace libtorrent {
|
|||
int m_generation;
|
||||
|
||||
// this is where all alerts are queued up. There are two heterogenous
|
||||
// queues to double buffer the thread access. The mutex in the alert
|
||||
// queues to double buffer the thread access. The std::mutex in the alert
|
||||
// manager gives exclusive access to m_alerts[m_generation] and
|
||||
// m_allocations[m_generation] whereas the other copy is exclusively
|
||||
// used by the client thread.
|
||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_SESSION_CALL_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/aux_/session_impl.hpp"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
|
@ -44,13 +43,13 @@ namespace libtorrent { namespace aux {
|
|||
void blocking_call();
|
||||
void dump_call_profile();
|
||||
|
||||
void fun_wrap(bool& done, condition_variable& e, mutex& m, boost::function<void(void)> f);
|
||||
void fun_wrap(bool& done, std::condition_variable& e, std::mutex& m, boost::function<void(void)> f);
|
||||
|
||||
template <class R>
|
||||
void fun_ret(R& ret, bool& done, condition_variable& e, mutex& m, boost::function<R(void)> f)
|
||||
void fun_ret(R& ret, bool& done, std::condition_variable& e, std::mutex& m, boost::function<R(void)> f)
|
||||
{
|
||||
ret = f();
|
||||
mutex::scoped_lock l(m);
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
done = true;
|
||||
e.notify_all();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <stdarg.h> // for va_start, va_end
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -76,7 +78,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/disk_io_thread.hpp"
|
||||
#include "libtorrent/udp_socket.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/alert_manager.hpp" // for alert_manager
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/socket_io.hpp" // for print_address
|
||||
|
@ -609,8 +610,8 @@ namespace libtorrent
|
|||
|
||||
// used when posting synchronous function
|
||||
// calls to session_impl and torrent objects
|
||||
mutable libtorrent::mutex mut;
|
||||
mutable libtorrent::condition_variable cond;
|
||||
mutable std::mutex mut;
|
||||
mutable std::condition_variable cond;
|
||||
|
||||
// cork a peer and schedule a delayed uncork
|
||||
// does nothing if the peer is already corked
|
||||
|
|
|
@ -45,7 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/bandwidth_limit.hpp"
|
||||
#include "libtorrent/bandwidth_queue_entry.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/bandwidth_socket.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#if defined TORRENT_ASIO_DEBUGGING
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
@ -75,7 +74,7 @@ namespace libtorrent
|
|||
// defined in session_impl.cpp
|
||||
extern std::map<std::string, async_t> _async_ops;
|
||||
extern int _async_ops_nthreads;
|
||||
extern mutex _async_ops_mutex;
|
||||
extern std::mutex _async_ops_mutex;
|
||||
|
||||
// timestamp -> operation
|
||||
struct wakeup_t
|
||||
|
@ -88,14 +87,14 @@ namespace libtorrent
|
|||
|
||||
inline bool has_outstanding_async(char const* name)
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
std::map<std::string, async_t>::iterator i = _async_ops.find(name);
|
||||
return i != _async_ops.end();
|
||||
}
|
||||
|
||||
inline void add_outstanding_async(char const* name)
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
async_t& a = _async_ops[name];
|
||||
if (a.stack.empty())
|
||||
{
|
||||
|
@ -113,7 +112,7 @@ namespace libtorrent
|
|||
|
||||
inline void complete_async(char const* name)
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
async_t& a = _async_ops[name];
|
||||
TORRENT_ASSERT(a.refs > 0);
|
||||
--a.refs;
|
||||
|
@ -139,19 +138,19 @@ namespace libtorrent
|
|||
|
||||
inline void async_inc_threads()
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
++_async_ops_nthreads;
|
||||
}
|
||||
|
||||
inline void async_dec_threads()
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
--_async_ops_nthreads;
|
||||
}
|
||||
|
||||
inline int log_async()
|
||||
{
|
||||
mutex::scoped_lock l(_async_ops_mutex);
|
||||
std::lock_guard<std::mutex> l(_async_ops_mutex);
|
||||
int ret = 0;
|
||||
for (std::map<std::string, async_t>::iterator i = _async_ops.begin()
|
||||
, end(_async_ops.end()); i != end; ++i)
|
||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
@ -53,7 +54,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/io_service_fwd.hpp"
|
||||
#include "libtorrent/file.hpp" // for iovec_t
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace libtorrent
|
|||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
bool is_disk_buffer(char* buffer
|
||||
, mutex::scoped_lock& l) const;
|
||||
, std::unique_lock<std::mutex>& l) const;
|
||||
bool is_disk_buffer(char* buffer) const;
|
||||
#endif
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace libtorrent
|
|||
|
||||
boost::uint32_t in_use() const
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
return m_in_use;
|
||||
}
|
||||
boost::uint32_t num_to_evict(int num_needed = 0);
|
||||
|
@ -100,8 +100,8 @@ namespace libtorrent
|
|||
|
||||
protected:
|
||||
|
||||
void free_buffer_impl(char* buf, mutex::scoped_lock& l);
|
||||
char* allocate_buffer_impl(mutex::scoped_lock& l, char const* category);
|
||||
void free_buffer_impl(char* buf, std::unique_lock<std::mutex>& l);
|
||||
char* allocate_buffer_impl(std::unique_lock<std::mutex>& l, char const* category);
|
||||
|
||||
// number of bytes per block. The BitTorrent
|
||||
// protocol defines the block size to 16 KiB.
|
||||
|
@ -137,9 +137,9 @@ namespace libtorrent
|
|||
|
||||
private:
|
||||
|
||||
void check_buffer_level(mutex::scoped_lock& l);
|
||||
void check_buffer_level(std::unique_lock<std::mutex>& l);
|
||||
|
||||
mutable mutex m_pool_mutex;
|
||||
mutable std::mutex m_pool_mutex;
|
||||
|
||||
int m_cache_buffer_chunk_size;
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/disk_interface.hpp"
|
||||
#include "libtorrent/performance_counters.hpp"
|
||||
#include "libtorrent/aux_/session_settings.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
@ -54,7 +53,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/shared_array.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <deque>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
#include <boost/pool/pool.hpp>
|
||||
#endif
|
||||
|
@ -452,7 +453,7 @@ namespace libtorrent
|
|||
void fail_jobs(storage_error const& e, jobqueue_t& jobs_);
|
||||
void fail_jobs_impl(storage_error const& e, jobqueue_t& src, jobqueue_t& dst);
|
||||
|
||||
void check_cache_level(mutex::scoped_lock& l, jobqueue_t& completed_jobs);
|
||||
void check_cache_level(std::unique_lock<std::mutex>& l, jobqueue_t& completed_jobs);
|
||||
|
||||
void perform_job(disk_io_job* j, jobqueue_t& completed_jobs);
|
||||
|
||||
|
@ -461,11 +462,11 @@ namespace libtorrent
|
|||
void add_fence_job(piece_manager* storage, disk_io_job* j
|
||||
, bool user_add = true);
|
||||
|
||||
// assumes l is locked (cache mutex).
|
||||
// assumes l is locked (cache std::mutex).
|
||||
// writes out the blocks [start, end) (releases the lock
|
||||
// during the file operation)
|
||||
int flush_range(cached_piece_entry* p, int start, int end
|
||||
, jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
|
||||
// low level flush operations, used by flush_range
|
||||
int build_iovec(cached_piece_entry* pe, int start, int end
|
||||
|
@ -477,12 +478,12 @@ namespace libtorrent
|
|||
, storage_error const& error
|
||||
, jobqueue_t& completed_jobs);
|
||||
|
||||
// assumes l is locked (the cache mutex).
|
||||
// assumes l is locked (the cache std::mutex).
|
||||
// assumes pe->hash to be set.
|
||||
// If there are new blocks in piece 'pe' that have not been
|
||||
// hashed by the partial_hash object attached to this piece,
|
||||
// the piece will
|
||||
void kick_hasher(cached_piece_entry* pe, mutex::scoped_lock& l);
|
||||
void kick_hasher(cached_piece_entry* pe, std::unique_lock<std::mutex>& l);
|
||||
|
||||
// flags to pass in to flush_cache()
|
||||
enum flush_flags_t
|
||||
|
@ -498,13 +499,13 @@ namespace libtorrent
|
|||
// used for asserts and only applies for fence jobs
|
||||
flush_expect_clear = 8
|
||||
};
|
||||
void flush_cache(piece_manager* storage, boost::uint32_t flags, jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
void flush_expired_write_blocks(jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
void flush_piece(cached_piece_entry* pe, int flags, jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
void flush_cache(piece_manager* storage, boost::uint32_t flags, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
void flush_expired_write_blocks(jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
void flush_piece(cached_piece_entry* pe, int flags, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
|
||||
int try_flush_hashed(cached_piece_entry* p, int cont_blocks, jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
int try_flush_hashed(cached_piece_entry* p, int cont_blocks, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
|
||||
void try_flush_write_blocks(int num, jobqueue_t& completed_jobs, mutex::scoped_lock& l);
|
||||
void try_flush_write_blocks(int num, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
|
||||
|
||||
// used to batch reclaiming of blocks to once per cycle
|
||||
void commit_reclaimed_blocks();
|
||||
|
@ -528,7 +529,7 @@ namespace libtorrent
|
|||
boost::atomic<int> m_num_running_threads;
|
||||
|
||||
// the actual threads running disk jobs
|
||||
std::vector<boost::shared_ptr<thread> > m_threads;
|
||||
std::vector<std::thread> m_threads;
|
||||
|
||||
aux::session_settings m_settings;
|
||||
|
||||
|
@ -545,7 +546,7 @@ namespace libtorrent
|
|||
file_pool m_file_pool;
|
||||
|
||||
// disk cache
|
||||
mutable mutex m_cache_mutex;
|
||||
mutable std::mutex m_cache_mutex;
|
||||
block_cache m_disk_cache;
|
||||
enum
|
||||
{
|
||||
|
@ -580,10 +581,10 @@ namespace libtorrent
|
|||
|
||||
// used to wake up the disk IO thread when there are new
|
||||
// jobs on the job queue (m_queued_jobs)
|
||||
condition_variable m_job_cond;
|
||||
std::condition_variable m_job_cond;
|
||||
|
||||
// mutex to protect the m_queued_jobs list
|
||||
mutable mutex m_job_mutex;
|
||||
// std::mutex to protect the m_queued_jobs list
|
||||
mutable std::mutex m_job_mutex;
|
||||
|
||||
// jobs queued for servicing
|
||||
jobqueue_t m_queued_jobs;
|
||||
|
@ -591,7 +592,7 @@ namespace libtorrent
|
|||
// when using more than 2 threads, this is
|
||||
// used for just hashing jobs, just for threads
|
||||
// dedicated to do hashing
|
||||
condition_variable m_hash_job_cond;
|
||||
std::condition_variable m_hash_job_cond;
|
||||
jobqueue_t m_queued_hash_jobs;
|
||||
|
||||
// used to rate limit disk performance warnings
|
||||
|
@ -602,12 +603,12 @@ namespace libtorrent
|
|||
// a message is posted to the network thread, which
|
||||
// will then drain the queue and execute the jobs'
|
||||
// handler functions
|
||||
mutex m_completed_jobs_mutex;
|
||||
std::mutex m_completed_jobs_mutex;
|
||||
jobqueue_t m_completed_jobs;
|
||||
|
||||
// these are blocks that have been returned by the main thread
|
||||
// but they haven't been freed yet. This is used to batch
|
||||
// reclaiming of blocks, to only need one mutex lock per cycle
|
||||
// reclaiming of blocks, to only need one std::mutex lock per cycle
|
||||
std::vector<block_cache_reference> m_blocks_to_reclaim;
|
||||
|
||||
// when this is true, there is an outstanding message in the
|
||||
|
|
|
@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_DISK_JOB_POOL
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <mutex>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
@ -68,7 +68,7 @@ namespace libtorrent
|
|||
// total number of in-use write jobs
|
||||
int m_write_jobs;
|
||||
|
||||
mutex m_job_mutex;
|
||||
std::mutex m_job_mutex;
|
||||
boost::pool<> m_job_pool;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -59,24 +59,20 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
// dead locks and race conditions. Since a plugin has access to internal
|
||||
// structures it is also quite easy to sabotage libtorrent's operation.
|
||||
//
|
||||
// All the callbacks in this interface are called with the main libtorrent thread
|
||||
// mutex locked. And they are always called from the libtorrent network thread. In
|
||||
// All the callbacks are always called from the libtorrent network thread. In
|
||||
// case portions of your plugin are called from other threads, typically the main
|
||||
// thread, you cannot use any of the member functions on the internal structures
|
||||
// in libtorrent, since those require the mutex to be locked. Furthermore, you would
|
||||
// also need to have a mutex on your own shared data within the plugin, to make
|
||||
// sure it is not accessed at the same time from the libtorrent thread (through a
|
||||
// callback). See `boost thread's mutex`_. If you need to send out a message from
|
||||
// another thread, it is advised to use an internal queue, and do the actual
|
||||
// sending in ``tick()``.
|
||||
// callback). If you need to send out a message from another thread, it is
|
||||
// advised to use an internal queue, and do the actual sending in ``tick()``.
|
||||
//
|
||||
// Since the plugin interface gives you easy access to internal structures, it
|
||||
// is not supported as a stable API. Plugins should be considered specific to a
|
||||
// specific version of libtorrent. Although, in practice the internals mostly
|
||||
// don't change that dramatically.
|
||||
//
|
||||
// .. _`boost thread's mutex`: http://www.boost.org/doc/html/mutex.html
|
||||
//
|
||||
//
|
||||
// plugin-interface
|
||||
// ================
|
||||
|
|
|
@ -242,7 +242,7 @@ namespace libtorrent
|
|||
|
||||
// open the file for reading and writing
|
||||
read_write = 2,
|
||||
|
||||
|
||||
// the mask for the bits determining read or write mode
|
||||
rw_mask = read_only | write_only | read_write,
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_FILE_POOL_HPP
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/file_storage.hpp"
|
||||
#include "libtorrent/aux_/time.hpp"
|
||||
|
||||
|
@ -120,7 +120,7 @@ namespace libtorrent
|
|||
|
||||
private:
|
||||
|
||||
void remove_oldest(mutex::scoped_lock& l);
|
||||
void remove_oldest(std::unique_lock<std::mutex>& l);
|
||||
|
||||
int m_size;
|
||||
bool m_low_prio_io;
|
||||
|
@ -137,12 +137,12 @@ namespace libtorrent
|
|||
// maps storage pointer, file index pairs to the
|
||||
// lru entry for the file
|
||||
typedef std::map<std::pair<void*, int>, lru_file_entry> file_set;
|
||||
|
||||
|
||||
file_set m_files;
|
||||
#if TORRENT_USE_ASSERTS
|
||||
std::vector<std::pair<std::string, void const*> > m_deleted_storages;
|
||||
#endif
|
||||
mutable mutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/udp_socket.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/aux_/array_view.hpp"
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
|
||||
#include <libtorrent/config.hpp>
|
||||
#include <libtorrent/kademlia/dht_storage.hpp>
|
||||
|
@ -51,7 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <libtorrent/socket.hpp> // for udp::endpoint
|
||||
#include <libtorrent/session_settings.hpp>
|
||||
#include <libtorrent/assert.hpp>
|
||||
#include <libtorrent/thread.hpp>
|
||||
#include <libtorrent/bloom_filter.hpp>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
@ -182,13 +182,13 @@ public:
|
|||
|
||||
void add_traversal_algorithm(traversal_algorithm* a)
|
||||
{
|
||||
mutex_t::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
m_running_requests.insert(a);
|
||||
}
|
||||
|
||||
void remove_traversal_algorithm(traversal_algorithm* a)
|
||||
{
|
||||
mutex_t::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
m_running_requests.erase(a);
|
||||
}
|
||||
|
||||
|
@ -231,8 +231,7 @@ private:
|
|||
|
||||
libtorrent::dht_settings const& m_settings;
|
||||
|
||||
typedef libtorrent::mutex mutex_t;
|
||||
mutex_t m_mutex;
|
||||
std::mutex m_mutex;
|
||||
|
||||
// this list must be destructed after the rpc manager
|
||||
// since it might have references to it
|
||||
|
|
|
@ -36,9 +36,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/io_service_fwd.hpp"
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
@ -75,22 +77,22 @@ public:
|
|||
void close();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
boost::shared_ptr<natpmp> self() { return shared_from_this(); }
|
||||
|
||||
void update_mapping(int i, mutex::scoped_lock& l);
|
||||
void send_map_request(int i, mutex::scoped_lock& l);
|
||||
void send_get_ip_address_request(mutex::scoped_lock& l);
|
||||
void update_mapping(int i, std::unique_lock<std::mutex>& l);
|
||||
void send_map_request(int i, std::unique_lock<std::mutex>& l);
|
||||
void send_get_ip_address_request(std::unique_lock<std::mutex>& l);
|
||||
void resend_request(int i, error_code const& e);
|
||||
void on_reply(error_code const& e
|
||||
, std::size_t bytes_transferred);
|
||||
void try_next_mapping(int i, mutex::scoped_lock& l);
|
||||
void update_expiration_timer(mutex::scoped_lock& l);
|
||||
void try_next_mapping(int i, std::unique_lock<std::mutex>& l);
|
||||
void update_expiration_timer(std::unique_lock<std::mutex>& l);
|
||||
void mapping_expired(error_code const& e, int i);
|
||||
void close_impl(mutex::scoped_lock& l);
|
||||
void close_impl(std::unique_lock<std::mutex>& l);
|
||||
|
||||
void log(char const* msg, mutex::scoped_lock& l);
|
||||
void disable(error_code const& ec, mutex::scoped_lock& l);
|
||||
void log(char const* msg, std::unique_lock<std::mutex>& l);
|
||||
void disable(error_code const& ec, std::unique_lock<std::mutex>& l);
|
||||
|
||||
struct mapping_t
|
||||
{
|
||||
|
@ -133,7 +135,7 @@ private:
|
|||
log_callback_t m_log_callback;
|
||||
|
||||
std::vector<mapping_t> m_mappings;
|
||||
|
||||
|
||||
// the endpoint to the nat router
|
||||
udp::endpoint m_nat_endpoint;
|
||||
|
||||
|
@ -145,7 +147,7 @@ private:
|
|||
// current retry count
|
||||
int m_retry_count;
|
||||
|
||||
// used to receive responses in
|
||||
// used to receive responses in
|
||||
char m_response_buffer[16];
|
||||
|
||||
// router external IP address
|
||||
|
@ -153,7 +155,7 @@ private:
|
|||
|
||||
// the endpoint we received the message from
|
||||
udp::endpoint m_remote;
|
||||
|
||||
|
||||
// the udp socket used to communicate
|
||||
// with the NAT router
|
||||
udp::socket m_socket;
|
||||
|
@ -167,12 +169,13 @@ private:
|
|||
|
||||
// the mapping index that will expire next
|
||||
int m_next_refresh;
|
||||
|
||||
|
||||
bool m_disabled;
|
||||
|
||||
bool m_abort;
|
||||
|
||||
mutable mutex m_mutex;
|
||||
// TODO:3 is this object really acceessed from multiple threads?
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
|
@ -42,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/thread.hpp" // for mutex
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ namespace libtorrent
|
|||
// this mutex must be held while accessing the data
|
||||
// structure. Not while reading or writing from the file though!
|
||||
// it's important to support multithreading
|
||||
mutex m_mutex;
|
||||
std::mutex m_mutex;
|
||||
|
||||
// this is a list of unallocated slots in the part file
|
||||
// within the m_num_allocated range
|
||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_PERFORMANCE_COUNTERS_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
@ -457,7 +456,7 @@ namespace libtorrent
|
|||
#else
|
||||
// if the atomic type is't lock-free, use a single lock instead, for
|
||||
// the whole array
|
||||
mutable mutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
boost::int64_t m_stats_counter[num_counters];
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
@ -51,7 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/session_handle.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
#include "libtorrent/fingerprint.hpp"
|
||||
|
@ -131,14 +131,14 @@ namespace libtorrent
|
|||
private:
|
||||
session_proxy(
|
||||
boost::shared_ptr<io_service> ios
|
||||
, boost::shared_ptr<thread> t
|
||||
, std::shared_ptr<std::thread> t
|
||||
, boost::shared_ptr<aux::session_impl> impl)
|
||||
: m_io_service(ios)
|
||||
, m_thread(t)
|
||||
, m_impl(impl)
|
||||
{}
|
||||
boost::shared_ptr<io_service> m_io_service;
|
||||
boost::shared_ptr<thread> m_thread;
|
||||
std::shared_ptr<std::thread> m_thread;
|
||||
boost::shared_ptr<aux::session_impl> m_impl;
|
||||
};
|
||||
|
||||
|
@ -289,7 +289,7 @@ namespace libtorrent
|
|||
// data shared between the main thread
|
||||
// and the working thread
|
||||
boost::shared_ptr<io_service> m_io_service;
|
||||
boost::shared_ptr<thread> m_thread;
|
||||
std::shared_ptr<std::thread> m_thread;
|
||||
boost::shared_ptr<aux::session_impl> m_impl;
|
||||
};
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <sys/types.h>
|
||||
#include <boost/function/function2.hpp>
|
||||
#include <boost/function/function0.hpp>
|
||||
|
@ -55,7 +56,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/disk_buffer_holder.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/storage_defs.hpp"
|
||||
#include "libtorrent/allocator.hpp"
|
||||
#include "libtorrent/file_pool.hpp" // pool_file_status
|
||||
|
@ -589,7 +589,7 @@ namespace libtorrent
|
|||
|
||||
// must be held when accessing m_has_fence and
|
||||
// m_blocked_jobs
|
||||
mutable mutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
|
||||
// this class keeps track of which pieces, belonging to
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2009-2016, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TORRENT_THREAD_HPP_INCLUDED
|
||||
#define TORRENT_THREAD_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
|
||||
// asio assumes that the windows error codes are defined already
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#if defined TORRENT_BEOS
|
||||
#include <kernel/OS.h>
|
||||
#endif
|
||||
|
||||
#include <memory> // for auto_ptr required by asio
|
||||
|
||||
#include <boost/asio/detail/thread.hpp>
|
||||
#include <boost/asio/detail/mutex.hpp>
|
||||
#include <boost/asio/detail/event.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
typedef boost::asio::detail::thread thread;
|
||||
typedef boost::asio::detail::mutex mutex;
|
||||
typedef boost::asio::detail::event event;
|
||||
|
||||
// internal
|
||||
void sleep(int milliseconds);
|
||||
|
||||
struct TORRENT_EXTRA_EXPORT condition_variable
|
||||
{
|
||||
condition_variable();
|
||||
~condition_variable();
|
||||
void wait(mutex::scoped_lock& l);
|
||||
void wait_for(mutex::scoped_lock& l, time_duration rel_time);
|
||||
void notify_all();
|
||||
void notify();
|
||||
private:
|
||||
#ifdef BOOST_HAS_PTHREADS
|
||||
pthread_cond_t m_cond;
|
||||
#elif defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
|
||||
HANDLE m_sem;
|
||||
mutex m_mutex;
|
||||
int m_num_waiters;
|
||||
#elif defined TORRENT_BEOS
|
||||
sem_id m_sem;
|
||||
mutex m_mutex;
|
||||
int m_num_waiters;
|
||||
#else
|
||||
#error not implemented
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -34,8 +34,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_THREAD_POOL
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/atomic.hpp>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -59,20 +60,23 @@ namespace libtorrent
|
|||
while (m_num_threads < n)
|
||||
{
|
||||
++m_num_threads;
|
||||
m_threads.push_back(boost::shared_ptr<thread>(
|
||||
new thread(boost::bind(&thread_pool::thread_fun, this, int(m_num_threads)-1))));
|
||||
m_threads.emplace_back(&thread_pool::thread_fun
|
||||
, this, int(m_num_threads)-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (m_num_threads > n) { --m_num_threads; }
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
m_cond.notify_all();
|
||||
l.unlock();
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
m_cond.notify_all();
|
||||
}
|
||||
if (wait)
|
||||
{
|
||||
for (int i = m_num_threads; i < int(m_threads.size()); ++i)
|
||||
m_threads[i]->join();
|
||||
{
|
||||
m_threads[i].join();
|
||||
}
|
||||
}
|
||||
// this will detach the threads
|
||||
m_threads.resize(m_num_threads);
|
||||
|
@ -93,14 +97,14 @@ namespace libtorrent
|
|||
else
|
||||
{
|
||||
retain_job(e);
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
m_queue.push_back(e);
|
||||
// we only need to signal if the threads
|
||||
// may have been put to sleep. If the size
|
||||
// previous to adding the new job was > 0
|
||||
// they don't need waking up.
|
||||
if (m_queue.size() == 1)
|
||||
m_cond.notify();
|
||||
m_cond.notify_one();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +120,7 @@ namespace libtorrent
|
|||
{
|
||||
for (;;)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
while (m_queue.empty() && thread_id < m_num_threads) m_cond.wait(l);
|
||||
|
||||
// if the number of wanted thread is decreased,
|
||||
|
@ -138,25 +142,25 @@ namespace libtorrent
|
|||
{
|
||||
// when we're terminating the last hasher thread, make sure
|
||||
// there are no more scheduled jobs
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
TORRENT_ASSERT(m_queue.empty());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// the mutex only protects m_cond and m_queue
|
||||
// the std::mutex only protects m_cond and m_queue
|
||||
// all other members are only used from a single
|
||||
// thread (the user of this class, i.e. the disk
|
||||
// thread).
|
||||
mutex m_mutex;
|
||||
condition_variable m_cond;
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_cond;
|
||||
std::deque<T> m_queue;
|
||||
|
||||
std::vector<boost::shared_ptr<thread> > m_threads;
|
||||
std::vector<std::thread> m_threads;
|
||||
// this is a counter which is atomically incremented
|
||||
// by each thread as it's started up, in order to
|
||||
// assign a unique id to each thread
|
||||
boost::atomic<int> m_num_threads;
|
||||
std::atomic<int> m_num_threads;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <string>
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
|
@ -64,8 +64,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/union_endpoint.hpp"
|
||||
#include "libtorrent/io_service.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/aux_/array_view.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -274,7 +274,8 @@ namespace libtorrent
|
|||
|
||||
int m_completion_timeout;
|
||||
|
||||
mutable mutex m_mutex;
|
||||
// TODO: 3 is this object really accessed from multiple threads?
|
||||
mutable std::mutex m_mutex;
|
||||
|
||||
// used for timeouts
|
||||
// this is set when the request has been sent
|
||||
|
@ -397,7 +398,7 @@ namespace libtorrent
|
|||
|
||||
private:
|
||||
|
||||
mutable mutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
|
||||
// maps transactionid to the udp_tracker_connection
|
||||
// TODO: this should be unique_ptr in the future
|
||||
|
|
|
@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/buffer.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/debug.hpp"
|
||||
#include "libtorrent/aux_/array_view.hpp"
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace libtorrent
|
|||
};
|
||||
|
||||
static std::map<address, connection_cache_entry> m_connection_cache;
|
||||
static mutex m_cache_mutex;
|
||||
static std::mutex m_cache_mutex;
|
||||
|
||||
udp::endpoint m_target;
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp"
|
||||
#include "libtorrent/http_connection.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/deadline_timer.hpp"
|
||||
#include "libtorrent/enum_net.hpp"
|
||||
#include "libtorrent/resolver.hpp"
|
||||
|
@ -48,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ public:
|
|||
// the router, it can be queried through this function.
|
||||
std::string router_model()
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
return m_model;
|
||||
}
|
||||
|
||||
|
@ -183,8 +183,8 @@ private:
|
|||
boost::shared_ptr<upnp> self() { return shared_from_this(); }
|
||||
|
||||
void map_timer(error_code const& ec);
|
||||
void try_map_upnp(mutex::scoped_lock& l, bool timer = false);
|
||||
void discover_device_impl(mutex::scoped_lock& l);
|
||||
void try_map_upnp(std::unique_lock<std::mutex>& l, bool timer = false);
|
||||
void discover_device_impl(std::unique_lock<std::mutex>& l);
|
||||
static address_v4 upnp_multicast_address;
|
||||
static udp::endpoint upnp_multicast_endpoint;
|
||||
|
||||
|
@ -199,8 +199,8 @@ private:
|
|||
, std::size_t bytes_transferred);
|
||||
|
||||
struct rootdevice;
|
||||
void next(rootdevice& d, int i, mutex::scoped_lock& l);
|
||||
void update_map(rootdevice& d, int i, mutex::scoped_lock& l);
|
||||
void next(rootdevice& d, int i, std::unique_lock<std::mutex>& l);
|
||||
void update_map(rootdevice& d, int i, std::unique_lock<std::mutex>& l);
|
||||
|
||||
|
||||
void on_upnp_xml(error_code const& e
|
||||
|
@ -217,15 +217,15 @@ private:
|
|||
, int mapping, http_connection& c);
|
||||
void on_expire(error_code const& e);
|
||||
|
||||
void disable(error_code const& ec, mutex::scoped_lock& l);
|
||||
void return_error(int mapping, int code, mutex::scoped_lock& l);
|
||||
void log(char const* msg, mutex::scoped_lock& l);
|
||||
void disable(error_code const& ec, std::unique_lock<std::mutex>& l);
|
||||
void return_error(int mapping, int code, std::unique_lock<std::mutex>& l);
|
||||
void log(char const* msg, std::unique_lock<std::mutex>& l);
|
||||
|
||||
void get_ip_address(rootdevice& d);
|
||||
void delete_port_mapping(rootdevice& d, int i);
|
||||
void create_port_mapping(http_connection& c, rootdevice& d, int i);
|
||||
void post(upnp::rootdevice const& d, char const* soap
|
||||
, char const* soap_action, mutex::scoped_lock& l);
|
||||
, char const* soap_action, std::unique_lock<std::mutex>& l);
|
||||
|
||||
int num_mappings() const { return int(m_mappings.size()); }
|
||||
|
||||
|
@ -394,7 +394,8 @@ private:
|
|||
bool m_closing;
|
||||
bool m_ignore_non_routers;
|
||||
|
||||
mutex m_mutex;
|
||||
// TODO: 3 is this class really accessed from multiple threads?
|
||||
std::mutex m_mutex;
|
||||
|
||||
std::string m_model;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/packet_buffer.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
|
|
@ -125,7 +125,6 @@ libtorrent_rasterbar_la_SOURCES = \
|
|||
storage.cpp \
|
||||
session_stats.cpp \
|
||||
string_util.cpp \
|
||||
thread.cpp \
|
||||
torrent.cpp \
|
||||
torrent_handle.cpp \
|
||||
torrent_info.cpp \
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace libtorrent
|
|||
|
||||
alert* alert_manager::wait_for_alert(time_duration max_wait)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
if (!m_alerts[m_generation].empty())
|
||||
return m_alerts[m_generation].front();
|
||||
|
@ -64,7 +64,7 @@ namespace libtorrent
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void alert_manager::maybe_notify(alert* a, mutex::scoped_lock& lock)
|
||||
void alert_manager::maybe_notify(alert* a, std::unique_lock<std::mutex>& lock)
|
||||
{
|
||||
if (m_alerts[m_generation].size() == 1)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ namespace libtorrent
|
|||
void alert_manager::set_dispatch_function(
|
||||
boost::function<void(std::auto_ptr<alert>)> const& fun)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
m_dispatch = fun;
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace libtorrent
|
|||
|
||||
void alert_manager::set_notify_function(boost::function<void()> const& fun)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_notify = fun;
|
||||
if (!m_alerts[m_generation].empty())
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ namespace libtorrent
|
|||
|
||||
void alert_manager::get_all(std::vector<alert*>& alerts)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
alerts.clear();
|
||||
if (m_alerts[m_generation].empty()) return;
|
||||
|
@ -177,13 +177,13 @@ namespace libtorrent
|
|||
|
||||
bool alert_manager::pending() const
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return !m_alerts[m_generation].empty();
|
||||
}
|
||||
|
||||
int alert_manager::set_alert_queue_size_limit(int queue_size_limit_)
|
||||
{
|
||||
mutex::scoped_lock lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
std::swap(m_queue_size_limit, queue_size_limit_);
|
||||
return queue_size_limit_;
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace libtorrent
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
|
||||
if (m_exceeded_max_size)
|
||||
ret = m_in_use - (std::min)(m_low_watermark, int(m_max_use - m_observers.size()*2));
|
||||
|
@ -152,9 +152,9 @@ namespace libtorrent
|
|||
// and if we're in fact below the low watermark. If so, we need to
|
||||
// post the notification messages to the peers that are waiting for
|
||||
// more buffers to received data into
|
||||
void disk_buffer_pool::check_buffer_level(mutex::scoped_lock& l)
|
||||
void disk_buffer_pool::check_buffer_level(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
if (!m_exceeded_max_size || m_in_use > m_low_watermark) return;
|
||||
|
||||
m_exceeded_max_size = false;
|
||||
|
@ -168,10 +168,10 @@ namespace libtorrent
|
|||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
bool disk_buffer_pool::is_disk_buffer(char* buffer
|
||||
, mutex::scoped_lock& l) const
|
||||
, std::unique_lock<std::mutex>& l) const
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
TORRENT_UNUSED(l);
|
||||
|
||||
#if TORRENT_HAVE_MMAP
|
||||
|
@ -198,14 +198,14 @@ namespace libtorrent
|
|||
|
||||
bool disk_buffer_pool::is_disk_buffer(char* buffer) const
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
return is_disk_buffer(buffer, l);
|
||||
}
|
||||
#endif
|
||||
|
||||
char* disk_buffer_pool::allocate_buffer(char const* category)
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
return allocate_buffer_impl(l, category);
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ namespace libtorrent
|
|||
char* disk_buffer_pool::allocate_buffer(bool& exceeded
|
||||
, boost::shared_ptr<disk_observer> o, char const* category)
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
char* ret = allocate_buffer_impl(l, category);
|
||||
if (m_exceeded_max_size)
|
||||
{
|
||||
|
@ -233,7 +233,7 @@ namespace libtorrent
|
|||
// fills in the iovec array with the buffers
|
||||
int disk_buffer_pool::allocate_iovec(file::iovec_t* iov, int iov_len)
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
for (int i = 0; i < iov_len; ++i)
|
||||
{
|
||||
iov[i].iov_base = allocate_buffer_impl(l, "pending read");
|
||||
|
@ -254,18 +254,18 @@ namespace libtorrent
|
|||
void disk_buffer_pool::free_iovec(file::iovec_t* iov, int iov_len)
|
||||
{
|
||||
// TODO: perhaps we should sort the buffers here?
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
for (int i = 0; i < iov_len; ++i)
|
||||
free_buffer_impl(static_cast<char*>(iov[i].iov_base), l);
|
||||
check_buffer_level(l);
|
||||
}
|
||||
|
||||
char* disk_buffer_pool::allocate_buffer_impl(mutex::scoped_lock& l
|
||||
char* disk_buffer_pool::allocate_buffer_impl(std::unique_lock<std::mutex>& l
|
||||
, char const*)
|
||||
{
|
||||
TORRENT_ASSERT(m_settings_set);
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
TORRENT_UNUSED(l);
|
||||
|
||||
char* ret;
|
||||
|
@ -339,7 +339,7 @@ namespace libtorrent
|
|||
// sort the pointers in order to maximize cache hits
|
||||
std::sort(bufvec, end);
|
||||
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
for (; bufvec != end; ++bufvec)
|
||||
{
|
||||
char* buf = *bufvec;
|
||||
|
@ -352,7 +352,7 @@ namespace libtorrent
|
|||
|
||||
void disk_buffer_pool::free_buffer(char* buf)
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
free_buffer_impl(buf, l);
|
||||
check_buffer_level(l);
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_UNUSED(ec);
|
||||
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
|
||||
// 0 cache_buffer_chunk_size means 'automatic' (i.e.
|
||||
// proportional to the total disk cache size)
|
||||
|
@ -515,13 +515,13 @@ namespace libtorrent
|
|||
#endif
|
||||
}
|
||||
|
||||
void disk_buffer_pool::free_buffer_impl(char* buf, mutex::scoped_lock& l)
|
||||
void disk_buffer_pool::free_buffer_impl(char* buf, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(buf);
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(m_settings_set);
|
||||
TORRENT_ASSERT(is_disk_buffer(buf, l));
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
TORRENT_UNUSED(l);
|
||||
|
||||
#if TORRENT_HAVE_MMAP
|
||||
|
@ -581,7 +581,7 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
std::unique_lock<std::mutex> l(m_pool_mutex);
|
||||
if (m_using_pool_allocator)
|
||||
m_pool.release_memory();
|
||||
#endif
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace libtorrent
|
|||
void debug_log(char const* fmt, ...)
|
||||
{
|
||||
#if DEBUG_DISK_THREAD
|
||||
static mutex log_mutex;
|
||||
static std::mutex log_mutex;
|
||||
static const time_point start = clock_type::now();
|
||||
va_list v;
|
||||
va_start(v, fmt);
|
||||
|
@ -115,7 +115,7 @@ namespace libtorrent
|
|||
if (!prepend_time)
|
||||
{
|
||||
prepend_time = (usr[len-1] == '\n');
|
||||
mutex::scoped_lock l(log_mutex);
|
||||
std::unique_lock<std::mutex> l(log_mutex);
|
||||
fputs(usr, stderr);
|
||||
return;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ namespace libtorrent
|
|||
int t = total_milliseconds(clock_type::now() - start);
|
||||
snprintf(buf, sizeof(buf), "%05d: [%p] %s", t, pthread_self(), usr);
|
||||
prepend_time = (usr[len-1] == '\n');
|
||||
mutex::scoped_lock l(log_mutex);
|
||||
std::unique_lock<std::mutex> l(log_mutex);
|
||||
fputs(buf, stderr);
|
||||
#else
|
||||
TORRENT_UNUSED(fmt);
|
||||
|
@ -215,7 +215,7 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
// TODO: 1 it would be nice to have the number of threads be set dynamically
|
||||
void disk_io_thread::set_num_threads(int i, bool wait)
|
||||
void disk_io_thread::set_num_threads(int const i, bool const wait)
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
if (i == m_num_threads) return;
|
||||
|
@ -241,20 +241,24 @@ namespace libtorrent
|
|||
// the magic number 3 is also used in add_job()
|
||||
// every 4:th thread is a hasher thread
|
||||
if ((thread_id & 0x3) == 3) type = hasher_thread;
|
||||
m_threads.push_back(boost::shared_ptr<thread>(
|
||||
new thread(boost::bind(&disk_io_thread::thread_fun, this
|
||||
, thread_id, type, work))));
|
||||
m_threads.emplace_back(&disk_io_thread::thread_fun, this
|
||||
, thread_id, type, work);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (m_num_threads > i) { --m_num_threads; }
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
m_job_cond.notify_all();
|
||||
m_hash_job_cond.notify_all();
|
||||
l.unlock();
|
||||
if (wait) for (int j = m_num_threads; j < m_threads.size(); ++j) m_threads[j]->join();
|
||||
// this will detach the threads
|
||||
for (int j = m_num_threads; j < m_threads.size(); ++j)
|
||||
{
|
||||
if (wait)
|
||||
m_threads[j].join();
|
||||
else
|
||||
m_threads[j].detach();
|
||||
}
|
||||
m_threads.resize(m_num_threads);
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +279,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(m_outstanding_reclaim_message);
|
||||
m_outstanding_reclaim_message = false;
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
for (int i = 0; i < m_blocks_to_reclaim.size(); ++i)
|
||||
m_disk_cache.reclaim_block(m_blocks_to_reclaim[i]);
|
||||
m_blocks_to_reclaim.clear();
|
||||
|
@ -284,7 +288,7 @@ namespace libtorrent
|
|||
void disk_io_thread::set_settings(settings_pack const* pack, alert_manager& alerts)
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
apply_pack(pack, m_settings);
|
||||
error_code ec;
|
||||
m_disk_cache.set_settings(m_settings, ec);
|
||||
|
@ -297,10 +301,10 @@ namespace libtorrent
|
|||
// flush all blocks that are below p->hash.offset, since we've
|
||||
// already hashed those blocks, they won't cause any read-back
|
||||
int disk_io_thread::try_flush_hashed(cached_piece_entry* p, int cont_block
|
||||
, jobqueue_t& completed_jobs, mutex::scoped_lock& l)
|
||||
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
TORRENT_ASSERT(cont_block > 0);
|
||||
if (p->hash == 0 && !p->hashing_done)
|
||||
{
|
||||
|
@ -737,9 +741,9 @@ namespace libtorrent
|
|||
// issues write operations for blocks in the given
|
||||
// range on the given piece.
|
||||
int disk_io_thread::flush_range(cached_piece_entry* pe, int start, int end
|
||||
, jobqueue_t& completed_jobs, mutex::scoped_lock& l)
|
||||
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
INVARIANT_CHECK;
|
||||
|
||||
DLOG("flush_range: piece=%d [%d, %d)\n"
|
||||
|
@ -799,9 +803,9 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
void disk_io_thread::flush_piece(cached_piece_entry* pe, int flags
|
||||
, jobqueue_t& completed_jobs, mutex::scoped_lock& l)
|
||||
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
if (flags & flush_delete_cache)
|
||||
{
|
||||
// delete dirty blocks and post handlers with
|
||||
|
@ -832,7 +836,7 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
void disk_io_thread::flush_cache(piece_manager* storage, boost::uint32_t flags
|
||||
, jobqueue_t& completed_jobs, mutex::scoped_lock& l)
|
||||
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
if (storage)
|
||||
{
|
||||
|
@ -855,7 +859,7 @@ namespace libtorrent
|
|||
flush_piece(pe, flags, completed_jobs, l);
|
||||
}
|
||||
#if TORRENT_USE_ASSERTS
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
// if the user asked to delete the cache for this storage
|
||||
// we really should not have any pieces left. This is only called
|
||||
// from disk_io_thread::do_delete, which is a fence job and should
|
||||
|
@ -903,7 +907,7 @@ namespace libtorrent
|
|||
// blocks of write cache line size, but try to flush all old blocks
|
||||
// this is why we pass in 1 as cont_block to the flushing functions
|
||||
void disk_io_thread::try_flush_write_blocks(int num, jobqueue_t& completed_jobs
|
||||
, mutex::scoped_lock& l)
|
||||
, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
DLOG("try_flush_write_blocks: %d\n", num);
|
||||
|
||||
|
@ -977,7 +981,7 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
void disk_io_thread::flush_expired_write_blocks(jobqueue_t& completed_jobs
|
||||
, mutex::scoped_lock& l)
|
||||
, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
DLOG("flush_expired_write_blocks\n");
|
||||
|
||||
|
@ -1064,7 +1068,7 @@ namespace libtorrent
|
|||
// below the number of blocks we flushed by the time we're done flushing
|
||||
// that's why we need to call this fairly often. Both before and after
|
||||
// a disk job is executed
|
||||
void disk_io_thread::check_cache_level(mutex::scoped_lock& l, jobqueue_t& completed_jobs)
|
||||
void disk_io_thread::check_cache_level(std::unique_lock<std::mutex>& l, jobqueue_t& completed_jobs)
|
||||
{
|
||||
// when the read cache is disabled, always try to evict all read cache
|
||||
// blocks
|
||||
|
@ -1096,7 +1100,7 @@ namespace libtorrent
|
|||
|
||||
#if DEBUG_DISK_THREAD
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
DLOG("perform_job job: %s ( %s%s) piece: %d offset: %d outstanding: %d\n"
|
||||
, job_action_name[j->action]
|
||||
|
@ -1112,7 +1116,7 @@ namespace libtorrent
|
|||
// TODO: instead of doing this. pass in the settings to each storage_interface
|
||||
// call. Each disk thread could hold its most recent understanding of the settings
|
||||
// in a shared_ptr, and update it every time it wakes up from a job. That way
|
||||
// each access to the settings won't require a mutex to be held.
|
||||
// each access to the settings won't require a std::mutex to be held.
|
||||
if (storage && storage->get_storage_impl()->m_settings == 0)
|
||||
storage->get_storage_impl()->m_settings = &m_settings;
|
||||
|
||||
|
@ -1130,14 +1134,14 @@ namespace libtorrent
|
|||
|
||||
m_stats_counters.inc_stats_counter(counters::num_running_disk_jobs, -1);
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
if (m_cache_check_state == cache_check_idle)
|
||||
{
|
||||
m_cache_check_state = cache_check_active;
|
||||
while (m_cache_check_state != cache_check_idle)
|
||||
{
|
||||
check_cache_level(l, completed_jobs);
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
--m_cache_check_state;
|
||||
}
|
||||
}
|
||||
|
@ -1149,7 +1153,7 @@ namespace libtorrent
|
|||
|
||||
if (ret == retry_job)
|
||||
{
|
||||
mutex::scoped_lock l2(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l2(m_job_mutex);
|
||||
// to avoid busy looping here, give up
|
||||
// our quanta in case there aren't any other
|
||||
// jobs to run in between
|
||||
|
@ -1163,7 +1167,7 @@ namespace libtorrent
|
|||
bool need_sleep = m_queued_jobs.empty();
|
||||
m_queued_jobs.push_back(j);
|
||||
l2.unlock();
|
||||
if (need_sleep) sleep(0);
|
||||
if (need_sleep) std::this_thread::yield();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1225,7 @@ namespace libtorrent
|
|||
|
||||
file::iovec_t* iov = TORRENT_ALLOCA(file::iovec_t, iov_len);
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
int evict = m_disk_cache.num_to_evict(iov_len);
|
||||
if (evict > 0) m_disk_cache.try_evict_blocks(evict);
|
||||
|
@ -1243,7 +1247,7 @@ namespace libtorrent
|
|||
{
|
||||
ret = do_uncached_read(j);
|
||||
|
||||
mutex::scoped_lock l2(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l2(m_cache_mutex);
|
||||
pe = m_disk_cache.find_piece(j);
|
||||
if (pe) maybe_issue_queued_read_jobs(pe, completed_jobs);
|
||||
return ret;
|
||||
|
@ -1260,7 +1264,7 @@ namespace libtorrent
|
|||
|
||||
// at this point, all the buffers are allocated and iov is initizalied
|
||||
// and the blocks have their refcounters incremented, so no other thread
|
||||
// can remove them. We can now release the cache mutex and dive into the
|
||||
// can remove them. We can now release the cache std::mutex and dive into the
|
||||
// disk operations.
|
||||
|
||||
int const file_flags = file_flags_for_job(j
|
||||
|
@ -1455,7 +1459,7 @@ namespace libtorrent
|
|||
INVARIANT_CHECK;
|
||||
TORRENT_ASSERT(j->d.io.buffer_size <= m_disk_cache.block_size());
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe && pe->hashing_done)
|
||||
|
@ -1537,7 +1541,7 @@ namespace libtorrent
|
|||
j->requester = requester;
|
||||
j->callback = handler;
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
int ret = prep_read_job_impl(j);
|
||||
l.unlock();
|
||||
|
||||
|
@ -1557,7 +1561,7 @@ namespace libtorrent
|
|||
// and if it doesn't have a picece allocated, it allocates
|
||||
// one and it sets outstanding_read flag and possibly queues
|
||||
// up the job in the piece read job list
|
||||
// the cache mutex must be held when calling this
|
||||
// the cache std::mutex must be held when calling this
|
||||
//
|
||||
// returns 0 if the job succeeded immediately
|
||||
// 1 if it needs to be added to the job queue
|
||||
|
@ -1655,7 +1659,7 @@ namespace libtorrent
|
|||
j->flags = flags;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
mutex::scoped_lock l3_(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l3_(m_cache_mutex);
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe)
|
||||
{
|
||||
|
@ -1670,7 +1674,7 @@ namespace libtorrent
|
|||
#endif
|
||||
|
||||
#if TORRENT_USE_ASSERTS && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
|
||||
mutex::scoped_lock l2_(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l2_(m_cache_mutex);
|
||||
std::pair<block_cache::iterator, block_cache::iterator> range = m_disk_cache.all_pieces();
|
||||
for (block_cache::iterator i = range.first; i != range.second; ++i)
|
||||
{
|
||||
|
@ -1685,7 +1689,7 @@ namespace libtorrent
|
|||
#endif
|
||||
|
||||
#if !defined TORRENT_DISABLE_POOL_ALLOCATOR && TORRENT_USE_ASSERTS
|
||||
mutex::scoped_lock l_(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l_(m_cache_mutex);
|
||||
TORRENT_ASSERT(m_disk_cache.is_disk_buffer(j->buffer.disk_block));
|
||||
l_.unlock();
|
||||
#endif
|
||||
|
@ -1705,7 +1709,7 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
// if we succeed in adding the block to the cache, the job will
|
||||
// be added along with it. we may not free j if so
|
||||
cached_piece_entry* dpe = m_disk_cache.add_dirty_block(j);
|
||||
|
@ -1755,7 +1759,7 @@ namespace libtorrent
|
|||
int piece_size = storage->files()->piece_size(piece);
|
||||
|
||||
// first check to see if the hashing is already done
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe && !pe->hashing && pe->hash && pe->hash->offset == piece_size)
|
||||
{
|
||||
|
@ -1823,7 +1827,7 @@ namespace libtorrent
|
|||
jobqueue_t completed_jobs;
|
||||
|
||||
// remove outstanding jobs belonging to this torrent
|
||||
mutex::scoped_lock l2(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l2(m_job_mutex);
|
||||
|
||||
// TODO: maybe the tailqueue_iterator<disk_io_job> should contain a pointer-pointer
|
||||
// instead and have an unlink function
|
||||
|
@ -1844,7 +1848,7 @@ namespace libtorrent
|
|||
}
|
||||
l2.unlock();
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
flush_cache(storage, flush_delete_cache, completed_jobs, l);
|
||||
l.unlock();
|
||||
|
||||
|
@ -1906,7 +1910,7 @@ namespace libtorrent
|
|||
, boost::function<void(disk_io_job const*)> const& handler)
|
||||
{
|
||||
// remove outstanding hash jobs belonging to this torrent
|
||||
mutex::scoped_lock l2(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l2(m_job_mutex);
|
||||
|
||||
disk_io_job* qj = m_queued_hash_jobs.get_all();
|
||||
jobqueue_t to_abort;
|
||||
|
@ -2040,7 +2044,7 @@ namespace libtorrent
|
|||
|
||||
void disk_io_thread::clear_read_cache(piece_manager* storage)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
jobqueue_t jobs;
|
||||
boost::unordered_set<cached_piece_entry*> const& cache = storage->cached_pieces();
|
||||
|
@ -2081,7 +2085,7 @@ namespace libtorrent
|
|||
|
||||
void disk_io_thread::clear_piece(piece_manager* storage, int index)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(storage, index);
|
||||
if (pe == 0) return;
|
||||
|
@ -2103,7 +2107,7 @@ namespace libtorrent
|
|||
fail_jobs(storage_error(boost::asio::error::operation_aborted), jobs);
|
||||
}
|
||||
|
||||
void disk_io_thread::kick_hasher(cached_piece_entry* pe, mutex::scoped_lock& l)
|
||||
void disk_io_thread::kick_hasher(cached_piece_entry* pe, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
if (!pe->hash) return;
|
||||
if (pe->hashing) return;
|
||||
|
@ -2268,7 +2272,7 @@ namespace libtorrent
|
|||
int const file_flags = file_flags_for_job(j
|
||||
, m_settings.get_bool(settings_pack::coalesce_reads));
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe)
|
||||
|
@ -2430,7 +2434,6 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(j->error.ec && j->error.operation != 0);
|
||||
m_disk_cache.free_buffer(static_cast<char*>(iov.iov_base));
|
||||
l.lock();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2444,7 +2447,6 @@ namespace libtorrent
|
|||
, boost::asio::error::get_misc_category());
|
||||
j->error.operation = storage_error::read;
|
||||
m_disk_cache.free_buffer(static_cast<char*>(iov.iov_base));
|
||||
l.lock();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2519,7 +2521,7 @@ namespace libtorrent
|
|||
// if this assert fails, something's wrong with the fence logic
|
||||
TORRENT_ASSERT(j->storage->num_outstanding_jobs() == 1);
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
flush_cache(j->storage.get(), flush_write_cache, completed_jobs, l);
|
||||
l.unlock();
|
||||
|
||||
|
@ -2535,7 +2537,7 @@ namespace libtorrent
|
|||
// if this assert fails, something's wrong with the fence logic
|
||||
TORRENT_ASSERT(j->storage->num_outstanding_jobs() == 1);
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
m_disk_cache.mark_deleted(*j->storage->files());
|
||||
#endif
|
||||
|
@ -2579,7 +2581,7 @@ namespace libtorrent
|
|||
|
||||
// issue write commands for all dirty blocks
|
||||
// and clear all read jobs
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
flush_cache(j->storage.get(), flush_read_cache | flush_write_cache
|
||||
, completed_jobs, l);
|
||||
l.unlock();
|
||||
|
@ -2603,7 +2605,7 @@ namespace libtorrent
|
|||
int const file_flags = file_flags_for_job(j
|
||||
, m_settings.get_bool(settings_pack::coalesce_reads));
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe == NULL)
|
||||
|
@ -2635,7 +2637,7 @@ namespace libtorrent
|
|||
int ret = 0;
|
||||
int offset = 0;
|
||||
|
||||
// TODO: it would be nice to not have to lock the mutex every
|
||||
// TODO: it would be nice to not have to lock the std::mutex every
|
||||
// turn through this loop
|
||||
for (int i = 0; i < blocks_in_piece; ++i)
|
||||
{
|
||||
|
@ -2727,7 +2729,7 @@ namespace libtorrent
|
|||
{
|
||||
// These are atomic_counts, so it's safe to access them from
|
||||
// a different thread
|
||||
mutex::scoped_lock jl(m_job_mutex);
|
||||
std::unique_lock<std::mutex> jl(m_job_mutex);
|
||||
|
||||
c.set_value(counters::num_read_jobs, read_jobs_in_use());
|
||||
c.set_value(counters::num_write_jobs, write_jobs_in_use());
|
||||
|
@ -2737,7 +2739,7 @@ namespace libtorrent
|
|||
|
||||
jl.unlock();
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
// gauges
|
||||
c.set_value(counters::disk_blocks_in_use, m_disk_cache.in_use());
|
||||
|
@ -2748,7 +2750,7 @@ namespace libtorrent
|
|||
void disk_io_thread::get_cache_info(cache_status* ret, bool no_pieces
|
||||
, piece_manager const* storage) const
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
ret->total_used_buffers = m_disk_cache.in_use();
|
||||
|
@ -2837,7 +2839,7 @@ namespace libtorrent
|
|||
l.unlock();
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
mutex::scoped_lock jl(m_job_mutex);
|
||||
std::unique_lock<std::mutex> jl(m_job_mutex);
|
||||
ret->queued_jobs = m_queued_jobs.size() + m_queued_hash_jobs.size();
|
||||
jl.unlock();
|
||||
#endif
|
||||
|
@ -2845,7 +2847,7 @@ namespace libtorrent
|
|||
|
||||
int disk_io_thread::do_flush_piece(disk_io_job* j, jobqueue_t& completed_jobs)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe == NULL) return 0;
|
||||
|
@ -2864,7 +2866,7 @@ namespace libtorrent
|
|||
// triggered by another mechanism.
|
||||
int disk_io_thread::do_flush_hashed(disk_io_job* j, jobqueue_t& completed_jobs)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
|
||||
|
@ -2907,7 +2909,7 @@ namespace libtorrent
|
|||
try_flush_hashed(pe, m_settings.get_int(
|
||||
settings_pack::write_cache_line_size), completed_jobs, l);
|
||||
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
|
||||
--pe->piece_refcount;
|
||||
|
||||
|
@ -2918,7 +2920,7 @@ namespace libtorrent
|
|||
|
||||
int disk_io_thread::do_flush_storage(disk_io_job* j, jobqueue_t& completed_jobs)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
flush_cache(j->storage.get(), flush_write_cache, completed_jobs, l);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2964,7 +2966,7 @@ namespace libtorrent
|
|||
// have been evicted
|
||||
int disk_io_thread::do_clear_piece(disk_io_job* j, jobqueue_t& completed_jobs)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe == 0) return 0;
|
||||
|
@ -3026,7 +3028,7 @@ namespace libtorrent
|
|||
int ret = storage->raise_fence(j, fj, m_stats_counters);
|
||||
if (ret == disk_job_fence::fence_post_fence)
|
||||
{
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
TORRENT_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage);
|
||||
// prioritize fence jobs since they're blocking other jobs
|
||||
m_queued_jobs.push_front(j);
|
||||
|
@ -3052,7 +3054,7 @@ namespace libtorrent
|
|||
// now, we have to make sure that all outstanding jobs on this
|
||||
// storage actually get flushed, in order for the fence job to
|
||||
// be executed
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
TORRENT_ASSERT((fj->flags & disk_io_job::in_progress) || !fj->storage);
|
||||
|
||||
m_queued_jobs.push_front(fj);
|
||||
|
@ -3084,7 +3086,7 @@ namespace libtorrent
|
|||
// block cache, and then get issued
|
||||
if (j->flags & disk_io_job::in_progress)
|
||||
{
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
TORRENT_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage);
|
||||
m_queued_jobs.push_back(j);
|
||||
|
||||
|
@ -3118,7 +3120,7 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
|
||||
TORRENT_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage);
|
||||
|
||||
|
@ -3156,7 +3158,7 @@ namespace libtorrent
|
|||
|
||||
void disk_io_thread::submit_jobs()
|
||||
{
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
if (!m_queued_jobs.empty())
|
||||
m_job_cond.notify_all();
|
||||
if (!m_queued_hash_jobs.empty())
|
||||
|
@ -3168,7 +3170,7 @@ namespace libtorrent
|
|||
time_point now = clock_type::now();
|
||||
if (now <= m_last_cache_expiry + seconds(5)) return;
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
DLOG("blocked_jobs: %d queued_jobs: %d num_threads %d\n"
|
||||
, int(m_stats_counters[counters::blocked_disk_jobs])
|
||||
, m_queued_jobs.size(), int(m_num_threads));
|
||||
|
@ -3196,13 +3198,13 @@ namespace libtorrent
|
|||
++m_num_running_threads;
|
||||
m_stats_counters.inc_stats_counter(counters::num_running_threads, 1);
|
||||
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
for (;;)
|
||||
{
|
||||
disk_io_job* j = 0;
|
||||
if (type == generic_thread)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
while (m_queued_jobs.empty() && thread_id < m_num_threads) m_job_cond.wait(l);
|
||||
|
||||
// if the number of wanted threads is decreased,
|
||||
|
@ -3219,7 +3221,7 @@ namespace libtorrent
|
|||
}
|
||||
else if (type == hasher_thread)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
while (m_queued_hash_jobs.empty() && thread_id < m_num_threads) m_hash_job_cond.wait(l);
|
||||
if (m_queued_hash_jobs.empty() && thread_id >= m_num_threads) break;
|
||||
j = m_queued_hash_jobs.pop_front();
|
||||
|
@ -3263,13 +3265,13 @@ namespace libtorrent
|
|||
// This is not supposed to happen because the disk thread is now scheduled
|
||||
// for shut down after all peers have shut down (see
|
||||
// session_impl::abort_stage2()).
|
||||
mutex::scoped_lock l2(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l2(m_cache_mutex);
|
||||
TORRENT_ASSERT_VAL(m_disk_cache.pinned_blocks() == 0
|
||||
, m_disk_cache.pinned_blocks());
|
||||
while (m_disk_cache.pinned_blocks() > 0)
|
||||
{
|
||||
l2.unlock();
|
||||
sleep(100);
|
||||
std::this_thread::sleep_for(milliseconds(100));
|
||||
l2.lock();
|
||||
}
|
||||
l2.unlock();
|
||||
|
@ -3402,7 +3404,7 @@ namespace libtorrent
|
|||
|
||||
if (j->action == disk_io_job::write)
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
cached_piece_entry* pe = m_disk_cache.find_piece(j);
|
||||
if (pe)
|
||||
{
|
||||
|
@ -3415,7 +3417,7 @@ namespace libtorrent
|
|||
#endif
|
||||
jobqueue_t other_jobs;
|
||||
jobqueue_t flush_jobs;
|
||||
mutex::scoped_lock l_(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l_(m_cache_mutex);
|
||||
while (new_jobs.size() > 0)
|
||||
{
|
||||
disk_io_job* j = new_jobs.pop_front();
|
||||
|
@ -3480,7 +3482,7 @@ namespace libtorrent
|
|||
}
|
||||
l_.unlock();
|
||||
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
m_queued_jobs.append(other_jobs);
|
||||
l.unlock();
|
||||
|
||||
|
@ -3493,7 +3495,7 @@ namespace libtorrent
|
|||
m_job_cond.notify_all();
|
||||
}
|
||||
|
||||
mutex::scoped_lock l(m_completed_jobs_mutex);
|
||||
std::unique_lock<std::mutex> l(m_completed_jobs_mutex);
|
||||
|
||||
bool need_post = m_completed_jobs.size() == 0;
|
||||
m_completed_jobs.append(jobs);
|
||||
|
@ -3512,7 +3514,7 @@ namespace libtorrent
|
|||
// This is run in the network thread
|
||||
void disk_io_thread::call_job_handlers(void* userdata)
|
||||
{
|
||||
mutex::scoped_lock l(m_completed_jobs_mutex);
|
||||
std::unique_lock<std::mutex> l(m_completed_jobs_mutex);
|
||||
|
||||
#if DEBUG_DISK_THREAD
|
||||
DLOG("call_job_handlers (%d)\n", m_completed_jobs.size());
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace libtorrent
|
|||
|
||||
disk_io_job* disk_job_pool::allocate_job(int type)
|
||||
{
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::unique_lock<std::mutex> l(m_job_mutex);
|
||||
disk_io_job* ptr = static_cast<disk_io_job*>(m_job_pool.malloc());
|
||||
m_job_pool.set_next_size(100);
|
||||
if (ptr == 0) return 0;
|
||||
|
@ -78,11 +78,11 @@ namespace libtorrent
|
|||
#endif
|
||||
int type = j->action;
|
||||
j->~disk_io_job();
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
std::lock_guard<std::mutex> l(m_job_mutex);
|
||||
if (type == disk_io_job::read) --m_read_jobs;
|
||||
else if (type == disk_io_job::write) --m_write_jobs;
|
||||
--m_jobs_in_use;
|
||||
m_job_pool.free(j);
|
||||
m_job_pool.free(j);
|
||||
}
|
||||
|
||||
void disk_job_pool::free_jobs(disk_io_job** j, int num)
|
||||
|
@ -98,13 +98,13 @@ namespace libtorrent
|
|||
if (type == disk_io_job::read) ++read_jobs;
|
||||
else if (type == disk_io_job::write) ++write_jobs;
|
||||
}
|
||||
|
||||
mutex::scoped_lock l(m_job_mutex);
|
||||
|
||||
std::lock_guard<std::mutex> l(m_job_mutex);
|
||||
m_read_jobs -= read_jobs;
|
||||
m_write_jobs -= write_jobs;
|
||||
m_jobs_in_use -= num;
|
||||
for (int i = 0; i < num; ++i)
|
||||
m_job_pool.free(j[i]);
|
||||
m_job_pool.free(j[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <string>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <boost/limits.hpp>
|
||||
#include <cstring>
|
||||
|
||||
|
@ -63,8 +64,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/random.hpp"
|
||||
|
||||
#include "libtorrent/utf8.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#include "libtorrent/aux_/escape_string.hpp"
|
||||
#include "libtorrent/string_util.hpp" // for to_string
|
||||
|
||||
|
@ -540,9 +539,9 @@ namespace libtorrent
|
|||
|
||||
std::string convert_to_native(std::string const& s)
|
||||
{
|
||||
static mutex iconv_mutex;
|
||||
static std::mutex iconv_mutex;
|
||||
// only one thread can use this handle at a time
|
||||
mutex::scoped_lock l(iconv_mutex);
|
||||
std::lock_guard<std::mutex> l(iconv_mutex);
|
||||
|
||||
// the empty string represents the local dependent encoding
|
||||
static iconv_t iconv_handle = iconv_open("", "UTF-8");
|
||||
|
@ -552,9 +551,9 @@ namespace libtorrent
|
|||
|
||||
std::string convert_from_native(std::string const& s)
|
||||
{
|
||||
static mutex iconv_mutex;
|
||||
static std::mutex iconv_mutex;
|
||||
// only one thread can use this handle at a time
|
||||
mutex::scoped_lock l(iconv_mutex);
|
||||
std::lock_guard<std::mutex> l(iconv_mutex);
|
||||
|
||||
// the empty string represents the local dependent encoding
|
||||
static iconv_t iconv_handle = iconv_open("UTF-8", "");
|
||||
|
|
15
src/file.cpp
15
src/file.cpp
|
@ -69,7 +69,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
||||
#include <set>
|
||||
#include "libtorrent/thread.hpp"
|
||||
#endif
|
||||
|
||||
// for convert_to_wstring and convert_to_native
|
||||
|
@ -2259,24 +2258,24 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
|
||||
#ifdef TORRENT_DEBUG_FILE_LEAKS
|
||||
std::set<file_handle*> global_file_handles;
|
||||
mutex file_handle_mutex;
|
||||
std::mutex file_handle_mutex;
|
||||
|
||||
file_handle::file_handle()
|
||||
{
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
global_file_handles.insert(this);
|
||||
stack[0] = 0;
|
||||
}
|
||||
file_handle::file_handle(file* f): m_file(f)
|
||||
{
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
global_file_handles.insert(this);
|
||||
if (f) print_backtrace(stack, sizeof(stack), 10);
|
||||
else stack[0] = 0;
|
||||
}
|
||||
file_handle::file_handle(file_handle const& fh)
|
||||
{
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
global_file_handles.insert(this);
|
||||
m_file = fh.m_file;
|
||||
if (m_file) print_backtrace(stack, sizeof(stack), 10);
|
||||
|
@ -2284,7 +2283,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
}
|
||||
file_handle::~file_handle()
|
||||
{
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
global_file_handles.erase(this);
|
||||
stack[0] = 0;
|
||||
}
|
||||
|
@ -2297,7 +2296,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
file_handle::operator bool() const { return m_file.get(); }
|
||||
file_handle& file_handle::reset(file* f)
|
||||
{
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
if (f) print_backtrace(stack, sizeof(stack), 10);
|
||||
else stack[0] = 0;
|
||||
l.unlock();
|
||||
|
@ -2308,7 +2307,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
void print_open_files(char const* event, char const* name)
|
||||
{
|
||||
FILE* out = fopen("open_files.log", "a+");
|
||||
mutex::scoped_lock l(file_handle_mutex);
|
||||
std::lock_guard<std::mutex> l(file_handle_mutex);
|
||||
fprintf(out, "\n\nEVENT: %s TORRENT: %s\n\n", event, name);
|
||||
for (std::set<file_handle*>::iterator i = global_file_handles.begin()
|
||||
, end(global_file_handles.end()); i != end; ++i)
|
||||
|
|
|
@ -129,12 +129,12 @@ namespace libtorrent
|
|||
{
|
||||
// potentially used to hold a reference to a file object that's
|
||||
// about to be destructed. If we have such object we assign it to
|
||||
// this member to be destructed after we release the mutex. On some
|
||||
// this member to be destructed after we release the std::mutex. On some
|
||||
// operating systems (such as OSX) closing a file may take a long
|
||||
// time. We don't want to hold the mutex for that.
|
||||
// time. We don't want to hold the std::mutex for that.
|
||||
file_handle defer_destruction;
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
// we're not allowed to open a file
|
||||
|
@ -230,7 +230,7 @@ namespace libtorrent
|
|||
|
||||
void file_pool::get_status(std::vector<pool_file_status>* files, void* st) const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
file_set::const_iterator start = m_files.lower_bound(std::make_pair(st, 0));
|
||||
file_set::const_iterator end = m_files.upper_bound(std::make_pair(st, INT_MAX));
|
||||
|
@ -245,7 +245,7 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
void file_pool::remove_oldest(mutex::scoped_lock& l)
|
||||
void file_pool::remove_oldest(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
file_set::iterator i = std::min_element(m_files.begin(), m_files.end()
|
||||
, boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _1))
|
||||
|
@ -263,7 +263,7 @@ namespace libtorrent
|
|||
|
||||
void file_pool::release(void* st, int file_index)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
file_set::iterator i = m_files.find(std::make_pair(st, file_index));
|
||||
if (i == m_files.end()) return;
|
||||
|
@ -280,7 +280,7 @@ namespace libtorrent
|
|||
// storage. If 0 is passed, all files are closed
|
||||
void file_pool::release(void* st)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
if (st == 0)
|
||||
{
|
||||
|
@ -309,7 +309,7 @@ namespace libtorrent
|
|||
#if TORRENT_USE_ASSERTS
|
||||
void file_pool::mark_deleted(file_storage const& fs)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
m_deleted_storages.push_back(std::make_pair(fs.name()
|
||||
, static_cast<void const*>(&fs)));
|
||||
if(m_deleted_storages.size() > 100)
|
||||
|
@ -318,7 +318,7 @@ namespace libtorrent
|
|||
|
||||
bool file_pool::assert_idle_files(void* st) const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
for (file_set::const_iterator i = m_files.begin();
|
||||
i != m_files.end(); ++i)
|
||||
|
@ -332,7 +332,7 @@ namespace libtorrent
|
|||
|
||||
void file_pool::resize(int size)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(size > 0);
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/time.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/debug.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
|
|
|
@ -727,7 +727,7 @@ time_duration node::connection_timeout()
|
|||
void node::status(std::vector<dht_routing_bucket>& table
|
||||
, std::vector<dht_lookup>& requests)
|
||||
{
|
||||
mutex_t::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
m_table.status(table);
|
||||
|
||||
|
@ -756,7 +756,7 @@ void node::update_stats_counters(counters& c) const
|
|||
// TODO: 2 use the non deprecated function instead of this one
|
||||
void node::status(session_status& s)
|
||||
{
|
||||
mutex_t::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
m_table.status(s);
|
||||
s.dht_torrents = int(m_storage->num_torrents());
|
||||
|
|
|
@ -83,7 +83,7 @@ natpmp::natpmp(io_service& ios
|
|||
|
||||
void natpmp::start()
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
error_code ec;
|
||||
address gateway = get_default_gateway(m_socket.get_io_service(), ec);
|
||||
|
@ -137,7 +137,7 @@ void natpmp::start()
|
|||
}
|
||||
}
|
||||
|
||||
void natpmp::send_get_ip_address_request(mutex::scoped_lock& l)
|
||||
void natpmp::send_get_ip_address_request(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
using namespace libtorrent::detail;
|
||||
|
||||
|
@ -153,7 +153,7 @@ void natpmp::send_get_ip_address_request(mutex::scoped_lock& l)
|
|||
|
||||
bool natpmp::get_mapping(int index, int& local_port, int& external_port, int& protocol) const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(index < int(m_mappings.size()) && index >= 0);
|
||||
if (index >= int(m_mappings.size()) || index < 0) return false;
|
||||
|
@ -165,14 +165,14 @@ bool natpmp::get_mapping(int index, int& local_port, int& external_port, int& pr
|
|||
return true;
|
||||
}
|
||||
|
||||
void natpmp::log(char const* msg, mutex::scoped_lock& l)
|
||||
void natpmp::log(char const* msg, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
l.unlock();
|
||||
m_log_callback(msg);
|
||||
l.lock();
|
||||
}
|
||||
|
||||
void natpmp::disable(error_code const& ec, mutex::scoped_lock& l)
|
||||
void natpmp::disable(error_code const& ec, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
m_disabled = true;
|
||||
|
||||
|
@ -192,7 +192,7 @@ void natpmp::disable(error_code const& ec, mutex::scoped_lock& l)
|
|||
|
||||
void natpmp::delete_mapping(int index)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(index < int(m_mappings.size()) && index >= 0);
|
||||
if (index >= int(m_mappings.size()) || index < 0) return;
|
||||
|
@ -212,7 +212,7 @@ void natpmp::delete_mapping(int index)
|
|||
|
||||
int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
if (m_disabled) return -1;
|
||||
|
||||
|
@ -249,7 +249,7 @@ int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
|
|||
return mapping_index;
|
||||
}
|
||||
|
||||
void natpmp::try_next_mapping(int i, mutex::scoped_lock& l)
|
||||
void natpmp::try_next_mapping(int i, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
#ifdef NATPMP_LOG
|
||||
time_point now = aux::time_now();
|
||||
|
@ -296,7 +296,7 @@ void natpmp::try_next_mapping(int i, mutex::scoped_lock& l)
|
|||
update_mapping(m - m_mappings.begin(), l);
|
||||
}
|
||||
|
||||
void natpmp::update_mapping(int i, mutex::scoped_lock& l)
|
||||
void natpmp::update_mapping(int i, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
if (i == int(m_mappings.size()))
|
||||
{
|
||||
|
@ -329,7 +329,7 @@ void natpmp::update_mapping(int i, mutex::scoped_lock& l)
|
|||
}
|
||||
}
|
||||
|
||||
void natpmp::send_map_request(int i, mutex::scoped_lock& l)
|
||||
void natpmp::send_map_request(int i, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
using namespace libtorrent::detail;
|
||||
|
||||
|
@ -383,7 +383,7 @@ void natpmp::resend_request(int i, error_code const& e)
|
|||
{
|
||||
COMPLETE_ASYNC("natpmp::resend_request");
|
||||
if (e) return;
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
if (m_currently_mapping != i) return;
|
||||
|
||||
// if we're shutting down, don't retry, just move on
|
||||
|
@ -403,7 +403,7 @@ void natpmp::resend_request(int i, error_code const& e)
|
|||
void natpmp::on_reply(error_code const& e
|
||||
, std::size_t bytes_transferred)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
COMPLETE_ASYNC("natpmp::on_reply");
|
||||
|
||||
|
@ -575,7 +575,7 @@ void natpmp::on_reply(error_code const& e
|
|||
try_next_mapping(index, l);
|
||||
}
|
||||
|
||||
void natpmp::update_expiration_timer(mutex::scoped_lock& l)
|
||||
void natpmp::update_expiration_timer(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
if (m_abort) return;
|
||||
|
||||
|
@ -643,7 +643,7 @@ void natpmp::mapping_expired(error_code const& e, int i)
|
|||
{
|
||||
COMPLETE_ASYNC("natpmp::mapping_expired");
|
||||
if (e) return;
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
char msg[200];
|
||||
snprintf(msg, sizeof(msg), "mapping %u expired", i);
|
||||
log(msg, l);
|
||||
|
@ -654,11 +654,11 @@ void natpmp::mapping_expired(error_code const& e, int i)
|
|||
|
||||
void natpmp::close()
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
close_impl(l);
|
||||
}
|
||||
|
||||
void natpmp::close_impl(mutex::scoped_lock& l)
|
||||
void natpmp::close_impl(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
m_abort = true;
|
||||
log("closing", l);
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace libtorrent
|
|||
int part_file::writev(file::iovec_t const* bufs, int num_bufs, int piece, int offset, error_code& ec)
|
||||
{
|
||||
TORRENT_ASSERT(offset >= 0);
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
open_file(file::read_write, ec);
|
||||
if (ec) return -1;
|
||||
|
@ -200,7 +200,7 @@ namespace libtorrent
|
|||
, int piece, int offset, error_code& ec)
|
||||
{
|
||||
TORRENT_ASSERT(offset >= 0);
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
boost::unordered_map<int, int>::iterator i = m_piece_map.find(piece);
|
||||
if (i == m_piece_map.end())
|
||||
|
@ -244,7 +244,7 @@ namespace libtorrent
|
|||
|
||||
void part_file::free_piece(int piece)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
boost::unordered_map<int, int>::iterator i = m_piece_map.find(piece);
|
||||
if (i == m_piece_map.end()) return;
|
||||
|
@ -261,7 +261,7 @@ namespace libtorrent
|
|||
|
||||
void part_file::move_partfile(std::string const& path, error_code& ec)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
flush_metadata_impl(ec);
|
||||
if (ec) return;
|
||||
|
@ -301,7 +301,7 @@ namespace libtorrent
|
|||
|
||||
void part_file::export_file(file& f, boost::int64_t offset, boost::int64_t size, error_code& ec)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
int piece = offset / m_piece_size;
|
||||
int const end = ((offset + size) + m_piece_size - 1) / m_piece_size;
|
||||
|
@ -366,7 +366,7 @@ namespace libtorrent
|
|||
|
||||
void part_file::flush_metadata(error_code& ec)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
flush_metadata_impl(ec);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace libtorrent {
|
|||
c.m_stats_counter[i].load(boost::memory_order_relaxed)
|
||||
, boost::memory_order_relaxed);
|
||||
#else
|
||||
mutex::scoped_lock l(c.m_mutex);
|
||||
std::lock_guard<std::mutex> l(c.m_mutex);
|
||||
memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter));
|
||||
#endif
|
||||
}
|
||||
|
@ -75,8 +75,8 @@ namespace libtorrent {
|
|||
c.m_stats_counter[i].load(boost::memory_order_relaxed)
|
||||
, boost::memory_order_relaxed);
|
||||
#else
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
mutex::scoped_lock l2(c.m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
std::lock_guard<std::mutex> l2(c.m_mutex);
|
||||
memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter));
|
||||
#endif
|
||||
return *this;
|
||||
|
@ -93,7 +93,7 @@ namespace libtorrent {
|
|||
#if BOOST_ATOMIC_LLONG_LOCK_FREE == 2
|
||||
return m_stats_counter[i].load(boost::memory_order_relaxed);
|
||||
#else
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
return m_stats_counter[i];
|
||||
#endif
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ namespace libtorrent {
|
|||
TORRENT_ASSERT(pv + value >= 0);
|
||||
return pv + value;
|
||||
#else
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
TORRENT_ASSERT(m_stats_counter[c] + value >= 0);
|
||||
return m_stats_counter[c] += value;
|
||||
#endif
|
||||
|
@ -139,7 +139,7 @@ namespace libtorrent {
|
|||
new_value = (current * (100-ratio) + value * ratio) / 100;
|
||||
}
|
||||
#else
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
boost::int64_t current = m_stats_counter[c];
|
||||
m_stats_counter[c] = (current * (100-ratio) + value * ratio) / 100;
|
||||
#endif
|
||||
|
@ -153,7 +153,7 @@ namespace libtorrent {
|
|||
#if BOOST_ATOMIC_LLONG_LOCK_FREE == 2
|
||||
m_stats_counter[c].store(value);
|
||||
#else
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
// if this assert fires, someone is trying to decrement a counter
|
||||
// which is not allowed. Counters are monotonically increasing
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace libtorrent
|
|||
|
||||
boost::uint32_t random()
|
||||
{
|
||||
// TODO: versions prior to msvc-14 (visual studio 2015) do
|
||||
// not generate thread safe initialization of statics
|
||||
static random_device dev;
|
||||
static mt19937 random_engine(dev());
|
||||
return uniform_int_distribution<boost::uint32_t>(0, UINT_MAX)(random_engine);
|
||||
|
|
|
@ -40,6 +40,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <deque>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -369,8 +371,8 @@ namespace libtorrent
|
|||
if (internal_executor)
|
||||
{
|
||||
// start a thread for the message pump
|
||||
m_thread = boost::make_shared<thread>(boost::bind(&io_service::run
|
||||
, m_io_service.get()));
|
||||
m_thread = std::make_shared<std::thread>(
|
||||
[&]() { m_io_service->run(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace libtorrent { namespace aux {
|
||||
|
||||
#ifdef TORRENT_PROFILE_CALLS
|
||||
static mutex g_calls_mutex;
|
||||
static std::mutex g_calls_mutex;
|
||||
static boost::unordered_map<std::string, int> g_blocking_calls;
|
||||
#endif
|
||||
|
||||
|
@ -44,7 +44,7 @@ void blocking_call()
|
|||
#ifdef TORRENT_PROFILE_CALLS
|
||||
char stack[2048];
|
||||
print_backtrace(stack, sizeof(stack), 20);
|
||||
mutex::scoped_lock l(g_calls_mutex);
|
||||
std::unique_lock<std::mutex> l(g_calls_mutex);
|
||||
g_blocking_calls[stack] += 1;
|
||||
#endif
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ void dump_call_profile()
|
|||
|
||||
std::map<int, std::string> profile;
|
||||
|
||||
mutex::scoped_lock l(g_calls_mutex);
|
||||
std::unique_lock<std::mutex> l(g_calls_mutex);
|
||||
for (boost::unordered_map<std::string, int>::const_iterator i = g_blocking_calls.begin()
|
||||
, end(g_blocking_calls.end()); i != end; ++i)
|
||||
{
|
||||
|
@ -71,10 +71,10 @@ void dump_call_profile()
|
|||
#endif
|
||||
}
|
||||
|
||||
void fun_wrap(bool& done, condition_variable& e, mutex& m, boost::function<void(void)> f)
|
||||
void fun_wrap(bool& done, std::condition_variable& e, std::mutex& m, boost::function<void(void)> f)
|
||||
{
|
||||
f();
|
||||
mutex::scoped_lock l(m);
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
done = true;
|
||||
e.notify_all();
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ void fun_wrap(bool& done, condition_variable& e, mutex& m, boost::function<void(
|
|||
void torrent_wait(bool& done, aux::session_impl& ses)
|
||||
{
|
||||
blocking_call();
|
||||
mutex::scoped_lock l(ses.mut);
|
||||
std::unique_lock<std::mutex> l(ses.mut);
|
||||
while (!done) { ses.cond.wait(l); };
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ namespace libtorrent {
|
|||
std::map<std::string, async_t> _async_ops;
|
||||
std::deque<wakeup_t> _wakeups;
|
||||
int _async_ops_nthreads = 0;
|
||||
mutex _async_ops_mutex;
|
||||
std::mutex _async_ops_mutex;
|
||||
#endif
|
||||
|
||||
socket_job::~socket_job() {}
|
||||
|
@ -6078,6 +6078,7 @@ namespace aux {
|
|||
|
||||
void session_impl::update_network_threads()
|
||||
{
|
||||
// TODO: 3 this is a mess
|
||||
int num_threads = m_settings.get_int(settings_pack::network_threads);
|
||||
int num_pools = num_threads > 0 ? num_threads : 1;
|
||||
while (num_pools > m_net_thread_pool.size())
|
||||
|
|
|
@ -180,7 +180,7 @@ namespace libtorrent
|
|||
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
static boost::atomic<int> event_id;
|
||||
static mutex disk_access_mutex;
|
||||
static std::mutex disk_access_mutex;
|
||||
|
||||
// this is opened and closed by the disk_io_thread class
|
||||
FILE* g_access_log = NULL;
|
||||
|
@ -210,7 +210,7 @@ namespace libtorrent
|
|||
detail::write_uint32(fileid, ptr);
|
||||
detail::write_uint8(flags, ptr);
|
||||
|
||||
mutex::scoped_lock l(disk_access_mutex);
|
||||
std::unique_lock<std::mutex> l(disk_access_mutex);
|
||||
int ret = fwrite(event, 1, sizeof(event), g_access_log);
|
||||
l.unlock();
|
||||
if (ret != sizeof(event))
|
||||
|
@ -1513,7 +1513,7 @@ namespace libtorrent
|
|||
|
||||
int disk_job_fence::job_complete(disk_io_job* j, tailqueue<disk_io_job>& jobs)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(j->flags & disk_io_job::in_progress);
|
||||
j->flags &= ~disk_io_job::in_progress;
|
||||
|
@ -1604,7 +1604,7 @@ namespace libtorrent
|
|||
|
||||
bool disk_job_fence::is_blocked(disk_io_job* j)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
DLOG(stderr, "[%p] is_blocked: fence: %d num_outstanding: %d\n"
|
||||
, static_cast<void*>(this), m_has_fence, int(m_outstanding_jobs));
|
||||
|
||||
|
@ -1631,13 +1631,13 @@ namespace libtorrent
|
|||
|
||||
bool disk_job_fence::has_fence() const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
return m_has_fence != 0;
|
||||
}
|
||||
|
||||
int disk_job_fence::num_blocked() const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
return m_blocked_jobs.size();
|
||||
}
|
||||
|
||||
|
@ -1650,7 +1650,7 @@ namespace libtorrent
|
|||
TORRENT_ASSERT((j->flags & disk_io_job::fence) == 0);
|
||||
j->flags |= disk_io_job::fence;
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
DLOG(stderr, "[%p] raise_fence: fence: %d num_outstanding: %d\n"
|
||||
, static_cast<void*>(this), m_has_fence, int(m_outstanding_jobs));
|
||||
|
|
|
@ -30,7 +30,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
|
||||
#ifdef TORRENT_BEOS
|
||||
|
@ -60,26 +59,26 @@ namespace libtorrent
|
|||
|
||||
#ifdef BOOST_HAS_PTHREADS
|
||||
|
||||
condition_variable::condition_variable()
|
||||
std::condition_variable::condition_variable()
|
||||
{
|
||||
pthread_cond_init(&m_cond, 0);
|
||||
}
|
||||
|
||||
condition_variable::~condition_variable()
|
||||
std::condition_variable::~condition_variable()
|
||||
{
|
||||
pthread_cond_destroy(&m_cond);
|
||||
}
|
||||
|
||||
void condition_variable::wait(mutex::scoped_lock& l)
|
||||
void std::condition_variable::wait(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
// wow, this is quite a hack
|
||||
pthread_cond_wait(&m_cond, reinterpret_cast<pthread_mutex_t*>(&l.mutex()));
|
||||
}
|
||||
|
||||
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time)
|
||||
void std::condition_variable::wait_for(std::unique_lock<std::mutex>& l, time_duration rel_time)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
|
@ -92,17 +91,17 @@ namespace libtorrent
|
|||
pthread_cond_timedwait(&m_cond, reinterpret_cast<pthread_mutex_t*>(&l.mutex()), &ts);
|
||||
}
|
||||
|
||||
void condition_variable::notify_all()
|
||||
void std::condition_variable::notify_all()
|
||||
{
|
||||
pthread_cond_broadcast(&m_cond);
|
||||
}
|
||||
|
||||
void condition_variable::notify()
|
||||
void std::condition_variable::notify()
|
||||
{
|
||||
pthread_cond_signal(&m_cond);
|
||||
}
|
||||
#elif defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
|
||||
condition_variable::condition_variable()
|
||||
std::condition_variable::condition_variable()
|
||||
: m_num_waiters(0)
|
||||
{
|
||||
#if _WIN32_WINNT == 0x0501
|
||||
|
@ -112,14 +111,14 @@ namespace libtorrent
|
|||
#endif
|
||||
}
|
||||
|
||||
condition_variable::~condition_variable()
|
||||
std::condition_variable::~condition_variable()
|
||||
{
|
||||
CloseHandle(m_sem);
|
||||
}
|
||||
|
||||
void condition_variable::wait(mutex::scoped_lock& l)
|
||||
void std::condition_variable::wait(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
++m_num_waiters;
|
||||
l.unlock();
|
||||
WaitForSingleObjectEx(m_sem, INFINITE, FALSE);
|
||||
|
@ -127,9 +126,9 @@ namespace libtorrent
|
|||
--m_num_waiters;
|
||||
}
|
||||
|
||||
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time)
|
||||
void std::condition_variable::wait_for(std::unique_lock<std::mutex>& l, time_duration rel_time)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
++m_num_waiters;
|
||||
l.unlock();
|
||||
WaitForSingleObjectEx(m_sem, total_milliseconds(rel_time), FALSE);
|
||||
|
@ -137,30 +136,30 @@ namespace libtorrent
|
|||
--m_num_waiters;
|
||||
}
|
||||
|
||||
void condition_variable::notify_all()
|
||||
void std::condition_variable::notify_all()
|
||||
{
|
||||
ReleaseSemaphore(m_sem, m_num_waiters, 0);
|
||||
}
|
||||
|
||||
void condition_variable::notify()
|
||||
void std::condition_variable::notify()
|
||||
{
|
||||
ReleaseSemaphore(m_sem, (std::min)(m_num_waiters, 1), 0);
|
||||
}
|
||||
#elif defined TORRENT_BEOS
|
||||
condition_variable::condition_variable()
|
||||
std::condition_variable::condition_variable()
|
||||
: m_num_waiters(0)
|
||||
{
|
||||
m_sem = create_sem(0, 0);
|
||||
}
|
||||
|
||||
condition_variable::~condition_variable()
|
||||
std::condition_variable::~condition_variable()
|
||||
{
|
||||
delete_sem(m_sem);
|
||||
}
|
||||
|
||||
void condition_variable::wait(mutex::scoped_lock& l)
|
||||
void std::condition_variable::wait(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
++m_num_waiters;
|
||||
l.unlock();
|
||||
acquire_sem(m_sem);
|
||||
|
@ -168,9 +167,9 @@ namespace libtorrent
|
|||
--m_num_waiters;
|
||||
}
|
||||
|
||||
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time)
|
||||
void std::condition_variable::wait_for(std::unique_lock<std::mutex>& l, time_duration rel_time)
|
||||
{
|
||||
TORRENT_ASSERT(l.locked());
|
||||
TORRENT_ASSERT(l.owns_lock());
|
||||
++m_num_waiters;
|
||||
l.unlock();
|
||||
acquire_sem_etc(m_sem, 1, B_RELATIVE_TIMEOUT, total_microseconds(rel_time));
|
||||
|
@ -178,12 +177,12 @@ namespace libtorrent
|
|||
--m_num_waiters;
|
||||
}
|
||||
|
||||
void condition_variable::notify_all()
|
||||
void std::condition_variable::notify_all()
|
||||
{
|
||||
release_sem_etc(m_sem, m_num_waiters, 0);
|
||||
}
|
||||
|
||||
void condition_variable::notify()
|
||||
void std::condition_variable::notify()
|
||||
{
|
||||
release_sem_etc(m_sem, (std::min)(m_num_waiters, 1), 0);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/aux_/session_call.hpp"
|
||||
#include "libtorrent/invariant_check.hpp"
|
||||
#include "libtorrent/utf8.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
|
||||
#if TORRENT_COMPLETE_TYPES_REQUIRED
|
||||
|
@ -653,11 +652,11 @@ namespace libtorrent
|
|||
{
|
||||
static boost::shared_ptr<const torrent_info> holder[4];
|
||||
static int cursor = 0;
|
||||
static mutex holder_mutex;
|
||||
static std::mutex holder_mutex;
|
||||
|
||||
boost::shared_ptr<const torrent_info> r = torrent_file();
|
||||
|
||||
mutex::scoped_lock l(holder_mutex);
|
||||
std::lock_guard<std::mutex> l(holder_mutex);
|
||||
holder[cursor++] = r;
|
||||
cursor = cursor % (sizeof(holder) / sizeof(holder[0]));
|
||||
return *r;
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace libtorrent
|
|||
|
||||
void tracker_manager::remove_request(tracker_connection const* c)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
|
||||
http_conns_t::iterator i = std::find_if(m_http_conns.begin()
|
||||
, m_http_conns.end()
|
||||
|
@ -270,7 +270,7 @@ namespace libtorrent
|
|||
, tracker_request req
|
||||
, boost::weak_ptr<request_callback> c)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
TORRENT_ASSERT(req.num_want >= 0);
|
||||
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
|
||||
if (m_abort && req.event != tracker_request::stopped) return;
|
||||
|
@ -405,7 +405,7 @@ namespace libtorrent
|
|||
void tracker_manager::abort_all_requests(bool all)
|
||||
{
|
||||
// removes all connections except 'event=stopped'-requests
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
m_abort = true;
|
||||
http_conns_t close_http_connections;
|
||||
|
@ -459,13 +459,13 @@ namespace libtorrent
|
|||
|
||||
bool tracker_manager::empty() const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
return m_http_conns.empty() && m_udp_conns.empty();
|
||||
}
|
||||
|
||||
int tracker_manager::num_requests() const
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
return m_http_conns.size() + m_udp_conns.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace libtorrent
|
|||
std::map<address, udp_tracker_connection::connection_cache_entry>
|
||||
udp_tracker_connection::m_connection_cache;
|
||||
|
||||
mutex udp_tracker_connection::m_cache_mutex;
|
||||
std::mutex udp_tracker_connection::m_cache_mutex;
|
||||
|
||||
udp_tracker_connection::udp_tracker_connection(
|
||||
io_service& ios
|
||||
|
@ -277,7 +277,7 @@ namespace libtorrent
|
|||
|
||||
void udp_tracker_connection::start_announce()
|
||||
{
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::unique_lock<std::mutex> l(m_cache_mutex);
|
||||
std::map<address, connection_cache_entry>::iterator cc
|
||||
= m_connection_cache.find(m_target.address());
|
||||
if (cc != m_connection_cache.end())
|
||||
|
@ -463,7 +463,7 @@ namespace libtorrent
|
|||
update_transaction_id();
|
||||
boost::uint64_t const connection_id = read_int64(buf);
|
||||
|
||||
mutex::scoped_lock l(m_cache_mutex);
|
||||
std::lock_guard<std::mutex> l(m_cache_mutex);
|
||||
connection_cache_entry& cce = m_connection_cache[m_target.address()];
|
||||
cce.connection_id = connection_id;
|
||||
cce.expires = aux::time_now() + seconds(m_man.settings().get_int(settings_pack::udp_tracker_token_expiry));
|
||||
|
|
46
src/upnp.cpp
46
src/upnp.cpp
|
@ -107,21 +107,21 @@ upnp::~upnp()
|
|||
|
||||
void upnp::discover_device()
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
if (m_socket.num_send_sockets() == 0)
|
||||
log("No network interfaces to broadcast to", l);
|
||||
|
||||
discover_device_impl(l);
|
||||
}
|
||||
|
||||
void upnp::log(char const* msg, mutex::scoped_lock& l)
|
||||
void upnp::log(char const* msg, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
l.unlock();
|
||||
m_log_callback(msg);
|
||||
l.lock();
|
||||
}
|
||||
|
||||
void upnp::discover_device_impl(mutex::scoped_lock& l)
|
||||
void upnp::discover_device_impl(std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
const char msearch[] =
|
||||
"M-SEARCH * HTTP/1.1\r\n"
|
||||
|
@ -163,7 +163,7 @@ int upnp::add_mapping(upnp::protocol_type p, int external_port, int local_port)
|
|||
// external port 0 means _every_ port
|
||||
TORRENT_ASSERT(external_port != 0);
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
char msg[500];
|
||||
snprintf(msg, sizeof(msg), "adding port map: [ protocol: %s ext_port: %u "
|
||||
|
@ -211,7 +211,7 @@ int upnp::add_mapping(upnp::protocol_type p, int external_port, int local_port)
|
|||
|
||||
void upnp::delete_mapping(int mapping)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
if (mapping >= int(m_mappings.size())) return;
|
||||
|
||||
|
@ -257,7 +257,7 @@ void upnp::resend_request(error_code const& ec)
|
|||
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
if (m_closing) return;
|
||||
|
||||
|
@ -312,7 +312,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
|
|||
{
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
using namespace libtorrent::detail;
|
||||
|
||||
|
@ -557,11 +557,11 @@ void upnp::map_timer(error_code const& ec)
|
|||
if (ec) return;
|
||||
if (m_closing) return;
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
try_map_upnp(l, true);
|
||||
}
|
||||
|
||||
void upnp::try_map_upnp(mutex::scoped_lock& l, bool timer)
|
||||
void upnp::try_map_upnp(std::unique_lock<std::mutex>& l, bool timer)
|
||||
{
|
||||
if (m_devices.empty()) return;
|
||||
|
||||
|
@ -627,7 +627,7 @@ void upnp::try_map_upnp(mutex::scoped_lock& l, bool timer)
|
|||
}
|
||||
|
||||
void upnp::post(upnp::rootdevice const& d, char const* soap
|
||||
, char const* soap_action, mutex::scoped_lock& l)
|
||||
, char const* soap_action, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
TORRENT_ASSERT(d.upnp_connection);
|
||||
|
@ -652,7 +652,7 @@ void upnp::post(upnp::rootdevice const& d, char const* soap
|
|||
|
||||
void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
|
||||
|
@ -694,7 +694,7 @@ void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
|
|||
post(d, soap, soap_action, l);
|
||||
}
|
||||
|
||||
void upnp::next(rootdevice& d, int i, mutex::scoped_lock& l)
|
||||
void upnp::next(rootdevice& d, int i, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
if (i < num_mappings() - 1)
|
||||
{
|
||||
|
@ -711,7 +711,7 @@ void upnp::next(rootdevice& d, int i, mutex::scoped_lock& l)
|
|||
}
|
||||
}
|
||||
|
||||
void upnp::update_map(rootdevice& d, int i, mutex::scoped_lock& l)
|
||||
void upnp::update_map(rootdevice& d, int i, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
TORRENT_ASSERT(i < int(d.mapping.size()));
|
||||
|
@ -777,7 +777,7 @@ void upnp::update_map(rootdevice& d, int i, mutex::scoped_lock& l)
|
|||
|
||||
void upnp::delete_port_mapping(rootdevice& d, int i)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
|
||||
|
@ -880,7 +880,7 @@ void upnp::on_upnp_xml(error_code const& e
|
|||
{
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||
|
@ -993,7 +993,7 @@ void upnp::on_upnp_xml(error_code const& e
|
|||
|
||||
void upnp::get_ip_address(rootdevice& d)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ void upnp::get_ip_address(rootdevice& d)
|
|||
post(d, soap, soap_action, l);
|
||||
}
|
||||
|
||||
void upnp::disable(error_code const& ec, mutex::scoped_lock& l)
|
||||
void upnp::disable(error_code const& ec, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
m_disabled = true;
|
||||
|
||||
|
@ -1163,7 +1163,7 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e
|
|||
{
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||
|
@ -1246,7 +1246,7 @@ void upnp::on_upnp_map_response(error_code const& e
|
|||
{
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||
|
@ -1388,7 +1388,7 @@ void upnp::on_upnp_map_response(error_code const& e
|
|||
next(d, mapping, l);
|
||||
}
|
||||
|
||||
void upnp::return_error(int mapping, int code, mutex::scoped_lock& l)
|
||||
void upnp::return_error(int mapping, int code, std::unique_lock<std::mutex>& l)
|
||||
{
|
||||
int num_errors = sizeof(error_codes) / sizeof(error_codes[0]);
|
||||
error_code_t* end = error_codes + num_errors;
|
||||
|
@ -1414,7 +1414,7 @@ void upnp::on_upnp_unmap_response(error_code const& e
|
|||
{
|
||||
boost::shared_ptr<upnp> me(self());
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
TORRENT_ASSERT(d.magic == 1337);
|
||||
if (d.upnp_connection && d.upnp_connection.get() == &c)
|
||||
|
@ -1478,7 +1478,7 @@ void upnp::on_expire(error_code const& ec)
|
|||
time_point now = aux::time_now();
|
||||
time_point next_expire = max_time();
|
||||
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
for (std::set<rootdevice>::iterator i = m_devices.begin()
|
||||
, end(m_devices.end()); i != end; ++i)
|
||||
|
@ -1512,7 +1512,7 @@ void upnp::on_expire(error_code const& ec)
|
|||
|
||||
void upnp::close()
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
error_code ec;
|
||||
m_refresh_timer.cancel(ec);
|
||||
|
|
|
@ -63,7 +63,7 @@ char const* socket_state_names[] = { "NONE", "SYN_SENT", "CONNECTED", "FIN_SENT"
|
|||
static struct utp_logger
|
||||
{
|
||||
FILE* utp_log_file;
|
||||
mutex utp_log_mutex;
|
||||
std::mutex utp_log_mutex;
|
||||
|
||||
utp_logger() : utp_log_file(NULL) {}
|
||||
~utp_logger()
|
||||
|
@ -77,7 +77,7 @@ void utp_log(char const* fmt, ...)
|
|||
{
|
||||
if (log_file_holder.utp_log_file == NULL) return;
|
||||
|
||||
mutex::scoped_lock lock(log_file_holder.utp_log_mutex);
|
||||
std::lock_guard<std::mutex> lock(log_file_holder.utp_log_mutex);
|
||||
static time_point start = clock_type::now();
|
||||
fprintf(log_file_holder.utp_log_file, "[%012" PRId64 "] ", total_microseconds(clock_type::now() - start));
|
||||
va_list l;
|
||||
|
|
|
@ -30,7 +30,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
|
@ -43,12 +42,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
struct dht_server
|
||||
|
@ -59,7 +61,7 @@ struct dht_server
|
|||
udp::socket m_socket;
|
||||
int m_port;
|
||||
|
||||
boost::shared_ptr<libtorrent::thread> m_thread;
|
||||
boost::shared_ptr<std::thread> m_thread;
|
||||
|
||||
dht_server()
|
||||
: m_dht_requests(0)
|
||||
|
@ -89,7 +91,7 @@ struct dht_server
|
|||
|
||||
fprintf(stderr, "%s: DHT initialized on port %d\n", time_now_string(), m_port);
|
||||
|
||||
m_thread.reset(new libtorrent::thread(boost::bind(&dht_server::thread_fun, this)));
|
||||
m_thread = boost::make_shared<std::thread>(&dht_server::thread_fun, this);
|
||||
}
|
||||
|
||||
~dht_server()
|
||||
|
|
|
@ -30,7 +30,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
|
@ -44,8 +43,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
struct peer_server
|
||||
|
@ -56,7 +59,7 @@ struct peer_server
|
|||
tcp::acceptor m_acceptor;
|
||||
int m_port;
|
||||
|
||||
boost::shared_ptr<libtorrent::thread> m_thread;
|
||||
std::shared_ptr<std::thread> m_thread;
|
||||
|
||||
peer_server()
|
||||
: m_peer_requests(0)
|
||||
|
@ -92,7 +95,7 @@ struct peer_server
|
|||
|
||||
fprintf(stderr, "%s: PEER peer initialized on port %d\n", time_now_string(), m_port);
|
||||
|
||||
m_thread.reset(new libtorrent::thread(boost::bind(&peer_server::thread_fun, this)));
|
||||
m_thread = std::make_shared<std::thread>(&peer_server::thread_fun, this);
|
||||
}
|
||||
|
||||
~peer_server()
|
||||
|
@ -119,7 +122,7 @@ struct peer_server
|
|||
error_code ec;
|
||||
tcp::endpoint from;
|
||||
tcp::socket socket(m_ios);
|
||||
condition_variable cond;
|
||||
std::condition_variable cond;
|
||||
bool done = false;
|
||||
m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
|
||||
while (!done)
|
||||
|
|
|
@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/http_parser.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
|
@ -46,7 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/instantiate_connection.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
#include "libtorrent/session_stats.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6()
|
||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/random.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
|
|
@ -35,13 +35,14 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/torrent_handle.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/extensions.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "setup_transfer.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
TORRENT_TEST(limit)
|
||||
|
@ -258,7 +259,7 @@ TORRENT_TEST(wait_for_alert)
|
|||
mgr.get_all(alerts);
|
||||
|
||||
start = clock_type::now();
|
||||
libtorrent::thread posting_thread(boost::bind(&post_torrent_added, &mgr));
|
||||
std::thread posting_thread(&post_torrent_added, &mgr);
|
||||
|
||||
a = mgr.wait_for_alert(seconds(10));
|
||||
end = clock_type::now();
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/torrent_status.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include "test.hpp"
|
||||
|
|
|
@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session_settings.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/extensions/ut_pex.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/ip_filter.hpp"
|
||||
#include "libtorrent/torrent_status.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/error_code.hpp"
|
||||
|
|
|
@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/session.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/session_status.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
|
|
|
@ -42,7 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/aux_/session_impl.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/read_resume_data.hpp"
|
||||
|
||||
|
@ -466,7 +465,7 @@ void test_check_files(std::string const& test_path
|
|||
|
||||
boost::shared_ptr<void> dummy;
|
||||
boost::shared_ptr<piece_manager> pm = boost::make_shared<piece_manager>(new default_storage(p), dummy, &fs);
|
||||
libtorrent::mutex lock;
|
||||
std::mutex lock;
|
||||
|
||||
bool done = false;
|
||||
add_torrent_params frd;
|
||||
|
|
|
@ -38,24 +38,23 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "test.hpp"
|
||||
#include "setup_transfer.hpp" // for test_sleep
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
void fun(condition_variable* s, libtorrent::mutex* m, int* waiting, int i)
|
||||
void fun(std::condition_variable* s, std::mutex* m, int* waiting, int i)
|
||||
{
|
||||
fprintf(stderr, "thread %d waiting\n", i);
|
||||
libtorrent::mutex::scoped_lock l(*m);
|
||||
std::unique_lock<std::mutex> l(*m);
|
||||
*waiting += 1;
|
||||
s->wait(l);
|
||||
fprintf(stderr, "thread %d done\n", i);
|
||||
}
|
||||
|
||||
void increment(condition_variable* s, libtorrent::mutex* m, int* waiting, boost::atomic<int>* c)
|
||||
void increment(std::condition_variable* s, std::mutex* m, int* waiting, boost::atomic<int>* c)
|
||||
{
|
||||
libtorrent::mutex::scoped_lock l(*m);
|
||||
std::unique_lock<std::mutex> l(*m);
|
||||
*waiting += 1;
|
||||
s->wait(l);
|
||||
l.unlock();
|
||||
|
@ -63,9 +62,9 @@ void increment(condition_variable* s, libtorrent::mutex* m, int* waiting, boost:
|
|||
++*c;
|
||||
}
|
||||
|
||||
void decrement(condition_variable* s, libtorrent::mutex* m, int* waiting, boost::atomic<int>* c)
|
||||
void decrement(std::condition_variable* s, std::mutex* m, int* waiting, boost::atomic<int>* c)
|
||||
{
|
||||
libtorrent::mutex::scoped_lock l(*m);
|
||||
std::unique_lock<std::mutex> l(*m);
|
||||
*waiting += 1;
|
||||
s->wait(l);
|
||||
l.unlock();
|
||||
|
@ -75,17 +74,17 @@ void decrement(condition_variable* s, libtorrent::mutex* m, int* waiting, boost:
|
|||
|
||||
TORRENT_TEST(threads)
|
||||
{
|
||||
condition_variable cond;
|
||||
libtorrent::mutex m;
|
||||
std::list<libtorrent::thread*> threads;
|
||||
std::condition_variable cond;
|
||||
std::mutex m;
|
||||
std::vector<std::thread> threads;
|
||||
int waiting = 0;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
threads.push_back(new libtorrent::thread(boost::bind(&fun, &cond, &m, &waiting, i)));
|
||||
threads.emplace_back(&fun, &cond, &m, &waiting, i);
|
||||
}
|
||||
|
||||
// make sure all threads are waiting on the condition_variable
|
||||
libtorrent::mutex::scoped_lock l(m);
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
while (waiting < 20)
|
||||
{
|
||||
l.unlock();
|
||||
|
@ -96,19 +95,15 @@ TORRENT_TEST(threads)
|
|||
cond.notify_all();
|
||||
l.unlock();
|
||||
|
||||
for (std::list<libtorrent::thread*>::iterator i = threads.begin(); i != threads.end(); ++i)
|
||||
{
|
||||
(*i)->join();
|
||||
delete *i;
|
||||
}
|
||||
for (auto& t : threads) t.join();
|
||||
threads.clear();
|
||||
|
||||
waiting = 0;
|
||||
boost::atomic<int> c(0);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
threads.push_back(new libtorrent::thread(boost::bind(&increment, &cond, &m, &waiting, &c)));
|
||||
threads.push_back(new libtorrent::thread(boost::bind(&decrement, &cond, &m, &waiting, &c)));
|
||||
threads.emplace_back(&increment, &cond, &m, &waiting, &c);
|
||||
threads.emplace_back(&decrement, &cond, &m, &waiting, &c);
|
||||
}
|
||||
|
||||
// make sure all threads are waiting on the condition_variable
|
||||
|
@ -123,11 +118,7 @@ TORRENT_TEST(threads)
|
|||
cond.notify_all();
|
||||
l.unlock();
|
||||
|
||||
for (std::list<libtorrent::thread*>::iterator i = threads.begin(); i != threads.end(); ++i)
|
||||
{
|
||||
(*i)->join();
|
||||
delete *i;
|
||||
}
|
||||
for (auto& t : threads) t.join();
|
||||
|
||||
TEST_CHECK(c == 0);
|
||||
}
|
||||
|
|
|
@ -34,21 +34,21 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "setup_transfer.hpp" // for test_sleep
|
||||
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <thread>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
void check_timer_loop(mutex& m, time_point& last, condition_variable& cv)
|
||||
void check_timer_loop(std::mutex& m, time_point& last, std::condition_variable& cv)
|
||||
{
|
||||
mutex::scoped_lock l(m);
|
||||
std::unique_lock<std::mutex> l(m);
|
||||
cv.wait(l);
|
||||
l.unlock();
|
||||
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
mutex::scoped_lock l(m);
|
||||
std::lock_guard<std::mutex> l(m);
|
||||
time_point now = clock_type::now();
|
||||
TEST_CHECK(now >= last);
|
||||
last = now;
|
||||
|
@ -80,13 +80,13 @@ TORRENT_TEST(time)
|
|||
TEST_CHECK(now >= last);
|
||||
last = now;
|
||||
}
|
||||
|
||||
mutex m;
|
||||
condition_variable cv;
|
||||
libtorrent::thread t1(boost::bind(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv)));
|
||||
libtorrent::thread t2(boost::bind(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv)));
|
||||
libtorrent::thread t3(boost::bind(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv)));
|
||||
libtorrent::thread t4(boost::bind(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv)));
|
||||
|
||||
std::mutex m;
|
||||
std::condition_variable cv;
|
||||
std::thread t1(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t2(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t3(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
std::thread t4(&check_timer_loop, boost::ref(m), boost::ref(last), boost::ref(cv));
|
||||
|
||||
test_sleep(100);
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/torrent.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
|
@ -83,7 +82,7 @@ struct test_storage : default_storage
|
|||
|
||||
void set_limit(int lim)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::lock_guard<std::mutex> l(m_mutex);
|
||||
m_limit = lim;
|
||||
}
|
||||
|
||||
|
@ -95,7 +94,7 @@ struct test_storage : default_storage
|
|||
, int flags
|
||||
, storage_error& se)
|
||||
{
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
if (m_written >= m_limit)
|
||||
{
|
||||
std::cerr << "storage written: " << m_written << " limit: " << m_limit << std::endl;
|
||||
|
@ -115,7 +114,7 @@ struct test_storage : default_storage
|
|||
|
||||
int m_written;
|
||||
int m_limit;
|
||||
mutex m_mutex;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
storage_interface* test_storage_constructor(storage_params const& params)
|
||||
|
|
|
@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/time.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
|
|
@ -30,7 +30,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
|
@ -45,12 +44,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
struct udp_tracker
|
||||
|
@ -62,7 +64,7 @@ struct udp_tracker
|
|||
int m_port;
|
||||
bool m_abort;
|
||||
|
||||
boost::shared_ptr<libtorrent::thread> m_thread;
|
||||
boost::shared_ptr<std::thread> m_thread;
|
||||
|
||||
void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoint* from, char* buffer, int size)
|
||||
{
|
||||
|
@ -171,7 +173,7 @@ struct udp_tracker
|
|||
|
||||
fprintf(stderr, "%s: UDP tracker initialized on port %d\n", time_now_string(), m_port);
|
||||
|
||||
m_thread.reset(new libtorrent::thread(boost::bind(&udp_tracker::thread_fun, this)));
|
||||
m_thread = boost::make_shared<std::thread>(&udp_tracker::thread_fun, this);
|
||||
}
|
||||
|
||||
void stop()
|
||||
|
|
|
@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/create_torrent.hpp"
|
||||
#include "libtorrent/thread.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/announce_entry.hpp"
|
||||
|
|
Loading…
Reference in New Issue