_afxThreadState是一个全局变量,定义在afxstate.cpp中:
THREAD_LOCAL(_AFX_THREAD_STATE, _afxThreadState);
#define THREAD_LOCAL(class_name, ident_name)
AFX_COMDAT CThreadLocal<class_name> ident_name;
CThreadLocal是一个模板类,具体定义如下:
template<class TYPE>
class CThreadLocal : public CThreadLocalObject
{
// Attributes
public:
AFX_INLINE TYPE* GetData()
{
TYPE* pData = (TYPE*)CThreadLocalObject::GetData(&CreateObject);
ENSURE(pData != NULL);
return pData;
}
AFX_INLINE TYPE* GetDataNA()
{
TYPE* pData = (TYPE*)CThreadLocalObject::GetDataNA();
return pData;
}
AFX_INLINE operator TYPE*()
{
return GetData();
}
AFX_INLINE TYPE* operator->()
{
return GetData();
}
// Implementation
public:
static CNoTrackObject* AFXAPI CreateObject()
{ return new TYPE; }
};