Leaked source code of windows server 2003
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.

61 lines
1.3 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. //
  3. // This header contains classes used to manage the memory mapped file for this DLL
  4. //
  5. class CScopeMutex
  6. {
  7. public:
  8. CScopeMutex()
  9. : m_hMutex(0)
  10. {};
  11. ~CScopeMutex() { MutexRelease(); }
  12. BOOL Create(LPCTSTR szMutex, unsigned long ulWait)
  13. {
  14. m_hMutex = CreateMutex( NULL, FALSE, szMutex );
  15. if (m_hMutex)
  16. {
  17. WaitForSingleObject(m_hMutex, ulWait);
  18. return TRUE;
  19. }
  20. DBPRINTF(TEXT("CScopeMutex::Create FAILED\r\n"));
  21. return FALSE;
  22. }
  23. void Release()
  24. {
  25. MutexRelease();
  26. }
  27. private:
  28. HANDLE m_hMutex;
  29. inline void MutexRelease()
  30. {
  31. if (m_hMutex)
  32. {
  33. ReleaseMutex(m_hMutex);
  34. CloseHandle(m_hMutex);
  35. m_hMutex = 0;
  36. }
  37. }
  38. };
  39. class CMemMappedFile
  40. {
  41. public:
  42. CMemMappedFile()
  43. : m_hMappedFile(0)
  44. , m_pvMappedAddr(0)
  45. , m_fFirstOpen(FALSE)
  46. {};
  47. ~CMemMappedFile() { Close(); }
  48. BOOL Open(LPCTSTR szName, unsigned long ulMemSize);
  49. BOOL AccessMem(void **ppvMappedAddr);
  50. void Close();
  51. BOOL FirstOpen() { return m_fFirstOpen; }
  52. private:
  53. HANDLE m_hMappedFile;
  54. void *m_pvMappedAddr;
  55. BOOL m_fFirstOpen;
  56. };