xref: /haiku/src/add-ons/kernel/file_systems/userlandfs/server/RequestThread.h (revision b028e77473189065f2baefc6f5e10d451cf591e2)
1 // RequestThread.h
2 
3 #ifndef USERLAND_FS_REQUEST_THREAD_H
4 #define USERLAND_FS_REQUEST_THREAD_H
5 
6 #include "RequestPort.h"
7 
8 namespace UserlandFS {
9 
10 class FileSystem;
11 class RequestThread;
12 class Volume;
13 
14 // RequestThreadContext
15 class RequestThreadContext {
16 public:
17 								RequestThreadContext(Volume* volume);
18 								~RequestThreadContext();
19 
20 			RequestThread*		GetThread() const;
21 			Volume*				GetVolume() const;
22 
23 private:
24 			RequestThreadContext*	fPreviousContext;
25 			RequestThread*		fThread;
26 			Volume*				fVolume;
27 };
28 
29 // RequestThread
30 class RequestThread {
31 public:
32 								RequestThread();
33 								~RequestThread();
34 
35 			status_t			Init(FileSystem* fileSystem);
36 			void				Run();
37 			void				PrepareTermination();
38 			void				Terminate();
39 
40 			const Port::Info*	GetPortInfo() const;
41 			FileSystem*			GetFileSystem() const;
42 			RequestPort*		GetPort() const;
43 			RequestThreadContext*	GetContext() const;
44 
45 	static	RequestThread*		GetCurrentThread();
46 
47 private:
48 			void				SetContext(RequestThreadContext* context);
49 
50 private:
51 	static	int32				_ThreadEntry(void* data);
52 			int32				_ThreadLoop();
53 
54 private:
55 			friend class RequestThreadContext;
56 
57 			thread_id			fThread;
58 			FileSystem*			fFileSystem;
59 			RequestPort*		fPort;
60 			RequestThreadContext* fContext;
61 			bool				fTerminating;
62 };
63 
64 }	// namespace UserlandFS
65 
66 using UserlandFS::RequestThreadContext;
67 using UserlandFS::RequestThread;
68 
69 #endif	// USERLAND_FS_REQUEST_THREAD_H
70