home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef _WPTD_HPP_INCLUDED
- #define _WPTD_HPP_INCLUDED
- #pragma once
-
- #include "wdef.hpp"
-
- //
- // Per-thread data allocation/deallocation
- //
-
- typedef void * WCMDEF (*WPTDAllocFunction)( int ptdID, WDWord threadID );
- typedef void WCMDEF (*WPTDDeallocFunction)( int ptdID, WDWord threadID,
- void *ptd );
-
- class WBaseSemaphore;
-
- class WCMCLASS WPerThreadData {
-
- public:
-
- /***********************************************************
- * Static methods
- ***********************************************************/
-
- // AllocateID
- //
- // Allocates an identifier for per-thread data. Allocation
- // and deallocation functions can be provided to initialize
- // and deinitialize per-thread data. The allocation function
- // is always called on the given thread, but the deallocation
- // function might be called on a different thread (during
- // cleanup). Returns -1 on error. If no allocation or
- // deallocation functions are passed in, a simple "void *"
- // is used and you must use Replace to set its value.
-
- static int AllocateID( WPTDAllocFunction a, WPTDDeallocFunction d );
-
- // DeallocateID
- //
- // Deallocate a per-thread data identifier. Calls the
- // deallocation functions for all PTD with the given ID.
-
- static void DeallocateID( int id );
-
- // Find
- //
- // Given an ID, return the per-thread data associated with
- // that ID. If no such data exists, either allocates it
- // (if allocIfNecessary is true) or returns NULL.
-
- static void *Find( int id, WBool allocIfNecessary );
-
- // Release
- //
- // Releases the per-thread data associated with an ID,
- // but only for the current thread. Pass in -1 to release
- // all per-thread data for the thread. The deallocation
- // function(s) will be called on release.
-
- static void Release( int id );
-
- // Replace
- //
- // Replaces the per-thread data associated with an ID.
- // Does not call the deallocation function. Returns
- // the previous value.
-
- static void *Replace( int id, void *newValue );
-
- /***********************************************************
- * Other
- ***********************************************************/
-
- // DeallocateAll
- //
- // Called on process termination to free all per-thread
- // data for all threads. Do not call directly.
-
- static void DeallocateAll();
- };
-
- #endif
-