pthreadthreads.h
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 7k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: pthreadthreads.h,v 1.5.32.3 2004/07/09 01:43:45 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #ifndef _PTHREADTHREADS
  50. #define _PTHREADTHREADS
  51. #include "UnixThreads.h"
  52. class HXPthreadCondition;
  53. //=======================================================================
  54. //
  55. //                      HXPthreadMutex
  56. //                   ------------------
  57. //
  58. // NOTE: Mutexs must be recursive.
  59. //=======================================================================
  60. class HXPthreadMutex : public HXUnixMutex
  61. {
  62. public:
  63.     //Ctors and dtors.
  64.     HXPthreadMutex();
  65.     virtual ~HXPthreadMutex();
  66.     friend class HXPthreadCondition;
  67.     
  68. protected:
  69.     //Must be recursive
  70.     virtual HX_RESULT _Lock();
  71.     virtual HX_RESULT _Unlock();
  72.     virtual HX_RESULT _TryLock();
  73.     //Used by freind class HXCondition for locking.
  74.     pthread_mutex_t* _GetPthreadMutex();
  75.         
  76. private:
  77.     pthread_mutex_t m_mutex;
  78.     //These are used to simulate recursive mutexes on systems that don't
  79.     //have them.
  80. #ifndef _MAC_UNIX
  81.     ULONG32         m_ulOwnerThread;
  82. #else
  83.     pthread_t       m_ulOwnerThread;
  84. #endif
  85.     ULONG32         m_ulLockCount;
  86.     pthread_mutex_t m_mtxLockLock; //A mutex to protect the mutex!
  87.     //Prevent unintentional ctors
  88.     HXPthreadMutex( const HXPthreadMutex& ); //copy ctor
  89.     HXPthreadMutex& operator=(const HXPthreadMutex& ); //assignment operator.
  90. };
  91. #ifndef _MAC_UNIX
  92. struct HXsem_t : public sem_t
  93. {
  94.     char padding[64]; /* Flawfinder: ignore */ // different linux versions have different binary reps blechhhh!
  95. };
  96. //=======================================================================
  97. //
  98. //                   HXPthreadSemaphore
  99. //                   ------------------
  100. //
  101. //=======================================================================
  102. class HXPthreadSemaphore : public HXUnixSemaphore
  103. {
  104.   public:
  105.     //Ctors and dtors.
  106.     HXPthreadSemaphore(UINT32 unInitialCount=0);
  107.     virtual ~HXPthreadSemaphore();
  108.         
  109. protected:
  110.     virtual HX_RESULT _Post();
  111.     virtual HX_RESULT _Wait();
  112.     virtual HX_RESULT _TryWait();
  113.     virtual HX_RESULT _GetValue(int* pnCount );
  114. private:
  115.     HXsem_t m_semaphore;
  116.     
  117.     //Prevent unintentional ctors
  118.     HXPthreadSemaphore( const HXPthreadSemaphore& ); //copy ctor
  119.     HXPthreadSemaphore& operator=(const HXPthreadSemaphore& ); //assignment operator.
  120. };
  121. #else
  122. //=======================================================================
  123. //
  124. //                   HXPthreadmacSemaphore
  125. //                   ---------------------
  126. //
  127. //=======================================================================
  128. class HXPthreadMacSemaphore : public HXUnixSemaphore
  129. {
  130.   public:
  131.     //Ctors and dtors.
  132.     HXPthreadMacSemaphore(UINT32 unInitialCount=0);
  133.     virtual ~HXPthreadMacSemaphore();
  134.         
  135. protected:
  136.     virtual HX_RESULT _Post();
  137.     virtual HX_RESULT _Wait();
  138.     virtual HX_RESULT _TryWait();
  139.     virtual HX_RESULT _GetValue(int* pnCount );
  140. private:
  141.     sem_t* m_semaphore;
  142.     
  143.     //Prevent unintentional ctors
  144.     HXPthreadMacSemaphore( const HXPthreadMacSemaphore& ); //copy ctor
  145.     HXPthreadMacSemaphore& operator=(const HXPthreadMacSemaphore& ); //assignment operator.
  146. };
  147. #endif
  148. //=======================================================================
  149. //
  150. //                   HXPthreadCondition
  151. //                   ----------------------
  152. //
  153. //=======================================================================
  154. class HXPthreadCondition : public HXUnixCondition
  155. {
  156. public:
  157.     
  158.     HXPthreadCondition(HXUnixMutex*& pMutex);
  159.     virtual ~HXPthreadCondition();
  160. protected:
  161.     
  162.     virtual HX_RESULT _Wait();
  163.     virtual HX_RESULT _TimedWait( UINT32 uTimeoutPeriod = ALLFS);
  164.     virtual HX_RESULT _Broadcast();
  165.     virtual HX_RESULT _Signal();
  166. private:
  167.     HXPthreadMutex* m_pMutex;
  168.     pthread_cond_t   m_cond;
  169.     //Protect unintentional ctors
  170.     HXPthreadCondition( const HXPthreadCondition& ); //copy ctor.
  171.     HXPthreadCondition& operator=(const HXPthreadCondition& ); //assignment oper.
  172. };
  173. //=======================================================================
  174. //
  175. //                    HXPthreadThread    
  176. //                   ------------------
  177. //
  178. //=======================================================================
  179. class HXPthreadThread : public HXUnixThread
  180. {
  181.   public:
  182.     HXPthreadThread();
  183.     virtual ~HXPthreadThread();
  184. protected:
  185.     //
  186.     // Pure virtuals that implement the OS specific chores.
  187.     //
  188.     virtual HX_RESULT _thread_create( ULONG32& ulThreadID, void*(pfExecFunc(void*)), void* pArg );
  189.     virtual ULONG32   _thread_self();
  190.     virtual void      _thread_exit(UINT32 unExitCode);
  191.     virtual void      _thread_cancel(ULONG32 ulThreadID);
  192.     virtual ULONG32   _thread_join(ULONG32 ulThreadID);
  193.     
  194. private:
  195.     //Prevent unintentional ctors
  196.     HXPthreadThread( const HXPthreadThread& ); //copy ctor
  197.     HXPthreadThread& operator=(const HXPthreadThread&); //assignment operator.
  198. };
  199. #endif /*_PTHREADTHREADS */