Example #1
0
 virtual ~CObjectWithNew() {
     if ( m_Counter != eCounter_heap && m_Counter != eCounter_static ) {
         error("invalid CObjectWithNew::delete");
     }
     object_count.Add(-1);
     m_Counter = eCounter_deleted;
 }
Example #2
0
inline void add_step()
{
    CAtomicCounter::TValue c = current_step.Add(1);
    if ( c % 1000000 == 0 ) {
        LOG_POST("step "<<c<<" of "<<total_steps);
    }
}
Example #3
0
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;
}
Example #4
0
 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);
 }
Example #5
0
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);
}
Example #6
0
int CSafeStaticPtr_Base::x_GetCreationOrder(void)
{
    static CAtomicCounter s_CreationOrder;
    return int(s_CreationOrder.Add(1));
}
Example #7
0
CRequestContext::TCount CRequestContext::GetNextRequestID(void)
{
    static CAtomicCounter s_RequestCount;
    return s_RequestCount.Add(1);
}
Example #8
0
 virtual ~CObjectWithRef() {
     object_count.Add(-1);
 }
Example #9
0
 CObjectWithRef(int = 0) {
     object_count.Add(1);
 }
Example #10
0
 CObjectWithNew(void) {
     m_Counter = IsNewInHeap(this)? eCounter_heap: eCounter_static;
     _ASSERT(s_CurrentInHeap == IsInHeap());
     object_count.Add(1);
 }
Example #11
0
inline void add_alloc(int d)
{
    alloc_count.Add(d);
}
Example #12
0
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;
}