?? taskallocator.cpp
字號:
/* TaskAllocator.cpp - COM/DCOM TaskAllocator class implementation *//*modification history--------------------01r,17dec01,nel Add include symbol for diab.01q,23oct01,nel SPR#71142. Add call to comSysRealloc to Realloc method.01p,13jul01,dbs remove NEW macro usage01o,27jun01,dbs fix include paths and names01n,19aug99,aim TASK_LOCK now uses mutex01m,19aug99,aim added TraceCall header01l,05aug99,aim added mutex01k,16jul99,aim undef Free if defined01j,17jun99,dbs use NEW not new01i,17jun99,aim added standard OPERATOR_NEW_AND_DELETE01h,02jun99,dbs use new OS-specific macros01g,28may99,dbs simplify allocator strategy01f,27may99,dbs change to vxdcomTarget.h01e,05may99,dbs fix TASK_LOCK macros under Win32, trim old code out01d,29apr99,dbs fix warnings under -Wall01c,29apr99,dbs use main COM allocator01b,26apr99,aim added TRACE_CALL01a,20apr99,dbs created during Grand Renaming*//* DESCRIPTION: TaskAllocator -- */#include "TaskAllocator.h"#include "private/comMisc.h"#include "private/comSysLib.h"#include "TraceCall.h"/* Include symbol for diab */extern "C" int include_vxcom_TaskAllocator (void) { return 0; }//////////////////////////////////////////////////////////////////////////////// Global Variables -- the pointer 'pSysAllocator' points to the// IMalloc interface of the current system allocator. In future, there// may be one per application (one per PD, for example), but right now// there can only be one ;-)//////////////////////////////////////////////////////////////////////////////IMalloc* pSysAllocator = 0;static VxMutex coGetMallocLock;//////////////////////////////////////////////////////////////////////////////VxTaskAllocator::VxTaskAllocator () : m_dwRefCount (0), m_mutex () { TRACE_CALL; }//////////////////////////////////////////////////////////////////////////////VxTaskAllocator::~VxTaskAllocator () { TRACE_CALL; }//////////////////////////////////////////////////////////////////////////////ULONG VxTaskAllocator::AddRef () { TRACE_CALL; VxCritSec cs (m_mutex); return ++m_dwRefCount; }//////////////////////////////////////////////////////////////////////////////ULONG VxTaskAllocator::Release () { TRACE_CALL; VxCritSec cs (m_mutex); if (--m_dwRefCount) return m_dwRefCount; delete this; return 0; }//////////////////////////////////////////////////////////////////////////////HRESULT VxTaskAllocator::QueryInterface ( REFIID riid, void** ppv ) { TRACE_CALL; // Is it one of our own interfaces? if ((riid == IID_IUnknown) || (riid == IID_IMalloc)) { *ppv = this; AddRef (); return S_OK; } return E_NOINTERFACE; }//////////////////////////////////////////////////////////////////////////////void* VxTaskAllocator::Alloc (ULONG cb) { TRACE_CALL; return comSysAlloc (cb); }//////////////////////////////////////////////////////////////////////////////void* VxTaskAllocator::Realloc (void *pv, ULONG cb) { TRACE_CALL; return comSysRealloc (pv, cb); }//////////////////////////////////////////////////////////////////////////////// resolve clashes in networking headers#ifdef Free#undef Free#endifvoid VxTaskAllocator::Free (void *pv) { TRACE_CALL; comSysFree (pv); }//////////////////////////////////////////////////////////////////////////////ULONG VxTaskAllocator::GetSize (void *pv) { TRACE_CALL; return (ULONG) -1; }//////////////////////////////////////////////////////////////////////////////int VxTaskAllocator::DidAlloc (void *pv) { TRACE_CALL; return -1; }//////////////////////////////////////////////////////////////////////////////void VxTaskAllocator::HeapMinimize () { TRACE_CALL; }//////////////////////////////////////////////////////////////////////////////// comCoGetMalloc - gets a pointer to the task-allocator for the current// task, which is always the system allocator. If there is already one// then it simply adds a reference for it, if not then it creates one// afresh...//HRESULT comCoGetMalloc ( DWORD dwMemContext, // MUST BE 1 IMalloc** ppMalloc // output ptr ) { TRACE_CALL; HRESULT hr = S_OK; VxCritSec cs (coGetMallocLock); // Make sure context is valid if (dwMemContext != 1) return E_INVALIDARG; // Check for existing allocator... if (! pSysAllocator) { // Must create a new one, always keep one extra ref (from QI) // so it never gets destroyed... VxTaskAllocator* pa = new VxTaskAllocator (); if (pa) hr = pa->QueryInterface (IID_IMalloc, (void**) &pSysAllocator); else hr = E_OUTOFMEMORY; } // Hand out a reference to the existing allocator... if (SUCCEEDED (hr)) { pSysAllocator->AddRef (); *ppMalloc = pSysAllocator; } return hr; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -