hxthread.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:7k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxtypes.h"
  36. #if defined (_WIN32) || defined (_WINDOWS)
  37. #include <windows.h>
  38. #endif
  39. #include "hxresult.h"
  40. #include "hxassert.h"
  41. #include "hxthread.h"
  42. #include "genthrd.h"
  43. #if defined (_WIN32)
  44. #include "winthrd.h"
  45. #endif
  46. #if defined( _UNIX_THREADS_SUPPORTED )
  47. #  include "UnixThreads.h"
  48. #endif
  49. #if defined( _SYMBIAN )
  50. # include "hxslist.h"
  51. # include "hxmap.h"
  52. # include "symbianthreads.h"
  53. #endif
  54. #if defined (_MACINTOSH)
  55. #ifdef THREADS_SUPPORTED
  56. #include "platform/mac/carbthrd.h"
  57. #else
  58. #include "macthrd.h"
  59. #endif
  60. #endif
  61. #include "hxheap.h"
  62. #ifdef _DEBUG
  63. #undef HX_THIS_FILE
  64. static const char HX_THIS_FILE[] = __FILE__;
  65. #endif  
  66. HXThread::~HXThread()
  67. {
  68. }
  69. HX_RESULT
  70. HXThread::MakeThread(HXThread*& pThread)
  71. {
  72.     pThread = 0;
  73. #ifdef _WIN32
  74.     pThread = new HXWinThread;
  75. #elif defined (_MACINTOSH)
  76. # ifdef THREADS_SUPPORTED
  77.     pThread = new HXCarbonThread;
  78. # else
  79.     pThread = new HXMacThread;
  80. # endif
  81. #elif defined( _UNIX_THREADS_SUPPORTED )
  82.     HXUnixThread::MakeThread(pThread);
  83. #elif defined _SYMBIAN
  84.     pThread = new HXSymbianThread();
  85. #else
  86.     pThread = new HXGenThread;
  87. #endif
  88.     if (!pThread)
  89.     {
  90. return HXR_OUTOFMEMORY;
  91.     }
  92.     return HXR_OK;
  93. }
  94. HX_RESULT
  95. HXThread::MakeStubThread(HXThread*& pThread)
  96. {
  97.     pThread = 0;
  98.     pThread = new HXGenThread;
  99.     if (!pThread)
  100.     {
  101. return HXR_OUTOFMEMORY;
  102.     }
  103.     return HXR_OK;
  104. }
  105. HXMutex::~HXMutex()
  106. {
  107. }
  108. HX_RESULT
  109. HXMutex::MakeNamedMutex(HXMutex*& pMutex, char* name)
  110. {
  111.     pMutex = NULL;
  112. #ifdef _WIN32
  113.     pMutex = new HXWinNamedMutex(name);
  114. #else
  115.     pMutex = new HXGenMutex;
  116. #endif
  117.     if (!pMutex)
  118.     {
  119. return HXR_OUTOFMEMORY;
  120.     }
  121.     return HXR_OK;
  122. }
  123. HX_RESULT
  124. HXMutex::MakeMutex(HXMutex*& pMutex)
  125. {
  126.     pMutex = 0;
  127. #ifdef _WIN32
  128.     pMutex = new HXWinMutex;
  129. #elif defined( _UNIX_THREADS_SUPPORTED )
  130.     HXUnixMutex::MakeMutex(pMutex);
  131. #elif defined _MACINTOSH
  132. #ifdef THREADS_SUPPORTED
  133.     pMutex = new HXCarbonMutex;
  134. #else
  135.     pMutex = new HXMacMutex;
  136. #endif
  137. #elif defined _SYMBIAN
  138.     pMutex = new HXSymbianMutex;
  139. #else
  140.     pMutex = new HXGenMutex;
  141. #endif
  142.     if (!pMutex)
  143.     {
  144. return HXR_OUTOFMEMORY;
  145.     }
  146.     return HXR_OK;
  147. }
  148. HX_RESULT
  149. HXMutex::MakeStubMutex(HXMutex*& pMutex)
  150. {
  151.     pMutex = 0;
  152. #if defined(_CARBON) && !defined(THREADS_SUPPORTED)
  153. pMutex = new HXGenMacMutex;
  154. #else
  155.     pMutex = new HXGenMutex;
  156. #endif
  157.     if (!pMutex)
  158.     {
  159. return HXR_OUTOFMEMORY;
  160.     }
  161.     return HXR_OK;
  162. }
  163. HXEvent::~HXEvent()
  164. {
  165. }
  166. HX_RESULT
  167. HXEvent::MakeEvent(HXEvent*& pEvent, const char* pEventName, BOOL bManualReset)
  168. {
  169.     pEvent = 0;
  170. #ifdef _WIN32
  171.     pEvent = new HXWinEvent(pEventName, bManualReset);
  172. #elif defined( _UNIX_THREADS_SUPPORTED )
  173.     pEvent = new HXUnixEvent(pEventName, bManualReset );
  174. #elif defined _MACINTOSH
  175. #ifdef THREADS_SUPPORTED
  176.     if (bManualReset)
  177.     {
  178. pEvent = new HXCarbonManualEvent(pEventName);
  179.     }
  180.     else
  181.     {
  182. pEvent = new HXCarbonEvent(pEventName, bManualReset);
  183.     }
  184. #else
  185.     pEvent = new HXMacEvent(pEventName, bManualReset);
  186. #endif
  187. #elif defined _SYMBIAN
  188.     pEvent = new HXSymbianEvent(pEventName, bManualReset);
  189. #else
  190.     pEvent = new HXGenEvent(pEventName, bManualReset);
  191. #endif
  192.     if (!pEvent)
  193.     {
  194. return HXR_OUTOFMEMORY;
  195.     }
  196.     return HXR_OK;
  197. }
  198. HX_RESULT
  199. HXEvent::MakeStubEvent(HXEvent*& pEvent, const char* pEventName, BOOL bManualReset)
  200. {
  201.     pEvent = 0;
  202.     pEvent = new HXGenEvent(pEventName, bManualReset);
  203.     if (!pEvent)
  204.     {
  205. return HXR_OUTOFMEMORY;
  206.     }
  207.     return HXR_OK;
  208. }
  209. //
  210. // HXAsyncTimer mehtods.
  211. //
  212. UINT32 HXAsyncTimer::SetTimer(ULONG32 ulTimeOut, HXThread* pReceivingThread )
  213. {
  214. #ifdef _WIN32
  215.     return ::SetTimer( NULL, NULL, ulTimeOut, NULL );
  216. #elif defined( _UNIX_THREADS_SUPPORTED )
  217.     return HXUnixAsyncTimer::SetTimer(ulTimeOut, pReceivingThread );
  218. #elif defined _SYMBIAN
  219.     return HXSymbianAsyncTimer::SetTimer(ulTimeOut, pReceivingThread );
  220. #else
  221.     return 0;
  222. //#   error HXAsyncTimer::SetTimer not defined on this platform.
  223. #endif        
  224. }
  225.     
  226. UINT32 HXAsyncTimer::SetTimer(ULONG32 ulTimeOut, TIMERPROC pfExecFunc )
  227. {
  228. #ifdef _WIN32
  229.     return ::SetTimer( NULL, NULL, ulTimeOut, pfExecFunc );
  230. #elif defined( _UNIX_THREADS_SUPPORTED )
  231.     return HXUnixAsyncTimer::SetTimer(ulTimeOut, pfExecFunc );
  232. #elif defined _SYMBIAN
  233.     return HXSymbianAsyncTimer::SetTimer(ulTimeOut, pfExecFunc );
  234. #else
  235.     return 0;
  236. //#   error HXAsyncTimer::SetTimer not defined on this platform.
  237. #endif        
  238. }
  239.     
  240. BOOL HXAsyncTimer::KillTimer(UINT32 ulTimerID )
  241. {
  242. #ifdef _WIN32
  243.     return ::KillTimer( NULL, ulTimerID );
  244. #elif defined( _UNIX_THREADS_SUPPORTED )
  245.     return HXUnixAsyncTimer::KillTimer(ulTimerID );
  246. #elif defined _SYMBIAN
  247.     return HXSymbianAsyncTimer::KillTimer(ulTimerID);
  248. #else
  249.     return TRUE;
  250. //#   error HXAsyncTimer::KillTimer not defined on this platform.
  251. #endif        
  252. }