use unsigned integer for file and storage flags (#1895)

use unsigned integer for file and storage flags
This commit is contained in:
Arvid Norberg 2017-04-09 01:28:46 -04:00 committed by GitHub
parent 13b16a63a3
commit c35718d322
9 changed files with 37 additions and 43 deletions

View File

@ -518,14 +518,6 @@ void bind_torrent_handle()
.value("locked", file_open_mode::locked)
;
#ifndef TORRENT_NO_DEPRECATE
class_<open_file_state>("pool_file_status")
.add_property("file_index", make_getter((&open_file_state::file_index), by_value()))
.def_readonly("last_use", &open_file_state::last_use)
.def_readonly("open_mode", &open_file_state::open_mode)
;
#endif
enum_<torrent_handle::file_progress_flags_t>("file_progress_flags")
.value("piece_granularity", torrent_handle::piece_granularity)
;

View File

@ -119,7 +119,7 @@ namespace libtorrent
struct TORRENT_EXTRA_EXPORT disk_interface
{
enum flags_t
enum flags_t : std::uint8_t
{
sequential_access = 0x1,
@ -137,7 +137,7 @@ namespace libtorrent
virtual storage_interface* get_torrent(storage_index_t) = 0;
virtual void async_read(storage_index_t storage, peer_request const& r
, std::function<void(disk_buffer_holder block, int flags, storage_error const& se)> handler
, std::function<void(disk_buffer_holder block, std::uint32_t flags, storage_error const& se)> handler
, void* requester, std::uint8_t flags = 0) = 0;
virtual bool async_write(storage_index_t storage, peer_request const& r
, char const* buf, std::shared_ptr<disk_observer> o

View File

@ -147,7 +147,7 @@ namespace libtorrent
// this is called when operation completes
using read_handler = std::function<void(disk_buffer_holder block, int flags, storage_error const& se)>;
using read_handler = std::function<void(disk_buffer_holder block, std::uint32_t flags, storage_error const& se)>;
using write_handler = std::function<void(storage_error const&)>;
using hash_handler = std::function<void(piece_index_t, sha1_hash const&, storage_error const&)>;
using move_handler = std::function<void(status_t, std::string const&, storage_error const&)>;

View File

@ -299,7 +299,7 @@ namespace libtorrent
void async_read(storage_index_t storage, peer_request const& r
, std::function<void(disk_buffer_holder block
, int flags, storage_error const& se)> handler, void* requester, std::uint8_t flags = 0) override;
, std::uint32_t flags, storage_error const& se)> handler, void* requester, std::uint8_t flags = 0) override;
bool async_write(storage_index_t storage, peer_request const& r
, char const* buf, std::shared_ptr<disk_observer> o
, std::function<void(storage_error const&)> handler
@ -462,7 +462,7 @@ namespace libtorrent
void kick_hasher(cached_piece_entry* pe, std::unique_lock<std::mutex>& l);
// flags to pass in to flush_cache()
enum flush_flags_t
enum flush_flags_t : std::uint32_t
{
// only flush read cache (this is cheap)
flush_read_cache = 1,
@ -475,9 +475,9 @@ namespace libtorrent
// used for asserts and only applies for fence jobs
flush_expect_clear = 8
};
void flush_cache(storage_interface* storage, int flags, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l);
void flush_cache(storage_interface* storage, std::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);
void flush_piece(cached_piece_entry* pe, std::uint32_t 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, std::unique_lock<std::mutex>& l);

View File

@ -208,9 +208,9 @@ namespace libtorrent
// error. If there's an error, the ``storage_error`` must be filled out
// to represent the error that occurred.
virtual int readv(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) = 0;
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) = 0;
virtual int writev(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) = 0;
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) = 0;
// This function is called when first checking (or re-checking) the
// storage for a torrent. It should return true if any of the files that
@ -398,9 +398,9 @@ namespace libtorrent
virtual bool tick() override;
int readv(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) override;
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) override;
int writev(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) override;
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) override;
// if the files in this storage are mapped, returns the mapped
// file_storage, otherwise returns the original file_storage object.

View File

@ -116,10 +116,10 @@ namespace libtorrent
#endif // DEBUG_DISK_THREAD
int file_flags_for_job(disk_io_job* j
std::uint32_t file_flags_for_job(disk_io_job* j
, bool const coalesce_buffers)
{
int ret = 0;
std::uint32_t ret = 0;
if (!(j->flags & disk_interface::sequential_access)) ret |= file::random_access;
if (coalesce_buffers) ret |= file::coalesce_buffers;
return ret;
@ -658,7 +658,7 @@ namespace libtorrent
DLOG("]\n");
#endif
int const file_flags = m_settings.get_bool(settings_pack::coalesce_writes)
std::uint32_t const file_flags = m_settings.get_bool(settings_pack::coalesce_writes)
? file::coalesce_buffers : static_cast<file::open_mode_t>(0);
// issue the actual write operation
@ -820,7 +820,7 @@ namespace libtorrent
}
}
void disk_io_thread::flush_piece(cached_piece_entry* pe, int flags
void disk_io_thread::flush_piece(cached_piece_entry* pe, std::uint32_t const flags
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
{
TORRENT_ASSERT(l.owns_lock());
@ -853,7 +853,7 @@ namespace libtorrent
}
}
void disk_io_thread::flush_cache(storage_interface* storage, int const flags
void disk_io_thread::flush_cache(storage_interface* storage, std::uint32_t const flags
, jobqueue_t& completed_jobs, std::unique_lock<std::mutex>& l)
{
if (storage)
@ -1224,7 +1224,7 @@ namespace libtorrent
time_point const start_time = clock_type::now();
int const file_flags = file_flags_for_job(j
std::uint32_t const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_reads));
iovec_t b = {j->buffer.disk_block, std::size_t(j->d.io.buffer_size)};
@ -1300,7 +1300,7 @@ namespace libtorrent
// 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
std::uint32_t const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_reads));
time_point const start_time = clock_type::now();
@ -1459,7 +1459,7 @@ namespace libtorrent
time_point const start_time = clock_type::now();
iovec_t const b = {j->buffer.disk_block, std::size_t(j->d.io.buffer_size)};
int const file_flags = file_flags_for_job(j
std::uint32_t const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_writes));
m_stats_counters.inc_stats_counter(counters::num_writing_threads, 1);
@ -1551,8 +1551,8 @@ namespace libtorrent
}
void disk_io_thread::async_read(storage_index_t storage, peer_request const& r
, std::function<void(disk_buffer_holder block, int flags, storage_error const& se)> handler
, void* requester, std::uint8_t const flags)
, std::function<void(disk_buffer_holder block, std::uint32_t const flags
, storage_error const& se)> handler, void* requester, std::uint8_t const flags)
{
TORRENT_ASSERT(r.length <= m_disk_cache.block_size());
TORRENT_ASSERT(r.length <= 16 * 1024);
@ -2147,7 +2147,7 @@ namespace libtorrent
int const piece_size = j->storage->files().piece_size(j->piece);
int const block_size = m_disk_cache.block_size();
int const blocks_in_piece = (piece_size + block_size - 1) / block_size;
int const file_flags = file_flags_for_job(j
std::uint32_t const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_reads));
iovec_t iov;
@ -2192,7 +2192,7 @@ namespace libtorrent
status_t disk_io_thread::do_hash(disk_io_job* j, jobqueue_t& /* completed_jobs */ )
{
int const piece_size = j->storage->files().piece_size(j->piece);
int const file_flags = file_flags_for_job(j
std::uint32_t const file_flags = file_flags_for_job(j
, m_settings.get_bool(settings_pack::coalesce_reads));
std::unique_lock<std::mutex> l(m_cache_mutex);

View File

@ -614,9 +614,10 @@ namespace libtorrent
}
int default_storage::readv(span<iovec_t const> bufs
, piece_index_t const piece, int offset, int flags, storage_error& ec)
, piece_index_t const piece, int const offset
, std::uint32_t const flags, storage_error& ec)
{
read_fileop op(*this, static_cast<std::uint32_t>(flags));
read_fileop op(*this, flags);
#ifdef TORRENT_SIMULATE_SLOW_READ
std::this_thread::sleep_for(seconds(1));
@ -625,9 +626,10 @@ namespace libtorrent
}
int default_storage::writev(span<iovec_t const> bufs
, piece_index_t const piece, int offset, int flags, storage_error& ec)
, piece_index_t const piece, int const offset
, std::uint32_t const flags, storage_error& ec)
{
write_fileop op(*this, static_cast<std::uint32_t>(flags));
write_fileop op(*this, flags);
return readwritev(files(), bufs, piece, offset, op, ec);
}
@ -770,12 +772,12 @@ namespace libtorrent
status_t move_storage(std::string const&, int, storage_error&) override { return status_t::no_error; }
int readv(span<iovec_t const> bufs
, piece_index_t, int, int, storage_error&) override
, piece_index_t, int, std::uint32_t, storage_error&) override
{
return bufs_size(bufs);
}
int writev(span<iovec_t const> bufs
, piece_index_t, int, int, storage_error&) override
, piece_index_t, int, std::uint32_t, storage_error&) override
{
return bufs_size(bufs);
}
@ -803,7 +805,7 @@ namespace libtorrent
void initialize(storage_error&) override {}
int readv(span<iovec_t const> bufs
, piece_index_t, int, int, storage_error&) override
, piece_index_t, int, std::uint32_t, storage_error&) override
{
int ret = 0;
for (auto const& b : bufs)
@ -814,7 +816,7 @@ namespace libtorrent
return 0;
}
int writev(span<iovec_t const> bufs
, piece_index_t, int, int, storage_error&) override
, piece_index_t, int, std::uint32_t, storage_error&) override
{
int ret = 0;
for (auto const& b : bufs)

View File

@ -50,12 +50,12 @@ struct test_storage_impl : storage_interface
void initialize(storage_error& ec) override {}
int readv(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) override
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) override
{
return bufs_size(bufs);
}
int writev(span<iovec_t const> bufs
, piece_index_t piece, int offset, int flags, storage_error& ec) override
, piece_index_t piece, int offset, std::uint32_t flags, storage_error& ec) override
{
return bufs_size(bufs);
}

View File

@ -71,7 +71,7 @@ bool on_alert(alert const* a)
// simulate a full disk
struct test_storage : default_storage
{
explicit test_storage(storage_params const& params, file_pool& pool)
test_storage(storage_params const& params, file_pool& pool)
: default_storage(params, pool)
, m_written(0)
, m_limit(16 * 1024 * 2)
@ -90,7 +90,7 @@ struct test_storage : default_storage
span<iovec_t const> bufs
, piece_index_t piece_index
, int offset
, int flags
, std::uint32_t const flags
, storage_error& se) override
{
std::unique_lock<std::mutex> l(m_mutex);