Exemplo n.º 1
0
/*----------------------------------------------------------------------
|   NPT_Win32Thread::EntryPoint
+---------------------------------------------------------------------*/
unsigned int __stdcall
NPT_Win32Thread::EntryPoint(void* argument)
{
    NPT_Win32Thread* thread = reinterpret_cast<NPT_Win32Thread*>(argument);

    NPT_LOG_FINER("thread in =======================");

    // set random seed per thread
    NPT_TimeStamp now;
    NPT_System::GetCurrentTimeStamp(now);
    NPT_System::SetRandomSeed((NPT_UInt32)(now.ToNanos()) + ::GetCurrentThreadId());

    thread->m_ThreadId = (DWORD)::GetCurrentThreadId();

    // run the thread
    thread->Run();

    // if the thread is detached, delete it
    if (thread->m_Detached) {
        delete thread->m_Delegator;
    }

    // done
    return 0;
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------
|       NPT_PosixQueue::NPT_PosixQueue
+---------------------------------------------------------------------*/
NPT_PosixQueue::NPT_PosixQueue(NPT_Cardinal max_items) : 
    m_MaxItems(max_items)
{
    NPT_LOG_FINER("NPT_PosixQueue::NPT_PosixQueue");

    pthread_mutex_init(&m_Mutex, NULL);
    pthread_cond_init(&m_CanPushOrPopCondition, NULL);
}
Exemplo n.º 3
0
/*----------------------------------------------------------------------
|  main
+---------------------------------------------------------------------*/
int 
main(int, char**)
{
    NPT_LogManager::GetDefault().Configure("plist:.level=ALL;");
    NPT_LOG_L(MyLogger, NPT_LOG_LEVEL_WARNING, "blabla");
    NPT_LOG_L2(MyLogger, NPT_LOG_LEVEL_WARNING, "blabla %d %d", 8, 9);

    NPT_LOG(NPT_LOG_LEVEL_WARNING, "blibli");
    NPT_LOG_2(NPT_LOG_LEVEL_INFO, "fofo %d %d", 5, 7);

    NPT_LOG_SEVERE("this is severe!");
    NPT_LOG_SEVERE_1("this is severe (%d)", 9);

    NPT_LOG_SEVERE_L(MyLogger, "this is severe!");
    NPT_LOG_SEVERE_L1(MyLogger, "this is severe (%d)", 9);

    NPT_LOG_SEVERE_L(FooLogger, "this is severe!");
    NPT_LOG_SEVERE_L1(FooLogger, "this is severe (%d)", 9);

    NPT_LOG_SEVERE("severe");
    NPT_LOG_WARNING("warning");
    NPT_LOG_INFO("info");
    NPT_LOG_FINE("fine");
    NPT_LOG_FINER("finer");
    NPT_LOG_FINEST("finest");

    NPT_LOG_SEVERE_L(FooLogger, "severe");
    NPT_LOG_WARNING_L(FooLogger, "warning");
    NPT_LOG_INFO_L(FooLogger, "info");
    NPT_LOG_FINE_L(FooLogger, "fine");
    NPT_LOG_FINER_L(FooLogger, "finer");
    NPT_LOG_FINEST_L(FooLogger, "finest");

    TestLargeBuffer();

    TestCheck();
    TestCheckSevere();
    TestCheckWarning();
    TestCheckInfo();
    TestCheckFine();
    TestCheckFiner();
    TestCheckFinest();

    TestCheckL();
    TestCheckSevereL();
    TestCheckWarningL();
    TestCheckInfoL();
    TestCheckFineL();
    TestCheckFinerL();
    TestCheckFinestL();

    return 0;
}
Exemplo n.º 4
0
/*----------------------------------------------------------------------
|   NPT_Win32Thread::Start
+---------------------------------------------------------------------*/
NPT_Result
NPT_Win32Thread::Start()
{
    if (m_ThreadHandle > 0) {
        // failed
        NPT_LOG_WARNING("thread already started !");
        return NPT_ERROR_INVALID_STATE;
    }

    NPT_LOG_FINER("creating thread");

    // create the native thread
#if defined(_WIN32_WCE)
    DWORD thread_id;
#else
    unsigned int thread_id;
#endif
    // create a stack local variable 'detached', as this object
    // may already be deleted when _beginthreadex returns and
    // before we get to call detach on the given thread
    bool detached = m_Detached;

    HANDLE thread_handle = (HANDLE)
        _beginthreadex(NULL,
                       NPT_CONFIG_THREAD_STACK_SIZE,
                       EntryPoint,
                       reinterpret_cast<void*>(this),
                       0,
                       &thread_id);
    if (thread_handle == 0) {
        // failed
        return NPT_FAILURE;
    }

    if (detached) {
        CloseHandle(thread_handle);
    } else {
        m_ThreadHandle = thread_handle;
    }

    m_ThreadId = (DWORD)thread_id;

    return NPT_SUCCESS;
}