fully support unbuffered I/O
This commit is contained in:
@@ -225,80 +225,11 @@ namespace libtorrent
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
page_aligned_allocator::free(buf);
|
||||
#else
|
||||
m_pool.ordered_free(buf);
|
||||
m_pool.free(buf);
|
||||
#endif
|
||||
--m_in_use;
|
||||
}
|
||||
|
||||
char* disk_buffer_pool::allocate_buffers(int num_blocks, char const* category)
|
||||
{
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
char* ret = page_aligned_allocator::malloc(m_block_size * num_blocks);
|
||||
#else
|
||||
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
|
||||
m_pool.set_next_size(m_settings.cache_buffer_chunk_size);
|
||||
#endif
|
||||
m_in_use += num_blocks;
|
||||
#if TORRENT_USE_MLOCK
|
||||
if (m_settings.lock_disk_cache)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
VirtualLock(ret, m_block_size * num_blocks);
|
||||
#else
|
||||
mlock(ret, m_block_size * num_blocks);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
||||
m_allocations += num_blocks;
|
||||
#endif
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
m_categories[category] += num_blocks;
|
||||
m_buf_to_category[ret] = category;
|
||||
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
|
||||
#endif
|
||||
TORRENT_ASSERT(ret == 0 || is_disk_buffer(ret, l));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void disk_buffer_pool::free_buffers(char* buf, int num_blocks)
|
||||
{
|
||||
TORRENT_ASSERT(buf);
|
||||
TORRENT_ASSERT(num_blocks >= 1);
|
||||
mutex::scoped_lock l(m_pool_mutex);
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
TORRENT_ASSERT(is_disk_buffer(buf, l));
|
||||
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
||||
m_allocations -= num_blocks;
|
||||
#endif
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
TORRENT_ASSERT(m_categories.find(m_buf_to_category[buf])
|
||||
!= m_categories.end());
|
||||
std::string const& category = m_buf_to_category[buf];
|
||||
m_categories[category] -= num_blocks;
|
||||
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
|
||||
m_buf_to_category.erase(buf);
|
||||
#endif
|
||||
#if TORRENT_USE_MLOCK
|
||||
if (m_settings.lock_disk_cache)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
VirtualUnlock(buf, m_block_size * num_blocks);
|
||||
#else
|
||||
munlock(buf, m_block_size * num_blocks);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
page_aligned_allocator::free(buf);
|
||||
#else
|
||||
m_pool.ordered_free(buf, num_blocks);
|
||||
#endif
|
||||
m_in_use -= num_blocks;
|
||||
}
|
||||
|
||||
void disk_buffer_pool::release_memory()
|
||||
{
|
||||
TORRENT_ASSERT(m_magic == 0x1337);
|
||||
|
Reference in New Issue
Block a user