BlMsf.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "../Beef/BfCommon.h"
  3. #include "BeefySysLib/FileStream.h"
  4. #include "BeefySysLib/util/CritSect.h"
  5. #include "BeefySysLib/util/WorkThread.h"
  6. #include "../Compiler/BfUtil.h"
  7. #include <queue>
  8. NS_BF_BEGIN
  9. struct BlMsfBlock
  10. {
  11. public:
  12. int mIdx;
  13. bool mIsUsed;
  14. void* mData;
  15. public:
  16. BlMsfBlock()
  17. {
  18. mIdx = -1;
  19. mIsUsed = true;
  20. mData = NULL;
  21. }
  22. };
  23. class BlCodeView;
  24. class BlMsf;
  25. class BlMsfWorkThread : public WorkThread
  26. {
  27. public:
  28. BlMsf* mMsf;
  29. bool mDone;
  30. CritSect mCritSect;
  31. SyncEvent mWorkEvent;
  32. std::deque<BlMsfBlock*> mSortedWriteBlockWorkQueue;
  33. std::deque<BlMsfBlock*> mWriteBlockWorkQueue;
  34. bool mSortDirty;
  35. public:
  36. BlMsfWorkThread();
  37. ~BlMsfWorkThread();
  38. virtual void Stop() override;
  39. virtual void Run() override;
  40. void Add(BlMsfBlock* block);
  41. };
  42. class BlMsf
  43. {
  44. public:
  45. SysFileStream mFS;
  46. String mFileName;
  47. int mFileSize;
  48. int mAllocatedFileSize;
  49. BlCodeView* mCodeView;
  50. int mBlockSize;
  51. int mFreePageBitmapIdx; // Either 1 or 2
  52. OwnedVector<BlMsfBlock> mBlocks;
  53. BlMsfWorkThread mWorkThread;
  54. public:
  55. void WriteBlock(BlMsfBlock* block);
  56. public:
  57. BlMsf();
  58. ~BlMsf();
  59. bool Create(const StringImpl& fileName);
  60. int Alloc(bool clear = true, bool skipFPMBlocks = true);
  61. void FlushBlock(int blockIdx);
  62. void Finish(int rootBlockNum, int streamDirLen);
  63. };
  64. NS_BF_END