Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

596 lines
25 KiB

  1. //===== Copyright � 2009, Valve Corporation, All rights reserved. ======//
  2. // filesyste_newasync.h
  3. //
  4. // Purpose:
  5. //
  6. // $NoKeywords: $async file system
  7. //===========================================================================//
  8. #include <limits.h>
  9. #include "tier0/threadtools.h"
  10. #include "tier0/memalloc.h"
  11. #include "tier1/interface.h"
  12. #include "tier1/utlsymbol.h"
  13. #include "appframework/iappsystem.h"
  14. #include "tier1/checksum_crc.h"
  15. #include "filesystem/iasyncfilesystem.h"
  16. #ifndef FILESYSTEMASYNC_H
  17. #define FILESYSTEMASYNC_H
  18. #ifdef _WIN32
  19. #pragma once
  20. #endif
  21. #ifdef OSX
  22. #pragma GCC diagnostic ignored "-Wreturn-type" // control reaches end of non-void function, for unsupported assignment operators below
  23. #endif
  24. class CAsyncGroupRequest;
  25. struct CAsyncResultInfo_t
  26. {
  27. public:
  28. void* m_pAllocatedBuffer;
  29. int m_nBytesTransferred;
  30. FSAsyncStatus_t m_ErrorCode;
  31. CAsyncResultInfo_t() : m_pAllocatedBuffer(NULL), m_nBytesTransferred(0) {}
  32. };
  33. //-----------------------------------------------------------------------------
  34. // CAsyncRequestBase - Common items to all async filesystem requests
  35. //
  36. // Allows the async filesystem to have a standard way to deal with different
  37. // types of requests equally re: priority, callbacks, state, aborting, etc
  38. //
  39. //-----------------------------------------------------------------------------
  40. class CAsyncRequestBase
  41. {
  42. public:
  43. void* m_pOuter; // pointer to object containing this base
  44. // -------------------------------------------------------
  45. // Members to set by the user before submission
  46. CFunctor* m_pCallback; // Optional Callback object (we own this)
  47. CIOCompletionQueue* m_pResultQueue; // Message Queue object to send results to
  48. AsyncFileOperation_t m_Operation; // operation to perform
  49. int32 m_priority; // inter list priority, 0=lowest??
  50. // -------------------------------------------------------
  51. // Used internally by the filesystem to keep track of the request
  52. CAsyncRequestBase* m_pNext; // used to maintain the priority linked list
  53. CAsyncRequestBase* m_pPrev;
  54. // -------------------------------------------------------
  55. // Members which get set by the file system after submission
  56. AsyncRequestState_t m_RequestState; // State of this request (which stage it is n)
  57. AsyncRequestStatus_t m_RequestStatus; // Error/Success Status from the last operation attempted on this request
  58. bool m_bAbortRequest; // Flag indicating this request is to be aborted
  59. bool m_bProcessingCallback; // Flag indicating a callback is being processed
  60. bool m_bDontAutoRelease; // Flag indicating not to automatically release the request once the callback finishes
  61. // bool m_bIsAContainer
  62. CThreadEvent* m_pSyncThreadEvent; // Thread event to signal in synchronous mode...
  63. FSAsyncControl_t m_pOldAsyncControl; // old Async System control Handle
  64. FSAsyncStatus_t m_pOldAsyncStatus; // old Async System IO Status
  65. CAsyncGroupRequest* m_pGroup; // group this request belongs to
  66. public:
  67. CAsyncRequestBase(); // Default Constructor - We want NO implicit constructions
  68. ~CAsyncRequestBase(); // Destructor - not virtual anymore
  69. void SetOuter( void* pOuter ) { m_pOuter = pOuter; }
  70. void* GetOuter() { return m_pOuter; }
  71. IAsyncRequestBase* GetInterfaceBase();
  72. // functions to query operation
  73. AsyncFileOperation_t GetAsyncOperationType() { return m_Operation; }
  74. // Set completion options
  75. void AssignCallback( CFunctor* pCallback ); // Add a completion callback to this request
  76. void AssignResultQueue( CIOCompletionQueue* pMsgQueue ); // Send the results to this queue object
  77. void AssignCallbackAndQueue( CIOCompletionQueue* pMsgQueue, CFunctor* pCallback );
  78. // Completion processing functions
  79. void ProcessCallback( bool bRelease = true ); // Execute the optional callback functor
  80. void KeepRequestPostCallback() { m_bDontAutoRelease = true; } // User wants to keep request alive after the callback completes
  81. void DontKeepRequestPostCallback() { m_bDontAutoRelease = false; } // User doesn't want to keep request after the callback completes
  82. void Release(); // lets user manually release the async request (only valid when completed)
  83. void DeleteOuter(); // Used by async filesystem to delete the containing object (as well as the CAsyncRequestBase)
  84. // Priority Functions
  85. void SetPriority( int32 nPriority );
  86. int32 GetPriority() { return m_priority; }
  87. // Status & Results functions
  88. AsyncRequestState_t GetRequestState() { return m_RequestState; }
  89. AsyncRequestStatus_t GetRequestStatus() { return m_RequestStatus; }
  90. // --------------------------------------------------------------
  91. // Gateway to outer's Public Methods not included in the interface, used by Async FileSystem
  92. void AbortAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  93. void UpdateAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  94. AsyncRequestStatus_t ValidateSubmittedRequest( bool bPerformSync ); // Validates the derived object data at request submission
  95. bool ValidateRequestModification(); // core check to determine if modification is allowed at this time
  96. protected:
  97. // Helper functions for repeated operations
  98. void RefreshCallback( CFunctor* pCallback );
  99. private:
  100. explicit CAsyncRequestBase( const CAsyncRequestBase& rhs ); // copy constructor - NOT SUPPORTED
  101. CAsyncRequestBase& operator=( const CAsyncRequestBase& rhs ); // assignment operator - NOT SUPPORTED
  102. };
  103. //-----------------------------------------------------------------------------
  104. // CAsyncGroupRequest - Concrete implementation for a group of async requests
  105. //
  106. //
  107. //
  108. //-----------------------------------------------------------------------------
  109. class CAsyncGroupRequest : public IAsyncGroupRequest
  110. {
  111. public:
  112. CAsyncRequestBase m_Base; // Base request - we can't derive from due to multiple inheritance problems
  113. CUtlVector<IAsyncRequestBase*> m_RequestList; // List of requests to process
  114. CUtlVector<bool> m_ValidList; // List of requests which are valid
  115. CInterlockedInt m_nNumRequestsOutstanding;
  116. public:
  117. CAsyncGroupRequest(); // Default Constructor - We want NO implicit constructions
  118. virtual ~CAsyncGroupRequest(); // Destructor
  119. // ---------------------------------------------------------
  120. // methods from the IAsyncRequestBase Interface
  121. // ---------------------------------------------------------
  122. // functions to query operation
  123. virtual AsyncFileOperation_t GetAsyncOperationType() { return m_Base.GetAsyncOperationType(); }
  124. // Set completion options
  125. virtual void AssignCallback( CFunctor* pCallback ) { m_Base.AssignCallback( pCallback ); }
  126. virtual void AssignResultQueue( CIOCompletionQueue* pMsgQueue ) { m_Base.AssignResultQueue( pMsgQueue ); }
  127. virtual void AssignCallbackAndQueue( CIOCompletionQueue* pMsgQueue, CFunctor* pCallback ) { m_Base.AssignCallbackAndQueue( pMsgQueue, pCallback); }
  128. // Completion processing functions
  129. virtual void ProcessCallback( bool bRelease = true ) { m_Base.ProcessCallback( bRelease ); }
  130. virtual void KeepRequestPostCallback() { m_Base.KeepRequestPostCallback(); }
  131. virtual void DontKeepRequestPostCallback() { m_Base.DontKeepRequestPostCallback(); }
  132. virtual void Release() { m_Base.Release(); }
  133. // Priority Functions
  134. virtual void SetPriority( int32 nPriority ) { m_Base.SetPriority( nPriority ); }
  135. virtual int32 GetPriority() { return m_Base.GetPriority(); }
  136. // Status & Results functions
  137. virtual AsyncRequestState_t GetRequestState() { return m_Base.GetRequestState(); }
  138. virtual AsyncRequestStatus_t GetRequestStatus() { return m_Base.GetRequestStatus(); }
  139. private:
  140. virtual CAsyncRequestBase* GetBase() { return (CAsyncRequestBase*) &m_Base; }
  141. // ----------------------------------------------------
  142. // methods from the IAsyncGroupRequest Interface
  143. // ----------------------------------------------------
  144. public:
  145. virtual void AddAsyncRequest( IAsyncRequestBase* pRequest );
  146. virtual int32 GetAsyncRequestCount() { return m_RequestList.Count(); }
  147. virtual IAsyncRequestBase* GetAsyncRequest( int32 nRNum );
  148. virtual IAsyncFileRequest* GetAsyncFileRequest( int32 nRNum );
  149. virtual IAsyncSearchRequest* GetAsyncSearchRequest( int32 nRNum );
  150. virtual void ReleaseAsyncRequest( int32 nRNum );
  151. void NotifyOfCompletion( IAsyncRequestBase* pRequest );
  152. private:
  153. explicit CAsyncGroupRequest( const CAsyncRequestBase& rhs ); // copy constructor - NOT SUPPORTED
  154. CAsyncRequestBase& operator=( const CAsyncGroupRequest& rhs ); // assignment operator - NOT SUPPORTED
  155. };
  156. //-----------------------------------------------------------------------------
  157. // CAsyncFileRequest - Concrete implementation for the IAsyncFileRequest interface
  158. //
  159. // Manages a read or write to file request
  160. //
  161. //-----------------------------------------------------------------------------
  162. class CAsyncFileRequest : public IAsyncFileRequest
  163. {
  164. public:
  165. CAsyncRequestBase m_Base; // Base request - we can't derive from due to multiple inheritance problems
  166. // -------------------------------------------------------
  167. // Members to set by the user before submission
  168. const char* m_pFileName; // file system name (copy of string that we own)
  169. void* m_pUserProvidedDataBuffer; // optional (if read op), system will alloc one if NULL/free if NULL
  170. size_t m_nUserProvidedBufferSize; // size of the memory buffer
  171. int64 m_nFileSeekOffset; // (optional) position in the file to seek to/begin xfer at, 0=beginning
  172. int64 m_nMaxIOSizeInBytes; // optional read clamp, 0=full read
  173. // -------------------------------------------------------
  174. // Members which get set by the file system after submission
  175. void* m_pResultsBuffer; // Buffer results were placed in, could be from user (or not)
  176. size_t m_nResultsBufferSize; // size of results buffer
  177. size_t m_nIOActualSize; // actual size of IO performed
  178. bool m_bDeleteBufferMemory; // Flag indicating the memory holding the file data is deleted when the request is released
  179. public:
  180. CAsyncFileRequest(); // Default Constructor - We want NO implicit constructions
  181. virtual ~CAsyncFileRequest(); // Destructor
  182. // ---------------------------------------------------------
  183. // methods from the IAsyncRequestBase Interface
  184. // ---------------------------------------------------------
  185. // functions to query operation
  186. virtual AsyncFileOperation_t GetAsyncOperationType() { return m_Base.GetAsyncOperationType(); }
  187. // Set completion options
  188. virtual void AssignCallback( CFunctor* pCallback ) { m_Base.AssignCallback( pCallback ); }
  189. virtual void AssignResultQueue( CIOCompletionQueue* pMsgQueue ) { m_Base.AssignResultQueue( pMsgQueue ); }
  190. virtual void AssignCallbackAndQueue( CIOCompletionQueue* pMsgQueue, CFunctor* pCallback ) { m_Base.AssignCallbackAndQueue( pMsgQueue, pCallback); }
  191. // Completion processing functions
  192. virtual void ProcessCallback( bool bRelease = true ) { m_Base.ProcessCallback( bRelease ); }
  193. virtual void KeepRequestPostCallback() { m_Base.KeepRequestPostCallback(); }
  194. virtual void DontKeepRequestPostCallback() { m_Base.DontKeepRequestPostCallback(); }
  195. virtual void Release() { m_Base.Release(); }
  196. // Priority Functions
  197. virtual void SetPriority( int32 nPriority ) { m_Base.SetPriority( nPriority ); }
  198. virtual int32 GetPriority() { return m_Base.GetPriority(); }
  199. // Status & Results functions
  200. virtual AsyncRequestState_t GetRequestState() { return m_Base.GetRequestState(); }
  201. virtual AsyncRequestStatus_t GetRequestStatus() { return m_Base.GetRequestStatus(); }
  202. private:
  203. virtual CAsyncRequestBase* GetBase() { return (CAsyncRequestBase*) &m_Base; }
  204. // ----------------------------------------------------
  205. // methods from the IAsyncFileRequest Interface
  206. // ----------------------------------------------------
  207. public:
  208. // functions to set filename and operation
  209. virtual void LoadFile( const char* pFileName ); // make this a 'read data from file' request
  210. virtual void SaveFile( const char* pFileName ); // make this a 'write data to file' request
  211. virtual void AppendFile( const char* pFileName ); // make this a 'append data to file' request
  212. virtual void SetFileName( const char* pFileName ); // assign the filename to use
  213. virtual const char* GetFileName() { return m_pFileName; } // get the filename we've assigned
  214. // Buffer control functions
  215. virtual void SetUserBuffer( void* pDataBuffer, size_t nBufferSize ); // User supplies a memory buffer to use, which they own the memory for
  216. virtual void* GetUserBuffer() { return m_pUserProvidedDataBuffer; } // returns the address of the user supplied buffer
  217. virtual size_t GetUserBufferSize() { return m_nUserProvidedBufferSize; } // returns the size of the user supplied buffer
  218. virtual void ProvideDataBuffer(); // file system provide a buffer with the results
  219. // returned buffer (read) functions
  220. virtual void* GetResultBuffer() { return m_pResultsBuffer; } // Returns the address of the data transferred
  221. virtual size_t GetResultBufferSize() { return m_nResultsBufferSize; } // Returns the size of the buffer holding the data transferred
  222. virtual size_t GetIOTransferredSize() { return m_nIOActualSize; } // Returns the number of bytes of data actually transferred
  223. // Memory control functions for buffers allocated by the async file system
  224. virtual void KeepResultBuffer() { m_bDeleteBufferMemory = false; } // User wants to keeps buffer allocated by the file system
  225. virtual void ReleaseResultBuffer() { m_bDeleteBufferMemory = true; } // User decides they want the request to take care of releasing the buffer
  226. // file position functions
  227. virtual void ReadFileDataAt( int64 nOffset, size_t nReadSize = 0 ); // Read file data starting at supplied offset, optional max size to read
  228. virtual void WriteFileDataAt( int64 nOffset, size_t nWriteSize = 0 ); // Write data to file at supplied offset, optional size to write (max size of buffer)
  229. // --------------------------------------------------------------
  230. // Public Methods not included in the interface, used by Async FileSystem
  231. void AbortAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  232. void UpdateAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  233. AsyncRequestStatus_t ValidateSubmittedRequest( bool bPerformSync ); // Validates the derived object data at request submission
  234. bool ValidateRequestModification(); // Check to determine if modification is allowed at this time
  235. protected:
  236. // Helper functions for repeated operations
  237. void RefreshFileName( const char* pNewFileName );
  238. private:
  239. // disabled functions
  240. explicit CAsyncFileRequest( const CAsyncFileRequest& rhs ); // copy constructor - NOT SUPPORTED
  241. CAsyncFileRequest& operator=( const CAsyncFileRequest& rhs ); // assignment operator - NOT SUPPORTED
  242. };
  243. //-----------------------------------------------------------------------------
  244. // CAsyncSearchRequest - Implementation of the Interface for setting and reading
  245. // the results of an asynchronous directory search request
  246. //
  247. //-----------------------------------------------------------------------------
  248. class CAsyncSearchRequest : public IAsyncSearchRequest
  249. {
  250. public:
  251. CAsyncRequestBase m_Base; // Base request - we can't derive from due to multiple inheritance problems
  252. // CUtlStringList m_DirectoryList; // List of directories we have scanned
  253. int32 m_nNumResults; // number of results
  254. bool m_bRecurseSubdirs; // flag to activate recursing of subdirectories
  255. CUtlVector<CDirectoryEntryInfo_t> m_Results; // Search results...
  256. char m_FileSpec[MAX_PATH]; // filespec of the files we are looking for
  257. char m_PathID[MAX_PATH];
  258. char m_SearchPath[MAX_PATH];
  259. char m_SearchSpec[MAX_PATH];
  260. public:
  261. CAsyncSearchRequest(); // Default Constructor - We want NO implicit constructions
  262. virtual ~CAsyncSearchRequest(); // Destructor
  263. // ---------------------------------------------------------
  264. // methods from the IAsyncRequestBase Interface
  265. // ---------------------------------------------------------
  266. // functions to query operation
  267. virtual AsyncFileOperation_t GetAsyncOperationType() { return m_Base.GetAsyncOperationType(); }
  268. // Set completion options
  269. virtual void AssignCallback( CFunctor* pCallback ) { m_Base.AssignCallback( pCallback ); }
  270. virtual void AssignResultQueue( CIOCompletionQueue* pMsgQueue ) { m_Base.AssignResultQueue( pMsgQueue ); }
  271. virtual void AssignCallbackAndQueue( CIOCompletionQueue* pMsgQueue, CFunctor* pCallback ) { m_Base.AssignCallbackAndQueue( pMsgQueue, pCallback); }
  272. // Completion processing functions
  273. virtual void ProcessCallback( bool bRelease = true ) { m_Base.ProcessCallback( bRelease ); }
  274. virtual void KeepRequestPostCallback() { m_Base.KeepRequestPostCallback(); }
  275. virtual void DontKeepRequestPostCallback() { m_Base.DontKeepRequestPostCallback(); }
  276. virtual void Release() { m_Base.Release(); }
  277. // Priority Functions
  278. virtual void SetPriority( int32 nPriority ) { m_Base.SetPriority( nPriority ); }
  279. virtual int32 GetPriority() { return m_Base.GetPriority(); }
  280. // Status & Results functions
  281. virtual AsyncRequestState_t GetRequestState() { return m_Base.GetRequestState(); }
  282. virtual AsyncRequestStatus_t GetRequestStatus() { return m_Base.GetRequestStatus(); }
  283. private:
  284. virtual CAsyncRequestBase* GetBase() { return (CAsyncRequestBase*) &m_Base; }
  285. // ---------------------------------------------------------
  286. // methods from the IAsyncSearchRequest Interface
  287. // ---------------------------------------------------------
  288. public:
  289. // functions to define the request
  290. virtual void SetSearchFilespec( const char* pFullSearchSpec );
  291. virtual void SetSearchPathAndFileSpec( const char* pPathId, const char* pRelativeSearchSpec );
  292. virtual void SetSearchPathAndFileSpec( const char* pPathId, const char* pRelativeSearchPath, const char* pSearchSpec );
  293. virtual void SetSubdirectoryScan( const bool bInclude );
  294. virtual bool GetSubdirectoryScan() { return m_bRecurseSubdirs; }
  295. // Functions to return the results.
  296. virtual int GetResultCount() { return m_nNumResults; }
  297. virtual CDirectoryEntryInfo_t* GetResult( int rNum = 0 );
  298. virtual const char* GetMatchedFile( int rNum = 0 );
  299. // --------------------------------------------------------------
  300. // Public Methods not included in the interface, used by Async FileSystem
  301. void AbortAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  302. void UpdateAfterServicing( CAsyncResultInfo_t& results ); // Handle a request that got aborted while being serviced
  303. AsyncRequestStatus_t ValidateSubmittedRequest( bool bPerformSync ); // Validates the derived object data at request submission
  304. bool ValidateRequestModification(); // Check to determine if modification is allowed at this time
  305. private:
  306. // disabled functions
  307. explicit CAsyncSearchRequest( const CAsyncSearchRequest& rhs ); // copy constructor - NOT SUPPORTED
  308. CAsyncSearchRequest& operator=( const CAsyncSearchRequest& rhs ); // assignment operator - NOT SUPPORTED
  309. };
  310. //-----------------------------------------------------------------------------
  311. // CAsyncRequestQueue
  312. // Helper object for filesystem - Linked list of objects
  313. // dreeived from CAsyncRequestBase
  314. //-----------------------------------------------------------------------------
  315. class CAsyncRequestQueue
  316. {
  317. private:
  318. CThreadFastMutex m_Mutex;
  319. int32 m_nQueueSize;
  320. CAsyncRequestBase* m_pHead;
  321. CAsyncRequestBase* m_pTail;
  322. public:
  323. CAsyncRequestQueue();
  324. ~CAsyncRequestQueue();
  325. int32 GetSize() { return m_nQueueSize; }
  326. bool IsInQueue( CAsyncRequestBase* pItem );
  327. bool IsInQueueIp( const IAsyncRequestBase* pInterfaceBase );
  328. void AddToHead( CAsyncRequestBase* pItem );
  329. void AddToTail( CAsyncRequestBase* pItem );
  330. void InsertBefore( CAsyncRequestBase* pItem, CAsyncRequestBase* pInsertAt );
  331. void InsertAfter( CAsyncRequestBase* pItem, CAsyncRequestBase* pInsertAt );
  332. void PriorityInsert( CAsyncRequestBase* pItem );
  333. void Remove( CAsyncRequestBase* pItem );
  334. CAsyncRequestBase* RemoveHead();
  335. };
  336. //-----------------------------------------------------------------------------
  337. // CAsyncFileSystem - implements IAsyncFileSystem interface
  338. //
  339. //-----------------------------------------------------------------------------
  340. class CAsyncFileSystem : public CTier2AppSystem< IAsyncFileSystem >
  341. {
  342. typedef CTier2AppSystem< IAsyncFileSystem > BaseClass;
  343. friend class CAsyncGroupRequest;
  344. public:
  345. static const int s_MaxPlatformFileNameLength = 40;
  346. public:
  347. CAsyncFileSystem();
  348. ~CAsyncFileSystem();
  349. //--------------------------------------------------
  350. // Interface methods exposed with IAsyncFileSystem
  351. //--------------------------------------------------
  352. virtual AsyncRequestStatus_t SubmitAsyncFileRequest( const IAsyncRequestBase* pRequest );
  353. virtual AsyncRequestStatus_t SubmitSyncFileRequest( const IAsyncRequestBase* pRequest );
  354. virtual AsyncRequestStatus_t GetAsyncFileRequestStatus( const IAsyncRequestBase* pRequest );
  355. virtual AsyncRequestStatus_t AbortAsyncFileRequest( const IAsyncRequestBase* pRequest );
  356. virtual void SuspendAllAsyncIO( bool bWaitForIOCompletion = true );
  357. virtual void ResumeAllAsyncIO();
  358. virtual AsyncRequestStatus_t AbortAllAsyncIO( bool bWaitForIOCompletion = true );
  359. virtual IAsyncFileRequest* CreateNewFileRequest();
  360. virtual IAsyncSearchRequest* CreateNewSearchRequest();
  361. virtual IAsyncGroupRequest* CreateNewAsyncRequestGroup();
  362. virtual void ReleaseAsyncRequest( const IAsyncRequestBase* pRequest );
  363. virtual bool BlockUntilAsyncIOComplete( const IAsyncRequestBase* pRequest );
  364. virtual void* AllocateBuffer( size_t nBufferSize, int nAlignment = 4 );
  365. virtual void ReleaseBuffer( void* pBuffer );
  366. //--------------------------------------------------
  367. // Public Methods used inside the filesystem
  368. //--------------------------------------------------
  369. void* QueryInterface( const char *pInterfaceName );
  370. void RemoveRequest( CAsyncRequestBase* pRequest );
  371. bool ResolveAsyncRequest( const IAsyncRequestBase* pRequest, CAsyncRequestBase*& pRequestBase, AsyncRequestState_t& CurrentStage );
  372. bool ValidateRequestPtr( CAsyncRequestBase* pRequest );
  373. private:
  374. CAsyncRequestQueue m_Composing; // requests in state: Composing
  375. CAsyncRequestQueue m_Submitted; // requests in state: Submitted
  376. CAsyncRequestQueue m_InFlight; // requests in state: Serviced
  377. CAsyncRequestQueue m_Completed; // requests in state: Awaiting Finished, Completed*
  378. CInterlockedInt m_nJobsInflight; // number of requests currently being serviced by the old system
  379. CInterlockedInt m_nSuspendCount; // number of requests to suspend all Async IO outstanding (nested request support)
  380. bool m_bIOSuspended;
  381. #if defined(_DEBUG)
  382. CThreadFastMutex m_MemoryTrackMutex;
  383. CUtlVector<void*> m_AllocList; // Debug build - track allocations
  384. #endif
  385. CThreadFastMutex m_AsyncStateUpdateMutex;
  386. CThreadEvent m_CompletionSignal; // Used to signal the completion of an IO
  387. AsyncRequestStatus_t ValidateRequest( CAsyncRequestBase* pRequest, bool bPerformSync = false );
  388. void KickOffFileJobs();
  389. void WaitForServincingIOCompletion(); // Pauses until all jobs being serviced are complete
  390. static void* OldAsyncAllocatorCallback( const char *pszFilename, unsigned nBytes );
  391. static void AsyncIOCallbackGateway(const FileAsyncRequest_t &request, int nBytesRead, FSAsyncStatus_t err);
  392. static void AsyncSearchCallbackAddItem( void* pContext, char* pFoundPath, char* pFoundFile );
  393. static void AsyncSearchCallbackGateway( void* pContext, FSAsyncStatus_t err );
  394. void AsyncIOCallBackHandler(CAsyncRequestBase* pRequest, CAsyncResultInfo_t& results );
  395. void NotifyMessageQueueOrCallback( CAsyncRequestBase* pRequest );
  396. };
  397. //-----------------------------------------------------------------------------
  398. // Utility functions
  399. //
  400. //-----------------------------------------------------------------------------
  401. AsyncRequestStatus_t ValidateFileName( const char* pFileName );
  402. #endif