CComAutoThreadModule Class
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
Important
This class and its members cannot be used in applications that execute in the Windows Runtime.
template <class ThreadAllocator = CComSimpleThreadAllocator>
class CComAutoThreadModule : public CComModule
ThreadAllocator
[in] The class managing thread selection. The default value is CComSimpleThreadAllocator.
Function | Description |
---|---|
CreateInstance | Selects a thread and then creates an object in the associated apartment. |
GetDefaultThreads | (Static) Dynamically calculates the number of threads for the module based on the number of processors. |
Init | Creates the module's threads. |
Lock | Increments the lock count on the module and on the current thread. |
Unlock | Decrements the lock count on the module and on the current thread. |
Data member | Description |
---|---|
dwThreadID | Contains the identifier of the current thread. |
m_Allocator | Manages thread selection. |
m_nThreads | Contains the number of threads in the module. |
m_pApartments | Manages the module's apartments. |
Note
This class is obsolete, having been replaced by the CAtlAutoThreadModule and CAtlModule derived classes. The information that follows is for use with older releases of ATL.
CComAutoThreadModule
derives from CComModule to implement a thread-pooled, apartment-model COM server for EXEs and Windows services. CComAutoThreadModule
uses CComApartment to manage an apartment for each thread in the module.
Derive your module from CComAutoThreadModule
when you want to create objects in multiple apartments. You must also include the DECLARE_CLASSFACTORY_AUTO_THREAD macro in your object's class definition to specify CComClassFactoryAutoThread as the class factory.
By default, the ATL COM AppWizard (the ATL Project Wizard in Visual Studio .NET) will derive your module from CComModule
. To use CComAutoThreadModule
, modify the class definition. For example:
class CMyModule :
public CComAutoThreadModule<CComSimpleThreadAllocator>
{
public:
LONG Unlock()
{
LONG l = CComAutoThreadModule<CComSimpleThreadAllocator>::Unlock();
if (l == 0)
PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
return l;
}
DWORD dwThreadID;
};
IAtlAutoThreadModule
CComAutoThreadModule
Header: atlbase.h
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
HRESULT CreateInstance(
void* pfnCreateInstance,
REFIID riid,
void** ppvObj);
pfnCreateInstance
[in] A pointer to a creator function.
riid
[in] The IID of the requested interface.
ppvObj
[out] A pointer to the interface pointer identified by riid. If the object does not support this interface, ppvObj is set to NULL.
A standard HRESULT value.
Selects a thread and then creates an object in the associated apartment.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
DWORD dwThreadID;
Contains the identifier of the current thread.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
static int GetDefaultThreads();
The number of threads to be created in the EXE module.
This static function dynamically calculates the maximum number of threads for the EXE module, based on the number of processors. By default, this return value is passed to the Init method to create the threads.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
HRESULT Init(
_ATL_OBJMAP_ENTRY* p,
HINSTANCE h,
const GUID* plibid = NULL,
int nThreads = GetDefaultThreads());
p
[in] A pointer to an array of object map entries.
h
[in] The HINSTANCE passed to DLLMain
or WinMain
.
plibid
[in] A pointer to the LIBID of the type library associated with the project.
nThreads
[in] The number of threads to be created. By default, nThreads is the value returned by GetDefaultThreads.
Initializes data members and creates the number of threads specified by nThreads.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
LONG Lock();
A value that may be useful for diagnostics or testing.
Performs an atomic increment on the lock count for the module and for the current thread. CComAutoThreadModule
uses the module lock count to determine whether any clients are accessing the module. The lock count on the current thread is used for statistical purposes.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
ThreadAllocator m_Allocator;
The object managing thread selection. By default, the ThreadAllocator
class template parameter is CComSimpleThreadAllocator.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
int m_nThreads;
Contains the number of threads in the EXE module. When Init is called, m_nThreads
is set to the nThreads parameter value. Each thread's associated apartment is managed by a CComApartment object.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
CComApartment* m_pApartments;
Points to an array of CComApartment objects, each of which manages an apartment in the module. The number of elements in the array is based on the m_nThreads member.
As of ATL 7.0, CComAutoThreadModule
is obsolete: see ATL Module Classes for more details.
LONG Unlock();
A value that may be useful for diagnostics or testing.
Performs an atomic decrement on the lock count for the module and for the current thread. CComAutoThreadModule
uses the module lock count to determine whether any clients are accessing the module. The lock count on the current thread is used for statistical purposes.
When the module lock count reaches zero, the module can be unloaded.