home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / mtcore.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  1.9 KB  |  89 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. #define new DEBUG_NEW
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Basic synchronization object
  22.  
  23. CSyncObject::CSyncObject(LPCTSTR pstrName)
  24. {
  25.     UNUSED(pstrName);   // unused in release builds
  26.  
  27.     m_hObject = NULL;
  28.  
  29. #ifdef _DEBUG
  30.     m_strName = pstrName;
  31. #endif
  32. }
  33.  
  34. CSyncObject::~CSyncObject()
  35. {
  36.     if (m_hObject != NULL)
  37.     {
  38.         ::CloseHandle(m_hObject);
  39.         m_hObject = NULL;
  40.     }
  41. }
  42.  
  43. BOOL CSyncObject::Lock(DWORD dwTimeout)
  44. {
  45.     if (::WaitForSingleObject(m_hObject, dwTimeout) == WAIT_OBJECT_0)
  46.         return TRUE;
  47.     else
  48.         return FALSE;
  49. }
  50.  
  51. #ifdef _DEBUG
  52.  
  53. void CSyncObject::Dump(CDumpContext& dc) const
  54. {
  55.     dc << "Object ";
  56.     dc << m_hObject;
  57.     dc << " named " << m_strName << "\n";
  58.     CObject::Dump(dc);
  59. }
  60.  
  61. void CSyncObject::AssertValid() const
  62. {
  63.     CObject::AssertValid();
  64. }
  65.  
  66. #endif
  67.  
  68. //////////////////////////////////////////////////////////////////////////////
  69. // Inline function declarations expanded out-of-line
  70.  
  71. #ifndef _AFX_ENABLE_INLINES
  72.  
  73. static char _szAfxMtInl[] = "afxmt.inl";
  74. #undef THIS_FILE
  75. #define THIS_FILE _szAfxMtInl
  76. #define _AFXMT_INLINE
  77. #include "afxmt.inl"
  78.  
  79. #endif
  80.  
  81. #ifdef AFX_INIT_SEG
  82. #pragma code_seg(AFX_INIT_SEG)
  83. #endif
  84.  
  85. IMPLEMENT_DYNAMIC(CCriticalSection, CSyncObject)
  86. IMPLEMENT_DYNAMIC(CSyncObject, CObject)
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89.