home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / thrimpl.cpp < prev    next >
Text File  |  2002-06-06  |  4KB  |  176 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        include/wx/thrimpl.cpp
  3. // Purpose:     common part of wxThread Implementations
  4. // Author:      Vadim Zeitlin
  5. // Modified by:
  6. // Created:     04.06.02 (extracted from src/*/thread.cpp files)
  7. // RCS-ID:      $Id: thrimpl.cpp,v 1.1 2002/06/06 18:31:58 VZ Exp $
  8. // Copyright:   (c) Vadim Zeitlin (2002)
  9. // Licence:     wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. // this file is supposed to be included only by the various thread.cpp
  13.  
  14. // ----------------------------------------------------------------------------
  15. // wxMutex
  16. // ----------------------------------------------------------------------------
  17.  
  18. wxMutex::wxMutex(wxMutexType mutexType)
  19. {
  20.     m_internal = new wxMutexInternal(mutexType);
  21.  
  22.     if ( !m_internal->IsOk() )
  23.     {
  24.         delete m_internal;
  25.         m_internal = NULL;
  26.     }
  27. }
  28.  
  29. wxMutex::~wxMutex()
  30. {
  31.     delete m_internal;
  32. }
  33.  
  34. bool wxMutex::IsOk() const
  35. {
  36.     return m_internal != NULL;
  37. }
  38.  
  39. wxMutexError wxMutex::Lock()
  40. {
  41.     wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
  42.                  _T("wxMutex::Lock(): not initialized") );
  43.  
  44.     return m_internal->Lock();
  45. }
  46.  
  47. wxMutexError wxMutex::TryLock()
  48. {
  49.     wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
  50.                  _T("wxMutex::TryLock(): not initialized") );
  51.  
  52.     return m_internal->TryLock();
  53. }
  54.  
  55. wxMutexError wxMutex::Unlock()
  56. {
  57.     wxCHECK_MSG( m_internal, wxMUTEX_INVALID,
  58.                  _T("wxMutex::Unlock(): not initialized") );
  59.  
  60.     return m_internal->Unlock();
  61. }
  62.  
  63. // ----------------------------------------------------------------------------
  64. // wxCondition
  65. // ----------------------------------------------------------------------------
  66.  
  67. wxCondition::wxCondition(wxMutex& mutex)
  68. {
  69.     m_internal = new wxConditionInternal(mutex);
  70.  
  71.     if ( !m_internal->IsOk() )
  72.     {
  73.         delete m_internal;
  74.         m_internal = NULL;
  75.     }
  76. }
  77.  
  78. wxCondition::~wxCondition()
  79. {
  80.     delete m_internal;
  81. }
  82.  
  83. bool wxCondition::IsOk() const
  84. {
  85.     return m_internal != NULL;
  86. }
  87.  
  88. wxCondError wxCondition::Wait()
  89. {
  90.     wxCHECK_MSG( m_internal, wxCOND_INVALID,
  91.                  _T("wxCondition::Wait(): not initialized") );
  92.  
  93.     return m_internal->Wait();
  94. }
  95.  
  96. wxCondError wxCondition::WaitTimeout(unsigned long milliseconds)
  97. {
  98.     wxCHECK_MSG( m_internal, wxCOND_INVALID,
  99.                  _T("wxCondition::Wait(): not initialized") );
  100.  
  101.     return m_internal->WaitTimeout(milliseconds);
  102. }
  103.  
  104. wxCondError wxCondition::Signal()
  105. {
  106.     wxCHECK_MSG( m_internal, wxCOND_INVALID,
  107.                  _T("wxCondition::Signal(): not initialized") );
  108.  
  109.     return m_internal->Signal();
  110. }
  111.  
  112. wxCondError wxCondition::Broadcast()
  113. {
  114.     wxCHECK_MSG( m_internal, wxCOND_INVALID,
  115.                  _T("wxCondition::Broadcast(): not initialized") );
  116.  
  117.     return m_internal->Broadcast();
  118. }
  119.  
  120. // --------------------------------------------------------------------------
  121. // wxSemaphore
  122. // --------------------------------------------------------------------------
  123.  
  124. wxSemaphore::wxSemaphore(int initialcount, int maxcount)
  125. {
  126.     m_internal = new wxSemaphoreInternal( initialcount, maxcount );
  127.     if ( !m_internal->IsOk() )
  128.     {
  129.         delete m_internal;
  130.         m_internal = NULL;
  131.     }
  132. }
  133.  
  134. wxSemaphore::~wxSemaphore()
  135. {
  136.     delete m_internal;
  137. }
  138.  
  139. bool wxSemaphore::IsOk() const
  140. {
  141.     return m_internal != NULL;
  142. }
  143.  
  144. wxSemaError wxSemaphore::Wait()
  145. {
  146.     wxCHECK_MSG( m_internal, wxSEMA_INVALID,
  147.                  _T("wxSemaphore::Wait(): not initialized") );
  148.  
  149.     return m_internal->Wait();
  150. }
  151.  
  152. wxSemaError wxSemaphore::TryWait()
  153. {
  154.     wxCHECK_MSG( m_internal, wxSEMA_INVALID,
  155.                  _T("wxSemaphore::TryWait(): not initialized") );
  156.  
  157.     return m_internal->TryWait();
  158. }
  159.  
  160. wxSemaError wxSemaphore::WaitTimeout(unsigned long milliseconds)
  161. {
  162.     wxCHECK_MSG( m_internal, wxSEMA_INVALID,
  163.                  _T("wxSemaphore::WaitTimeout(): not initialized") );
  164.  
  165.     return m_internal->WaitTimeout(milliseconds);
  166. }
  167.  
  168. wxSemaError wxSemaphore::Post()
  169. {
  170.     wxCHECK_MSG( m_internal, wxSEMA_INVALID,
  171.                  _T("wxSemaphore::Post(): not initialized") );
  172.  
  173.     return m_internal->Post();
  174. }
  175.  
  176.