Ejemplo n.º 1
0
 void run()
 {
     unsigned s;
     unsigned n;
     if (waitForWork(s,n))
         subsort(s,n);
 }
Ejemplo n.º 2
0
void MessagePumpUI::doRunLoop() {
  // IF this was just a simple PeekMessage() loop (servicing all possible work queues), then Windows would try to
  // achieve the following order according to MSDN documentation about PeekMessage with no filter):
  //
  //   - Sent messages
  //   - Posted messages
  //   - Sent messages (again)
  //   - WM_PAINT messages
  //   - WM_TIMER messages
  //
  // Summary: none of the above classes is starved, and sent messages has twice the chance of being processed (i.e.,
  // reduced service time).

  for (;;) {
    // If we do any work, we may create more messages etc., and more work may possibly be waiting in another task group.
    // When we (for example) processNextWindowsMessage(), there is a good chance there are still more messages waiting.
    // On the other hand, when any of these methods return having done no work, then it is pretty unlikely that calling
    // them again quickly will find any work to do.  Finally, if they all say they had no work, then it is a good time
    // to consider sleeping (waiting) for more work.

    bool moreWorkIsPlausible = processNextWindowsMessage();
    if (m_runState->shouldQuit) {
      break;
    }

    moreWorkIsPlausible |= m_runState->delegate->doWork();
    if (m_runState->shouldQuit) {
      break;
    }

    moreWorkIsPlausible |= m_runState->delegate->doDelayedWork(&delayed_work_time_);
    // If we did not process any delayed work, then we can assume that our
    // existing WM_TIMER if any will fire when delayed work should run.  We
    // don't want to disturb that timer if it is already in flight.  However,
    // if we did do all remaining delayed work, then lets kill the WM_TIMER.
    if (moreWorkIsPlausible && delayed_work_time_.is_null())
      KillTimer(m_messageWindow.getHandle(), reinterpret_cast<UINT_PTR>(this));
    if (m_runState->shouldQuit)
      break;

    if (moreWorkIsPlausible)
      continue;

    moreWorkIsPlausible = m_runState->delegate->doIdleWork();
    if (m_runState->shouldQuit)
      break;

    if (moreWorkIsPlausible)
      continue;

    // Wait (sleep) until we have work to do again.
    waitForWork();
  }
}
Ejemplo n.º 3
0
void KisTileDataSwapper::run()
{
    while (1) {
        waitForWork();

        if (m_d->shouldExitFlag.load())
            return;

        QThread::msleep(DELAY);

        doJob();
    }
}
Ejemplo n.º 4
0
void Client::Connection::recvStart() {
    Log::write(INFO, "Connection receiver thread started. <thread id : %ld>, <pid : %d> \n",
               (long int)syscall(SYS_gettid), getpid());

    while(waitForWork()) {

        Log::write(DEBUG, "Got calls in Connection\n");

        recvRespond();
    }

    close();

    Log::write(INFO, "Connection receiver thread exits.\n");
}
Ejemplo n.º 5
0
 void subsort(unsigned s, unsigned n)
 {
     do {
         sJobItem *qi;
         while (n>PARALLEL_GRANULARITY) {
             unsigned r1;
             unsigned r2;
             partition(s, n, r1, r2);
             unsigned n2 = n+s-r2;
             if (r1==s) {
                 n = n2;
                 s = r2;
             }
             else {
                 if (n2!=0) {
                     qi = new sJobItem;
                     qi->num = n2;
                     qi->start = r2;
                     NonReentrantSpinBlock block(joblock);
                     jobq.enqueue(qi);
                     if (waiting) {
                         jobqsem.signal(waiting);
                         waiting = 0;
                     }
                 }
                 n = r1-s;
             }
         }
         serialsort(s,n);
         NonReentrantSpinBlock block(joblock);
         if (waiting==numsubthreads) { // well we are done so are rest
             done = true;
             jobqsem.signal(waiting);
             break;
         }
     }
     while(waitForWork(s,n));
 }
err_t X11UIEventLoopImpl::runInternal()
{
  int work = 0;

  // Sync with server before we get into the event loop.
  doXSync();

  for (;;)
  {
    bool didWork = false;
    bool more;

    // Process 'XEvent's - Highest priority.
    do {
      more = processNextXEvent();
      didWork |= more;

      if (_quitting)
        goto _End;
    } while (more);

    // doWork.
    didWork |= doWork();

    if (_quitting)
      goto _End;

    if (didWork && work < _workPerLoop)
      continue;

    work++;

    // doDelayedWork.
    didWork |= doDelayedWork(&_delayedWorkTime);
    if (_quitting)
      goto _End;

    if (didWork && work < _workPerLoop)
      continue;

    // doIdleWork.
    //
    // If quit is received in nestedLoop or through runAllPending(), we will
    // quit here, because we don't want to doXSync().
    didWork |= doIdleWork();

    if (_quitting)
      goto _End;

    // Call doXSync(), this is round-trip operation and can generate events.
    didWork |= doXSync();

    if (_quitting)
      goto _End;

    // Clear work status, this is why it's here...
    if (didWork || work < _workPerLoop)
      continue;
    work = 0;

    // Finally wait.
    waitForWork();
  }

_End:
  return ERR_OK;
}