forked from premiere/premiere-libtorrent
factor out storage_piece_set into its own file
This commit is contained in:
parent
d03540e3b3
commit
c239c2bdc4
|
@ -86,6 +86,7 @@ set(sources
|
|||
stat
|
||||
stat_cache
|
||||
storage
|
||||
storage_piece_set
|
||||
storage_utils
|
||||
time
|
||||
timestamp_history
|
||||
|
|
1
Jamfile
1
Jamfile
|
@ -617,6 +617,7 @@ SOURCES =
|
|||
socks5_stream
|
||||
stat
|
||||
storage
|
||||
storage_piece_set
|
||||
storage_utils
|
||||
torrent
|
||||
torrent_handle
|
||||
|
|
|
@ -176,6 +176,7 @@ nobase_include_HEADERS = \
|
|||
aux_/proxy_settings.hpp \
|
||||
aux_/session_interface.hpp \
|
||||
aux_/suggest_piece.hpp \
|
||||
aux_/storage_piece_set.hpp \
|
||||
aux_/time.hpp \
|
||||
aux_/file_progress.hpp \
|
||||
aux_/openssl.hpp \
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003-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_STORAGE_PIECE_SET_HPP_INCLUDE
|
||||
#define TORRENT_STORAGE_PIECE_SET_HPP_INCLUDE
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include "libtorrent/export.hpp"
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
struct cached_piece_entry;
|
||||
|
||||
namespace aux {
|
||||
|
||||
// this class keeps track of which pieces, belonging to
|
||||
// a specific storage, are in the cache right now. It's
|
||||
// used for quickly being able to evict all pieces for a
|
||||
// specific torrent
|
||||
struct TORRENT_EXPORT storage_piece_set
|
||||
{
|
||||
void add_piece(cached_piece_entry* p);
|
||||
void remove_piece(cached_piece_entry* p);
|
||||
bool has_piece(cached_piece_entry const* p) const;
|
||||
int num_pieces() const { return int(m_cached_pieces.size()); }
|
||||
std::unordered_set<cached_piece_entry*> const& cached_pieces() const
|
||||
{ return m_cached_pieces; }
|
||||
private:
|
||||
// these are cached pieces belonging to this storage
|
||||
std::unordered_set<cached_piece_entry*> m_cached_pieces;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
|
@ -38,24 +38,16 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <unordered_set>
|
||||
#include <memory>
|
||||
|
||||
#include "libtorrent/aux_/disk_job_fence.hpp"
|
||||
#include "libtorrent/piece_picker.hpp"
|
||||
#include "libtorrent/peer_request.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/disk_buffer_holder.hpp"
|
||||
#include "libtorrent/aux_/storage_piece_set.hpp"
|
||||
#include "libtorrent/storage_defs.hpp"
|
||||
#include "libtorrent/allocator.hpp"
|
||||
#include "libtorrent/file_pool.hpp" // pool_file_status
|
||||
#include "libtorrent/part_file.hpp"
|
||||
#include "libtorrent/stat_cache.hpp"
|
||||
#include "libtorrent/bdecode.hpp"
|
||||
#include "libtorrent/bitfield.hpp"
|
||||
#include "libtorrent/performance_counters.hpp"
|
||||
#include "libtorrent/span.hpp"
|
||||
#include "libtorrent/tailqueue.hpp"
|
||||
#include "libtorrent/aux_/vector.hpp"
|
||||
|
||||
// OVERVIEW
|
||||
|
@ -139,34 +131,13 @@ namespace libtorrent
|
|||
{
|
||||
class session;
|
||||
struct file_pool;
|
||||
struct disk_io_job;
|
||||
struct disk_buffer_pool;
|
||||
struct cache_status;
|
||||
namespace aux { struct session_settings; }
|
||||
struct cached_piece_entry;
|
||||
struct add_torrent_params;
|
||||
|
||||
TORRENT_EXTRA_EXPORT void clear_bufs(span<iovec_t const> bufs);
|
||||
|
||||
struct disk_io_thread;
|
||||
|
||||
// this class keeps track of which pieces, belonging to
|
||||
// a specific storage, are in the cache right now. It's
|
||||
// used for quickly being able to evict all pieces for a
|
||||
// specific torrent
|
||||
struct TORRENT_EXPORT storage_piece_set
|
||||
{
|
||||
void add_piece(cached_piece_entry* p);
|
||||
void remove_piece(cached_piece_entry* p);
|
||||
bool has_piece(cached_piece_entry const* p) const;
|
||||
int num_pieces() const { return int(m_cached_pieces.size()); }
|
||||
std::unordered_set<cached_piece_entry*> const& cached_pieces() const
|
||||
{ return m_cached_pieces; }
|
||||
private:
|
||||
// these are cached pieces belonging to this storage
|
||||
std::unordered_set<cached_piece_entry*> m_cached_pieces;
|
||||
};
|
||||
|
||||
// The storage interface is a pure virtual class that can be implemented to
|
||||
// customize how and where data for a torrent is stored. The default storage
|
||||
// implementation uses regular files in the filesystem, mapping the files in
|
||||
|
@ -195,7 +166,7 @@ namespace libtorrent
|
|||
struct TORRENT_EXPORT storage_interface
|
||||
: public std::enable_shared_from_this<storage_interface>
|
||||
, public aux::disk_job_fence
|
||||
, public storage_piece_set
|
||||
, public aux::storage_piece_set
|
||||
, boost::noncopyable
|
||||
{
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ libtorrent_rasterbar_la_SOURCES = \
|
|||
stat.cpp \
|
||||
stat_cache.cpp \
|
||||
storage.cpp \
|
||||
storage_piece_set.cpp \
|
||||
storage_utils.cpp \
|
||||
session_stats.cpp \
|
||||
string_util.cpp \
|
||||
|
|
|
@ -847,30 +847,4 @@ namespace libtorrent
|
|||
return new zero_storage;
|
||||
}
|
||||
|
||||
void storage_piece_set::add_piece(cached_piece_entry* p)
|
||||
{
|
||||
TORRENT_ASSERT(p->in_storage == false);
|
||||
TORRENT_ASSERT(p->storage.get() == this);
|
||||
TORRENT_ASSERT(m_cached_pieces.count(p) == 0);
|
||||
m_cached_pieces.insert(p);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
p->in_storage = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool storage_piece_set::has_piece(cached_piece_entry const* p) const
|
||||
{
|
||||
return m_cached_pieces.count(const_cast<cached_piece_entry*>(p)) > 0;
|
||||
}
|
||||
|
||||
void storage_piece_set::remove_piece(cached_piece_entry* p)
|
||||
{
|
||||
TORRENT_ASSERT(p->in_storage == true);
|
||||
TORRENT_ASSERT(m_cached_pieces.count(p) == 1);
|
||||
m_cached_pieces.erase(p);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
p->in_storage = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace libtorrent
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003-2016, Arvid Norberg, Daniel Wallin
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#include "libtorrent/aux_/storage_piece_set.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/block_cache.hpp"
|
||||
#include "libtorrent/storage.hpp" // for storage_interface
|
||||
|
||||
namespace libtorrent { namespace aux
|
||||
{
|
||||
void storage_piece_set::add_piece(cached_piece_entry* p)
|
||||
{
|
||||
TORRENT_ASSERT(p->in_storage == false);
|
||||
TORRENT_ASSERT(p->storage.get() == this);
|
||||
TORRENT_ASSERT(m_cached_pieces.count(p) == 0);
|
||||
m_cached_pieces.insert(p);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
p->in_storage = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool storage_piece_set::has_piece(cached_piece_entry const* p) const
|
||||
{
|
||||
return m_cached_pieces.count(const_cast<cached_piece_entry*>(p)) > 0;
|
||||
}
|
||||
|
||||
void storage_piece_set::remove_piece(cached_piece_entry* p)
|
||||
{
|
||||
TORRENT_ASSERT(p->in_storage == true);
|
||||
TORRENT_ASSERT(m_cached_pieces.count(p) == 1);
|
||||
m_cached_pieces.erase(p);
|
||||
#if TORRENT_USE_ASSERTS
|
||||
p->in_storage = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
|
@ -1,5 +1,38 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003-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.
|
||||
|
||||
*/
|
||||
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/disk_io_job.hpp"
|
||||
#include "libtorrent/performance_counters.hpp"
|
||||
#include "test.hpp"
|
||||
|
||||
#include <atomic>
|
||||
|
|
Loading…
Reference in New Issue