home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / OThread.inl < prev    next >
Text File  |  1996-08-12  |  4KB  |  121 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OThread.inl
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30. // $Header: W:/Projects/OCL/Include/rcs/OThread.inl 1.50 1996/08/11 23:47:33 B.STEIN Release $
  31.  
  32. #ifndef OTHREAD_INLINED
  33.   #define OTHREAD_INLINED
  34.  
  35.  
  36. #ifdef __IBMCPP__
  37.  
  38. template <class T>
  39. OThread<T>::OThread(OptlinkFnPtr aFunction,
  40.                     ULONG stackSize,
  41.                     BOOL forPM,
  42.                     PVOID pvData)
  43.      : OThreadBase(stackSize, forPM),
  44.        member(NULL),
  45.        object((T*)NULL),
  46.        threadFunc((PFNTHREAD)aFunction),
  47.        pArgs(pvData)
  48. {}
  49.  
  50. #endif // __IBMCPP__
  51.  
  52.  
  53.  
  54. template <class T>
  55. OThread<T>::OThread(T* obj,                    // pointer to object
  56.                     void(_WPPCAST_ T::*mem)(), // pointer to member-fn to detach
  57.                     ULONG stackSize,           // stacksize for thread
  58.                     BOOL  forPM)               // initialize PM?
  59.      : OThreadBase(stackSize, forPM),
  60.        member(mem),
  61.        object(obj),
  62.        threadFunc(NULL),
  63.        pArgs(NULL)
  64. {}
  65.  
  66.  
  67. template <class T>
  68. OThread<T>::OThread(T& obj,                    // reference to object
  69.                     void(_WPPCAST_ T::*mem)(), // pointer to member-fn to detach
  70.                     ULONG stackSize,           // stacksize for thread
  71.                     BOOL  forPM)               // initialize PM?
  72.      : OThreadBase(stackSize, forPM),
  73.        member(mem),
  74.        object(&obj),
  75.        threadFunc(NULL),
  76.        pArgs(NULL)
  77. {}
  78.  
  79. template <class T>
  80. OThread<T>::OThread(PFNTHREAD aFunction,
  81.                     ULONG stackSize,
  82.                     BOOL forPM,
  83.                     PVOID pvData)
  84.      : OThreadBase(stackSize, forPM),
  85. #if defined(__EMX__)
  86.        member( 0 ),
  87. #else
  88.        member( NULL),
  89. #endif
  90.        object((T*)NULL),
  91.        threadFunc(aFunction),
  92.        pArgs(pvData)
  93. {}
  94.  
  95.  
  96. template <class T>
  97. OThread<T>::~OThread()
  98. {}
  99.  
  100.  
  101. template <class T>
  102. PSZ OThread<T>::isOfType() const
  103.  return("OThread<T>"); 
  104. }
  105.  
  106.  
  107. template <class T>
  108. void OThread<T>::async() 
  109. {
  110.  if (threadFunc != NULL)
  111.    threadFunc((ULONG)pArgs);
  112.  else if (object)
  113.    (object->*member)(); 
  114. }
  115.  
  116.  
  117. #endif // OTHREAD_INLINED
  118.  
  119. // end of source
  120.