virtual ~CObjectWithNew() { if ( m_Counter != eCounter_heap && m_Counter != eCounter_static ) { error("invalid CObjectWithNew::delete"); } object_count.Add(-1); m_Counter = eCounter_deleted; }
bool CTestTlsObjectApp::Thread_Run(int /*idx*/) { try { RunTest(); RunTest(); RunTest(); return true; } NCBI_CATCH_ALL("Test failed"); size_t total, resident, shared; if ( GetMemoryUsage(&total, &resident, &shared) ) { ERR_POST("Alloc: "<<alloc_count.Get()<<" "<<object_count.Get()<<'\n'<< "Memory: "<<total<<" "<<resident<<" "<<shared); } return false; }
inline void add_step() { CAtomicCounter::TValue c = current_step.Add(1); if ( c % 1000000 == 0 ) { LOG_POST("step "<<c<<" of "<<total_steps); } }
inline void add_operation(int type, int size, void* ptr) { size_t index = operation_count.Add(1)-1; _ASSERT(index < kMaxOperationCount); operations[index].type = type; operations[index].size = size; operations[index].ptr = ptr; }
void check_cnts(size_t expected = 0, size_t expected_static = 0) { if ( expected == ~0u ) { expected = 0; } else { expected = 1; } if ( expected == 0 ) { if ( alloc_count.Get() != expected-expected_static ) ERR_FATAL("alloc_count: "<<alloc_count.Get()); if ( object_count.Get() != expected ) ERR_FATAL("object_count: "<<object_count.Get()); } _VERIFY(!sx_HaveLastNewPtr()); }
CObjectWithTLS(EObjectPlace place = eUnknown) { if ( s_CurrentInHeap ) { if ( rand() % 10 == 0 ) { throw runtime_error("CObjectWithTLS"); } } m_Counter = IsNewInHeap(this)? eCounter_heap: eCounter_static; _ASSERT(IsPlaceHeap(place) == IsInHeap()); object_count.Add(1); }
void message(const char* msg, const char* msg1, double t1, const char* msg2, double t2, size_t COUNT) { if ( 0 ) { LOG_POST(msg <<'\n'<<setw(40) << msg1 << ": "<< t1 * 1e9/(double)COUNT << " usec" <<'\n'<<setw(40) << msg2 << ": "<< t2 * 1e9/(double)COUNT << " usec"); } size_t total, resident, shared; if ( GetMemoryUsage(&total, &resident, &shared) ) { max_total = max(max_total, total); max_resident = max(max_resident, resident); max_shared = max(max_shared, shared); if ( 0 ) { LOG_POST("Alloc: "<<alloc_count.Get()<< " "<<object_count.Get()<<'\n'<< "Current memory: "<<total<<" "<<resident<<" "<<shared); } } }
void CRequestContext::x_UpdateSubHitID(bool increment) { static CAtomicCounter s_DefaultSubHitCounter; _ASSERT(IsSetHitID()); // Use global sub-hit counter for default hit id to prevent // duplicate phids in different threads. m_SubHitIDCache = GetHitID(); unsigned int sub_hit_id; if (m_SubHitIDCache == GetDiagContext().GetDefaultHitID()) { sub_hit_id = (unsigned int)(increment ? s_DefaultSubHitCounter.Add(1) : s_DefaultSubHitCounter.Get()); } else { if ( increment ) ++m_SubHitID; sub_hit_id = m_SubHitID; } // Cache the string so that C code can use it. m_SubHitIDCache += "." + NStr::NumericToString(sub_hit_id); }
void check_operations() { _ASSERT(current_step.Get() == total_steps); typedef map<void*, size_t> TAllocated; TAllocated allocated; size_t count = operation_count.Get(); for ( size_t i = 0; i < count; ++i ) { const SOperation& op = operations[i]; _ASSERT(op.type != 0); void* ptr = op.ptr; if ( op.type > 0 ) { void* end = (char*)ptr + op.size; TAllocated::iterator it1 = allocated.lower_bound(ptr); TAllocated::iterator it2 = allocated.lower_bound(end); _ASSERT(it1 == it2); allocated[ptr] = op.size; } else { _ASSERT(allocated.find(ptr) != allocated.end()); allocated.erase(ptr); } } _ASSERT(allocated.empty()); }
int CSafeStaticPtr_Base::x_GetCreationOrder(void) { static CAtomicCounter s_CreationOrder; return int(s_CreationOrder.Add(1)); }
CRequestContext::TCount CRequestContext::GetNextRequestID(void) { static CAtomicCounter s_RequestCount; return s_RequestCount.Add(1); }
virtual ~CObjectWithRef() { object_count.Add(-1); }
CObjectWithRef(int = 0) { object_count.Add(1); }
CObjectWithNew(void) { m_Counter = IsNewInHeap(this)? eCounter_heap: eCounter_static; _ASSERT(s_CurrentInHeap == IsInHeap()); object_count.Add(1); }
inline void add_alloc(int d) { alloc_count.Add(d); }
bool CThreadPoolTester::Thread_Run(int idx) { bool status = true; try { for (int i = 0; i < kTasksPerThread; ++i) { int serial_num = s_SerialNum.Add(1); double need_time = double(s_PostTimes[serial_num]) / 1000; double now_time = s_Timer.Elapsed(); if (now_time < need_time) { SleepMicroSec(int((need_time - now_time) * 1000000)); } int req_num = s_ActionTasks[serial_num]; switch (s_Actions[serial_num]) { case eAddTask: MSG_POST("Task " << req_num << " to be queued"); s_Pool->AddTask(new CTestTask(req_num)); MSG_POST("Task " << req_num << " queued"); break; case eAddExclusiveTask: MSG_POST("Task " << req_num << " to be queued"); s_Pool->RequestExclusiveExecution(new CExclusiveTask(req_num), CThreadPool::fFlushThreads + CThreadPool::fCancelExecutingTasks + CThreadPool::fCancelQueuedTasks); MSG_POST("Task " << req_num << " queued"); break; case eCancelTask: while (!s_Tasks[req_num]) { SleepMilliSec(10); } MSG_POST("Task " << req_num << " to be cancelled"); s_Pool->CancelTask(s_Tasks[req_num]); MSG_POST("Cancelation of task " << req_num << " requested"); break; case eFlushWaiting: case eFlushNoWait: MSG_POST("Flushing threads with " << (s_Actions[serial_num] == eFlushWaiting? "waiting": "immediate restart")); s_Pool->FlushThreads( s_Actions[serial_num] == eFlushWaiting? CThreadPool::eWaitToFinish: CThreadPool::eStartImmediately); MSG_POST("Flushing process began"); break; case eCancelAll: MSG_POST("Cancelling all tasks"); s_Pool->CancelTasks(CThreadPool::fCancelExecutingTasks + CThreadPool::fCancelQueuedTasks); MSG_POST("Cancellation of all tasks requested"); break; } } } STD_CATCH_ALL("CThreadPoolTester: status " << (status = false)) return status; }