diff options
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/file_allocator.h')
-rw-r--r-- | src/mongo/db/storage/mmap_v1/file_allocator.h | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/src/mongo/db/storage/mmap_v1/file_allocator.h b/src/mongo/db/storage/mmap_v1/file_allocator.h index d3f9b6cceda..e3e4ad55881 100644 --- a/src/mongo/db/storage/mmap_v1/file_allocator.h +++ b/src/mongo/db/storage/mmap_v1/file_allocator.h @@ -37,73 +37,71 @@ namespace mongo { +/* + * Handles allocation of contiguous files on disk. Allocation may be + * requested asynchronously or synchronously. + * singleton + */ +class FileAllocator { + MONGO_DISALLOW_COPYING(FileAllocator); /* - * Handles allocation of contiguous files on disk. Allocation may be - * requested asynchronously or synchronously. - * singleton + * The public functions may not be called concurrently. The allocation + * functions may be called multiple times per file, but only the first + * size specified per file will be used. + */ +public: + void start(); + + /** + * May be called if file exists. If file exists, or its allocation has + * been requested, size is updated to match existing file size. */ - class FileAllocator { - MONGO_DISALLOW_COPYING(FileAllocator); - /* - * The public functions may not be called concurrently. The allocation - * functions may be called multiple times per file, but only the first - * size specified per file will be used. - */ - public: - void start(); - - /** - * May be called if file exists. If file exists, or its allocation has - * been requested, size is updated to match existing file size. - */ - void requestAllocation( const std::string &name, long &size ); + void requestAllocation(const std::string& name, long& size); - /** - * Returns when file has been allocated. If file exists, size is - * updated to match existing file size. - */ - void allocateAsap( const std::string &name, unsigned long long &size ); - - void waitUntilFinished() const; + /** + * Returns when file has been allocated. If file exists, size is + * updated to match existing file size. + */ + void allocateAsap(const std::string& name, unsigned long long& size); - static void ensureLength(int fd, long size); + void waitUntilFinished() const; - /** @return the singleton */ - static FileAllocator * get(); - - private: + static void ensureLength(int fd, long size); - FileAllocator(); + /** @return the singleton */ + static FileAllocator* get(); - void checkFailure(); +private: + FileAllocator(); - // caller must hold pendingMutex_ lock. Returns size if allocated or - // allocation requested, -1 otherwise. - long prevSize( const std::string &name ) const; + void checkFailure(); - // caller must hold pendingMutex_ lock. - bool inProgress( const std::string &name ) const; + // caller must hold pendingMutex_ lock. Returns size if allocated or + // allocation requested, -1 otherwise. + long prevSize(const std::string& name) const; - /** called from the worked thread */ - static void run( FileAllocator * fa ); + // caller must hold pendingMutex_ lock. + bool inProgress(const std::string& name) const; - // generate a unique name for temporary files - std::string makeTempFileName( boost::filesystem::path root ); + /** called from the worked thread */ + static void run(FileAllocator* fa); - mutable stdx::mutex _pendingMutex; - mutable stdx::condition_variable _pendingUpdated; + // generate a unique name for temporary files + std::string makeTempFileName(boost::filesystem::path root); - std::list< std::string > _pending; - mutable std::map< std::string, long > _pendingSize; + mutable stdx::mutex _pendingMutex; + mutable stdx::condition_variable _pendingUpdated; - // unique number for temporary files - static unsigned long long _uniqueNumber; + std::list<std::string> _pending; + mutable std::map<std::string, long> _pendingSize; - bool _failed; + // unique number for temporary files + static unsigned long long _uniqueNumber; - static FileAllocator* _instance; + bool _failed; - }; + static FileAllocator* _instance; +}; -} // namespace mongo +} // namespace mongo |