home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / wptd.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  2.7 KB  |  84 lines

  1.  
  2. #ifndef _WPTD_HPP_INCLUDED
  3. #define _WPTD_HPP_INCLUDED
  4. #pragma once
  5.  
  6. #include "wdef.hpp"
  7.  
  8. //
  9. // Per-thread data allocation/deallocation
  10. //
  11.  
  12. typedef void * WCMDEF (*WPTDAllocFunction)( int ptdID, WDWord threadID );
  13. typedef void WCMDEF (*WPTDDeallocFunction)( int ptdID, WDWord threadID,
  14.                                             void *ptd );
  15.  
  16. class WBaseSemaphore;
  17.  
  18. class WCMCLASS WPerThreadData {
  19.  
  20.     public:
  21.  
  22.         /***********************************************************
  23.          * Static methods
  24.          ***********************************************************/
  25.  
  26.         // AllocateID
  27.         //
  28.         //    Allocates an identifier for per-thread data.  Allocation
  29.         //    and deallocation functions can be provided to initialize
  30.         //    and deinitialize per-thread data.  The allocation function
  31.         //    is always called on the given thread, but the deallocation
  32.         //    function might be called on a different thread (during
  33.         //    cleanup).  Returns -1 on error.  If no allocation or
  34.         //    deallocation functions are passed in, a simple "void *"
  35.         //    is used and you must use Replace to set its value.
  36.  
  37.         static int AllocateID( WPTDAllocFunction a, WPTDDeallocFunction d );
  38.  
  39.         // DeallocateID
  40.         //
  41.         //    Deallocate a per-thread data identifier.  Calls the
  42.         //    deallocation functions for all PTD with the given ID.
  43.  
  44.         static void DeallocateID( int id );
  45.  
  46.         // Find
  47.         //
  48.         //    Given an ID, return the per-thread data associated with
  49.         //    that ID.  If no such data exists, either allocates it
  50.         //    (if allocIfNecessary is true) or returns NULL.
  51.  
  52.         static void *Find( int id, WBool allocIfNecessary );
  53.  
  54.         // Release
  55.         //
  56.         //    Releases the per-thread data associated with an ID,
  57.         //    but only for the current thread.  Pass in -1 to release
  58.         //    all per-thread data for the thread.  The deallocation
  59.         //    function(s) will be called on release.
  60.  
  61.         static void Release( int id );
  62.  
  63.         // Replace
  64.         //
  65.         //    Replaces the per-thread data associated with an ID.
  66.         //    Does not call the deallocation function.  Returns
  67.         //    the previous value.
  68.  
  69.         static void *Replace( int id, void *newValue );
  70.  
  71.         /***********************************************************
  72.          * Other
  73.          ***********************************************************/
  74.  
  75.         // DeallocateAll
  76.         //
  77.         //    Called on process termination to free all per-thread
  78.         //    data for all threads.  Do not call directly.  
  79.  
  80.         static void DeallocateAll();
  81. };
  82.  
  83. #endif
  84.