/******************************************************************************* Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . device.h Block device. *******************************************************************************/ #ifndef DEVICE_H #define DEVICE_H class Block; static const size_t DEVICE_HASH_LENGTH = 1 << 16; class Device { public: Device(int fd, const char* path, uint32_t block_size, bool write); ~Device(); public: pthread_t sync_thread; pthread_cond_t sync_thread_cond; pthread_cond_t sync_thread_idle_cond; pthread_mutex_t sync_thread_lock; Block* mru_block; Block* lru_block; Block* dirty_block; Block* hash_blocks[DEVICE_HASH_LENGTH]; off_t device_size; const char* path; uint32_t block_size; int fd; bool write; bool has_sync_thread; bool sync_thread_should_exit; bool sync_in_transit; size_t block_count; size_t block_limit; public: void SpawnSyncThread(); Block* AllocateBlock(); Block* GetBlock(uint32_t block_id); Block* GetBlockZeroed(uint32_t block_id); Block* GetCachedBlock(uint32_t block_id); void Sync(); void SyncThread(); }; #endif