// Init //------------------------------------------------------------------------------ /*static*/ void MemTracker::Init() { static_assert( sizeof( MemTracker::s_Mutex ) == sizeof( Mutex ), "Unexpected sizeof(Mutex)" ); ASSERT( g_MemTrackerDisabledOnThisThread ); // first caller does init static uint32_t threadSafeGuard( 0 ); if ( AtomicIncU32( &threadSafeGuard ) != 1 ) { // subsequent callers wait for init while ( !s_Initialized ) {} return; } // construct primary mutex in-place INPLACE_NEW ( &GetMutex() ) Mutex; // init hash table s_AllocationHashTable = new Allocation*[ ALLOCATION_HASH_SIZE ]; memset( s_AllocationHashTable, 0, ALLOCATION_HASH_SIZE * sizeof( Allocation * ) ); // init pool for allocation structures s_Allocations = new MemPoolBlock( sizeof( Allocation ), __alignof( Allocation ) ); MemoryBarrier(); s_Initialized = true; }
// CONSTRUCTOR //------------------------------------------------------------------------------ Job::Job( Node * node ) : m_Node( node ) , m_Data( nullptr ) , m_DataSize( 0 ) , m_UserData( nullptr ) , m_DataIsCompressed( false ) , m_IsLocal( true ) , m_SystemErrorCount( 0 ) , m_ToolManifest( nullptr ) { m_JobId = AtomicIncU32( &s_LastJobId ); }
// GetJobToProcess (Worker Thread) //------------------------------------------------------------------------------ Job * JobQueue::GetJobToProcess() { for ( size_t i=0; i<Node::NUM_PRIORITY_LEVELS; ++i ) { Job * job = m_LocalAvailableJobs[ i ].RemoveJob(); if ( job ) { AtomicIncU32( &m_NumLocalJobsActive ); return job; } } return nullptr; }