File: writethread.h

package info (click to toggle)
aoflagger 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,476 kB
  • sloc: cpp: 51,868; python: 152; sh: 25; makefile: 17
file content (47 lines) | stat: -rw-r--r-- 1,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef AOLUA_WRITE_THREAD_H
#define AOLUA_WRITE_THREAD_H

#include "../imagesets/imageset.h"

#include <condition_variable>
#include <stack>
#include <thread>
#include <vector>

class WriteThread
{
public:
	WriteThread(rfiStrategy::ImageSet& imageSet, size_t calcThreadCount, std::mutex* ioMutex);
	~WriteThread();
	
	void SaveFlags(const TimeFrequencyData& data, rfiStrategy::ImageSetIndex& imageSetIndex);
	
private:
	struct FlushThread
	{
		WriteThread* _parent;
		void operator()(std::unique_ptr<rfiStrategy::ImageSet> imageSet);
	};

	struct BufferItem {
		BufferItem(const std::vector<Mask2DCPtr> &masks, const rfiStrategy::ImageSetIndex& index)
			: _masks(masks), _index(index)
		{ }
		std::vector<Mask2DCPtr> _masks;
		rfiStrategy::ImageSetIndex _index;
	};
	
	void pushInWriteBuffer(const BufferItem &newItem);
	
	std::mutex _writeMutex, *_ioMutex;
	std::condition_variable _writeBufferChange;
	std::unique_ptr<std::thread> _flusher;
	bool _isWriteFinishing;

	size_t _maxWriteBufferItems;
	size_t _minWriteBufferItemsForWriting;

	std::stack<BufferItem> _writeBuffer;
};

#endif