home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / THDPL.ZIP / THRDPOOL.HPP < prev    next >
C/C++ Source or Header  |  1992-02-02  |  3KB  |  80 lines

  1. /************************************************************************
  2.  
  3.       File Name..........: THRDPOOL.HPP
  4.       File Description...: Thread Pool Class Header
  5.       Date Written.......: 14-Nov-1991
  6.       Written By.........: Steve Horne / CoralSoft, Inc.
  7.                            305 Judson Dr. E.
  8.                            Mobile, AL  36608
  9.                            (205) 344-2251
  10.  
  11. -------------------------------------------------------------------------
  12.  
  13.    Description
  14.    -----------
  15.    See the description in THRDPOOL.CPP
  16.  
  17.    $Log:   E:/CSICLASS/INCLUDE/VCS/THRDPOOL.HVP  $
  18.    
  19.       Rev 1.0   02 Feb 1992 18:52:48
  20.    Initial revision.
  21.  
  22. -------------------------------------------------------------------------
  23.  
  24.    The C and C++ structures and code in this document have been created
  25.    by CoralSoft, Inc. and are considered proprietary and confidential.
  26.    This information may not be distributed by any means, electronic or
  27.    mechanical, without the prior written consent of CoralSoft, Inc.
  28.    No warranties are either EXPRESSED or IMPLIED.
  29.    Copyright (c) 1991, CoralSoft, Inc.
  30.  
  31. ************************************************************************/
  32. #define   _MT   1
  33. const USHORT TP_MINIMUM_STACK =         2048;
  34.  
  35. //      Thread Pool Result Codes...
  36. const USHORT TP_OK =                     0;
  37. const USHORT TP_NOTHREADS =            1;
  38. const USHORT TP_NOMEMORY =               2;
  39.  
  40. //   Thread commands to execute when pSignals[] is clear
  41. enum TP_THREAD_COMMAND {
  42.    TPC_INITIALIZE,
  43.    TPC_DISPATCH,
  44.    TPC_TERMINATE
  45. };
  46.  
  47. enum TP_THREAD_STATE {
  48.    TPS_WAITING,                     // Waiting for work
  49.    TPS_USERFUNC,                     // Executing a user function
  50.    TPS_STOPPED                        // Terminated by killAll
  51. };
  52.  
  53. class ThreadPool {
  54.    TID *pTIDs;                     
  55.    RESULTCODES *pResults;          
  56.    ULONG *pSignals;                
  57.    TP_THREAD_STATE *pStates;       
  58.    int thread_count;               
  59.    USHORT stack_size;              
  60.    USHORT lastError;
  61.    ULONG poolSem;                  
  62.    int active_threads;              
  63.    int current_index;               
  64.    HSEM current_notify;             
  65.    TP_THREAD_COMMAND current_cmd;   
  66.    void (*current_function)(PVOID args);
  67.    PVOID current_argument;          
  68. public:
  69.    VOID FAR internal_thread(void);   // Thread function
  70.    ThreadPool(int count, USHORT stack = 2048);
  71.    ~ThreadPool(void);
  72.    USHORT start(void (*func)(PVOID), PVOID arg = NULL, HSEM notify = NULL);
  73.    USHORT error(void);
  74.    void killAll(void);
  75.  
  76. };
  77.  
  78. extern "C" void C_thread(ThreadPool *tp);
  79.  
  80.