File indexing completed on 2024-04-28 15:39:58
0001 /* SPDX-FileCopyrightText: 2018 Robert Krawitz <rlk@alum.mit.edu> 0002 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef IMAGESCOUT_H 0007 #define IMAGESCOUT_H 0008 0009 #include <kpabase/FileName.h> 0010 0011 #include <QAtomicInt> 0012 #include <QList> 0013 #include <QMutex> 0014 #include <QQueue> 0015 0016 namespace DB 0017 { 0018 0019 typedef QQueue<DB::FileName> ImageScoutQueue; 0020 typedef void (*PreloadFunc)(const DB::FileName &); 0021 class ImageScoutThread; 0022 0023 /** 0024 * Scout thread for image loading: preload images from disk to have them in 0025 * RAM to mask I/O latency. 0026 */ 0027 class ImageScout 0028 { 0029 public: 0030 // count is an atomic variable containing the number of images 0031 // that have been loaded thus far. Used to prevent the scout from 0032 // getting too far ahead, if it's able to run faster than the 0033 // loader. Which usually it can't; with hard disks on any halfway 0034 // decent system, the loader can run faster than the disk. 0035 ImageScout(ImageScoutQueue &, QAtomicInt &count, int threads = 1); 0036 ~ImageScout(); 0037 // Specify scout buffer size. May not be called after starting the scout. 0038 void setBufSize(int); 0039 int getBufSize(); 0040 // Specify how far we're allowed to run ahead of the loader, in images. 0041 // May not be called after starting the scout. 0042 void setMaxSeekAhead(int); 0043 int getMaxSeekAhead(); 0044 // Specify how many bytes we read before moving on. 0045 // May not be called after starting the scout. 0046 void setReadLimit(int); 0047 int getReadLimit(); 0048 // Specify an alternate function to preload the file. 0049 // This function may perform useful work. Note that this is not 0050 // guaranteed to be called, so anything using this must be 0051 // prepared to do the work later. 0052 void setPreloadFunc(PreloadFunc); 0053 PreloadFunc getPreloadFunc(); 0054 // Start the scout running 0055 void start(); 0056 0057 private: 0058 QMutex m_mutex; 0059 QList<ImageScoutThread *> m_scoutList; 0060 QAtomicInt m_preloadedCount; 0061 QAtomicInt m_skippedCount; 0062 bool m_isStarted; 0063 int m_scoutBufSize; 0064 int m_maxSeekAhead; 0065 int m_readLimit; 0066 PreloadFunc m_preloadFunc; 0067 }; 0068 } 0069 0070 #endif /* IMAGESCOUT_H */ 0071 0072 // vi:expandtab:tabstop=4 shiftwidth=4: