Beispiel #1
0
void* JobPoolWorker::Entry()
{
#ifdef LINUX
    XInitThreads();
#endif
    while ( true ) {
        // Did we get a request to terminate?
        if (TestDestroy())
            break;

        Job *job = GetJob();
        if (job) {
            // Call user's implementation for processing request
            ProcessJob(job);
            delete job;
            job = NULL;
        } else {
            wxMutexLocker mutLock(*lock);
            if (idleThreads > 5) {
                break;
            }
        }
    }
    wxMutexLocker mutLock(*lock);
    numThreads--;
    return NULL;
}
Beispiel #2
0
void* JobPoolWorker::Entry()
{
#ifdef LINUX
    XInitThreads();
#endif
    while ( !stopped ) {
        // Did we get a request to terminate?
        if (TestDestroy())
            break;

        Job *job = GetJob();
        if (job) {
            // Call user's implementation for processing request
            ProcessJob(job);
            if (job->DeleteWhenComplete()) {
                delete job;
            }
            job = NULL;
        } else {
            std::unique_lock<std::mutex> mutLock(*lock);
            if (idleThreads > 5) {
                break;
            }
        }
    }
    std::unique_lock<std::mutex> mutLock(*lock);
    numThreads--;
    return NULL;
}
Beispiel #3
0
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;
}
Beispiel #4
0
void JobPoolWorker::Stop()
{
    stopped = true;
    if ( IsAlive() ) {
        std::unique_lock<std::mutex> mutLock(*lock);
        signal->notify_all();
    }
    if ( IsAlive() ) {
        Delete();
    }

    while ( IsAlive() ) {
        wxThread::Sleep( 5 );
    }
}
Beispiel #5
0
Job *JobPoolWorker::GetJob()
{
    std::unique_lock<std::mutex> mutLock(*lock);
    Job *req(NULL);
    if (queue->empty()) {
        idleThreads++;
        signal->wait_for(mutLock, std::chrono::milliseconds(100));
        idleThreads--;
    }
    if ( !queue->empty() ) {
        req = queue->front();
        queue->pop_front();
    }
    return req;
}