1 /* 2 * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef USERLAND_FS_REQUEST_THREAD_H 6 #define USERLAND_FS_REQUEST_THREAD_H 7 8 #include "RequestPort.h" 9 10 namespace UserlandFS { 11 12 class FileSystem; 13 class RequestThread; 14 class Volume; 15 16 #define REQUEST_THREAD_CONTEXT_FS_DATA_SIZE 256 17 18 // RequestThreadContext 19 class RequestThreadContext { 20 public: 21 RequestThreadContext(Volume* volume, 22 KernelRequest* request); 23 ~RequestThreadContext(); 24 25 RequestThread* GetThread() const; 26 Volume* GetVolume() const; 27 KernelRequest* GetRequest() const { return fRequest; } 28 void* GetFSData() { return fFSData; } 29 30 private: 31 RequestThreadContext* fPreviousContext; 32 RequestThread* fThread; 33 Volume* fVolume; 34 KernelRequest* fRequest; 35 uint8 fFSData[REQUEST_THREAD_CONTEXT_FS_DATA_SIZE]; 36 }; 37 38 // RequestThread 39 class RequestThread { 40 public: 41 RequestThread(); 42 ~RequestThread(); 43 44 status_t Init(FileSystem* fileSystem); 45 void Run(); 46 void PrepareTermination(); 47 void Terminate(); 48 49 const Port::Info* GetPortInfo() const; 50 FileSystem* GetFileSystem() const; 51 RequestPort* GetPort() const; 52 RequestThreadContext* GetContext() const; 53 54 static RequestThread* GetCurrentThread(); 55 56 private: 57 void SetContext(RequestThreadContext* context); 58 59 private: 60 static int32 _ThreadEntry(void* data); 61 int32 _ThreadLoop(); 62 63 private: 64 friend class RequestThreadContext; 65 66 thread_id fThread; 67 FileSystem* fFileSystem; 68 RequestPort* fPort; 69 RequestThreadContext* fContext; 70 bool fTerminating; 71 }; 72 73 } // namespace UserlandFS 74 75 using UserlandFS::RequestThreadContext; 76 using UserlandFS::RequestThread; 77 78 #endif // USERLAND_FS_REQUEST_THREAD_H 79