comparison base/MatrixFileCache.h @ 95:040a151d0897

* Add file reader thread, and make the matrix file code use it to preload fft cache data without glitching
author Chris Cannam
date Thu, 04 May 2006 13:59:57 +0000
parents 27d726916ab3
children
comparison
equal deleted inserted replaced
94:5b8392e80ed6 95:040a151d0897
19 #include <sys/types.h> 19 #include <sys/types.h>
20 #include <QString> 20 #include <QString>
21 #include <QMutex> 21 #include <QMutex>
22 #include <map> 22 #include <map>
23 23
24 // This class is _not_ thread safe. Each instance must only be used 24 #include "FileReadThread.h"
25 // within a single thread. You may however have as many instances as
26 // you like referring to the same file in separate threads.
27 25
28 class MatrixFileCache 26 class MatrixFileCache : public QObject
29 { 27 {
28 Q_OBJECT
29
30 public: 30 public:
31 enum Mode { ReadOnly, ReadWrite }; 31 enum Mode { ReadOnly, ReadWrite };
32 32
33 MatrixFileCache(QString fileBase, Mode mode); 33 MatrixFileCache(QString fileBase, Mode mode);
34 virtual ~MatrixFileCache(); 34 virtual ~MatrixFileCache();
37 size_t getHeight() const; 37 size_t getHeight() const;
38 38
39 void resize(size_t width, size_t height); 39 void resize(size_t width, size_t height);
40 void reset(); 40 void reset();
41 41
42 void setRegionOfInterest(size_t x, size_t width); 42 float getValueAt(size_t x, size_t y);
43 void clearRegionOfInterest(); 43 void getColumnAt(size_t x, float *values);
44
45 float getValueAt(size_t x, size_t y) const;
46 void getColumnAt(size_t x, float *values) const;
47 44
48 void setValueAt(size_t x, size_t y, float value); 45 void setValueAt(size_t x, size_t y, float value);
49 void setColumnAt(size_t x, float *values); 46 void setColumnAt(size_t x, float *values);
50 47
48 protected slots:
49 void requestCancelled(int token);
50
51 protected: 51 protected:
52 int m_fd; 52 int m_fd;
53 Mode m_mode; 53 Mode m_mode;
54 size_t m_width; 54 size_t m_width;
55 size_t m_height; 55 size_t m_height;
56 size_t m_headerSize; 56 size_t m_headerSize;
57 size_t m_autoRegionWidth;
58 QString m_fileName; 57 QString m_fileName;
58 size_t m_defaultCacheWidth;
59 size_t m_prevX;
59 60
60 mutable off_t m_off; 61 struct Cache {
61 mutable size_t m_rx; 62 size_t x;
62 mutable size_t m_rw; 63 size_t width;
63 mutable bool m_userRegion; 64 float *data;
64 mutable float *m_region; 65 };
65 float *getRegionPtr(size_t x, size_t y) const;
66 66
67 bool autoSetRegion(size_t x) const; 67 Cache m_cache;
68 bool setRegion(size_t x, size_t width, bool user) const;
69 68
70 bool seekTo(size_t x, size_t y) const; 69 bool getValuesFromCache(size_t x, size_t ystart, size_t ycount,
70 float *values);
71
72 void primeCache(size_t x, bool left);
73
74 bool seekTo(size_t x, size_t y);
75
76 FileReadThread m_readThread;
77 int m_requestToken;
78 size_t m_requestingX;
79 size_t m_requestingWidth;
71 80
72 static std::map<QString, int> m_refcount; 81 static std::map<QString, int> m_refcount;
73 static QMutex m_refcountMutex; 82 static QMutex m_refcountMutex;
83 QMutex m_fdMutex;
84 QMutex m_cacheMutex;
74 }; 85 };
75 86
76 #endif 87 #endif
77 88