コード例 #1
0
ファイル: threadpsx.cpp プロジェクト: czxxjtu/wxPython-1
wxSemaError wxSemaphoreInternal::WaitTimeout(unsigned long milliseconds)
{
    wxMutexLocker locker(m_mutex);

    wxLongLong startTime = wxGetLocalTimeMillis();

    while ( m_count == 0 )
    {
        wxLongLong elapsed = wxGetLocalTimeMillis() - startTime;
        long remainingTime = (long)milliseconds - (long)elapsed.GetLo();
        if ( remainingTime <= 0 )
        {
            // timeout
            return wxSEMA_TIMEOUT;
        }

        switch ( m_cond.WaitTimeout(remainingTime) )
        {
            case wxCOND_TIMEOUT:
                return wxSEMA_TIMEOUT;

            default:
                return wxSEMA_MISC_ERROR;

            case wxCOND_NO_ERROR:
                ;
        }
    }

    m_count--;

    return wxSEMA_NO_ERROR;
}
コード例 #2
0
void SearchThread::DeleteThread() {
    // We may be waiting for the condition so we cannot just call Delete
    m_stopSearch = true;
    CancelSearch();

    // Signal thread to stop waiting
    wxMutexLocker lock(m_condMutex);
    m_startSearchCond.Signal();
}
コード例 #3
0
void SearchThread::StartSearch(const wxString& path, const wxString& pattern, bool matchCase, bool regex) {
    m_path = path;
    m_pattern = pattern.c_str(); // wxString is not threadsafe, so we have to force copy
    m_matchCase = matchCase;
    m_regex = regex;
    m_lastError = false;

    // Signal thread that we should start search
    wxMutexLocker lock(m_condMutex);
    m_startSearchCond.Signal();
}
コード例 #4
0
ファイル: JobPool.cpp プロジェクト: rickcowan/xLights
Job *JobPoolWorker::GetJob()
{
    wxMutexLocker mutLock(*lock);
    Job *req(NULL);
    if (queue->empty()) {
        idleThreads++;
        signal->WaitTimeout(100);
        idleThreads--;
    }
    if ( !queue->empty() ) {
        req = queue->front();
        queue->pop_front();
    }
    return req;
}
コード例 #5
0
ファイル: threadpsx.cpp プロジェクト: czxxjtu/wxPython-1
wxSemaError wxSemaphoreInternal::Post()
{
    wxMutexLocker locker(m_mutex);

    if ( m_maxcount > 0 && m_count == m_maxcount )
    {
        return wxSEMA_OVERFLOW;
    }

    m_count++;

    wxLogTrace(TRACE_SEMA,
               _T("Thread %ld about to signal semaphore, count = %lu"),
               wxThread::GetCurrentId(), (unsigned long)m_count);

    return m_cond.Signal() == wxCOND_NO_ERROR ? wxSEMA_NO_ERROR
                                              : wxSEMA_MISC_ERROR;
}
コード例 #6
0
ファイル: threadpsx.cpp プロジェクト: czxxjtu/wxPython-1
wxSemaError wxSemaphoreInternal::Wait()
{
    wxMutexLocker locker(m_mutex);

    while ( m_count == 0 )
    {
        wxLogTrace(TRACE_SEMA,
                   _T("Thread %ld waiting for semaphore to become signalled"),
                   wxThread::GetCurrentId());

        if ( m_cond.Wait() != wxCOND_NO_ERROR )
            return wxSEMA_MISC_ERROR;

        wxLogTrace(TRACE_SEMA,
                   _T("Thread %ld finished waiting for semaphore, count = %lu"),
                   wxThread::GetCurrentId(), (unsigned long)m_count);
    }

    m_count--;

    return wxSEMA_NO_ERROR;
}
コード例 #7
0
void* SearchThread::Entry() {
    while (1) {
        // Wait for signal that we should start search
        m_isWaiting = true;
        wxMutexLocker lock(m_condMutex);
        m_startSearchCond.Wait();
        m_isWaiting = false;

        if (m_stopSearch) {
            while (1) {
                if (TestDestroy()) break;
                Sleep(100);
            }
        }

        SearchInfo si;
        if (!PrepareSearchInfo(si, m_pattern, m_matchCase, m_regex)) continue;

        m_isSearching = true;

        ProjectInfoHandler infoHandler;
        infoHandler.SetRoot(m_path);

        // Write the html header for output
        m_outputCrit.Enter();
        m_output = wxT("<head><style type=\"text/css\">#match {background-color: yellow}</style></head>");
        m_outputCrit.Leave();

        SearchDir(m_path, si, infoHandler);
        m_isSearching = false;

        // Clean up
        if (si.regex) free(si.regex);
    }

    return NULL;
}