xref: /haiku/src/tests/add-ons/kernel/file_systems/shared/consistency_check/AdaptiveBuffering.h (revision b8a45b3a2df2379b4301bf3bd5949b9a105be4ba)
1 /*
2  * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef ADAPTIVE_BUFFERING_H
6 #define ADAPTIVE_BUFFERING_H
7 
8 
9 #include <OS.h>
10 
11 
12 class AdaptiveBuffering {
13 public:
14 							AdaptiveBuffering(size_t initialBufferSize,
15 								size_t maxBufferSize, uint32 count);
16 	virtual					~AdaptiveBuffering();
17 
18 	virtual status_t		Init();
19 
20 	virtual status_t		Read(uint8* buffer, size_t* _length);
21 	virtual status_t		Write(uint8* buffer, size_t length);
22 
23 			status_t		Run();
24 
25 private:
26 			void			_QuitWriter();
27 			status_t		_Writer();
28 	static	status_t		_Writer(void* self);
29 
30 			thread_id		fWriterThread;
31 			uint8**			fBuffers;
32 			size_t*			fReadBytes;
33 			uint32			fBufferCount;
34 			uint32			fReadIndex;
35 			uint32			fWriteIndex;
36 			uint32			fReadCount;
37 			uint32			fWriteCount;
38 			size_t			fMaxBufferSize;
39 			size_t			fCurrentBufferSize;
40 			sem_id			fReadSem;
41 			sem_id			fWriteSem;
42 			sem_id			fFinishedSem;
43 			status_t		fWriteStatus;
44 			uint32			fWriteTime;
45 			bool			fFinished;
46 			bool			fQuit;
47 };
48 
49 #endif	// ADAPTIVE_BUFFERING_H
50