Esempio n. 1
0
Message::Ptr Task::WaitTaskDone() {
  uint32 msEnd = TimeAfter(timeout_);
  int cmsNext = timeout_;
  Message::Ptr msg(new Message());
  while(1) {
#if __has_feature(objc_arc)
    @autoreleasepool
#elif defined(OSX) || defined(IOS)
    // see: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html
    // Each thread is supposed to have an autorelease pool. Also for event loops
    // like this, autorelease pool needs to be created and drained/released
    // for each cycle.
    ScopedAutoreleasePool pool;
#endif
    task_thread_->Get(msg.get(), cmsNext);
    if(msg->phandler == NULL) {
      // msg.reset(NULL);
    } else if(msg->phandler != NULL && msg->message_id == task_id_) {
      break;
    } else {
      // Unhandle Error
      LOG(LS_ERROR) << "Unhandle Message";
      ASSERT(false);
      // current_thread->Dispatch(msg.get());
    }
    cmsNext = TimeUntil(msEnd);
    if (cmsNext < 0)
      break;
  }
  return msg;
}
Esempio n. 2
0
int MessageQueue::GetDelay() {
  CritScope cs(&crit_);

  if (!msgq_.empty())
    return 0;

  if (!dmsgq_.empty()) {
    int delay = TimeUntil(dmsgq_.top().msTrigger_);
    if (delay < 0)
      delay = 0;
    return delay;
  }

  return kForever;
}