예제 #1
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
void EventBase::cancelTimeout(AsyncTimeout* obj) {
  assert(isInEventBaseThread());
  struct event* ev = obj->getEvent();
  if (EventUtil::isEventRegistered(ev)) {
    event_del(ev);
  }
}
예제 #2
0
void EventBase::setName(const std::string& name) {
  assert(isInEventBaseThread());
  name_ = name;

  if (isRunning()) {
    setThreadName(loopThread_.load(std::memory_order_relaxed),
                  name_);
  }
}
예제 #3
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
void EventBase::setName(const std::string& name) {
  assert(isInEventBaseThread());
  name_ = name;
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)
  if (isRunning()) {
    pthread_setname_np(loopThread_.load(std::memory_order_relaxed),
                       name_.c_str());
  }
#endif
}
예제 #4
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
void EventBase::runInLoop(const Cob& cob, bool thisIteration) {
  DCHECK(isInEventBaseThread());
  Tr1FunctionLoopCallback* wrapper = new Tr1FunctionLoopCallback(cob);
  wrapper->context_ = RequestContext::saveContext();
  if (runOnceCallbacks_ != nullptr && thisIteration) {
    runOnceCallbacks_->push_back(*wrapper);
  } else {
    loopCallbacks_.push_back(*wrapper);
  }
}
예제 #5
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
void EventBase::runInLoop(LoopCallback* callback, bool thisIteration) {
  DCHECK(isInEventBaseThread());
  callback->cancelLoopCallback();
  callback->context_ = RequestContext::saveContext();
  if (runOnceCallbacks_ != nullptr && thisIteration) {
    runOnceCallbacks_->push_back(*callback);
  } else {
    loopCallbacks_.push_back(*callback);
  }
}
예제 #6
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
bool EventBase::scheduleTimeout(AsyncTimeout* obj,
                                 std::chrono::milliseconds timeout) {
  assert(isInEventBaseThread());
  // Set up the timeval and add the event
  struct timeval tv;
  tv.tv_sec = timeout.count() / 1000LL;
  tv.tv_usec = (timeout.count() % 1000LL) * 1000LL;

  struct event* ev = obj->getEvent();
  if (event_add(ev, &tv) < 0) {
    LOG(ERROR) << "EventBase: failed to schedule timeout: " << strerror(errno);
    return false;
  }

  return true;
}
예제 #7
0
파일: EventBase.cpp 프로젝트: Ninlgde/folly
const std::string& EventBase::getName() {
  assert(isInEventBaseThread());
  return name_;
}
예제 #8
0
파일: EventBase.cpp 프로젝트: smintz/folly
void EventBase::runBeforeLoop(LoopCallback* callback) {
    DCHECK(isInEventBaseThread());
    callback->cancelLoopCallback();
    runBeforeLoopCallbacks_.push_back(*callback);
}
예제 #9
0
void EventBase::runOnDestruction(LoopCallback* callback) {
  DCHECK(isInEventBaseThread());
  callback->cancelLoopCallback();
  onDestructionCallbacks_.push_back(*callback);
}
예제 #10
0
void RequestChannel::sendRequestAsync(
    apache::thrift::RpcOptions& rpcOptions,
    std::unique_ptr<apache::thrift::RequestCallback> callback,
    std::unique_ptr<apache::thrift::ContextStack> ctx,
    std::unique_ptr<folly::IOBuf> buf,
    std::shared_ptr<apache::thrift::transport::THeader> header,
    RpcKind kind) {
  auto eb = getEventBase();
  if (!eb || eb->isInEventBaseThread()) {
    switch (kind) {
      case RpcKind::SINGLE_REQUEST_NO_RESPONSE:
        // Calling asyncComplete before sending because
        // sendOnewayRequest moves from ctx and clears it.
        ctx->asyncComplete();
        sendOnewayRequest(
            rpcOptions,
            std::move(callback),
            std::move(ctx),
            std::move(buf),
            std::move(header));
        break;
      case RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE:
        sendRequest(
            rpcOptions,
            std::move(callback),
            std::move(ctx),
            std::move(buf),
            std::move(header));
        break;
      case RpcKind::SINGLE_REQUEST_STREAMING_RESPONSE:
        sendStreamRequest(
            rpcOptions,
            std::move(callback),
            std::move(ctx),
            std::move(buf),
            std::move(header));
        break;
      default:
        folly::assume_unreachable();
        break;
    }

  } else {
    switch (kind) {
      case RpcKind::SINGLE_REQUEST_NO_RESPONSE:
        eb->runInEventBaseThread([this,
                                  rpcOptions,
                                  callback = std::move(callback),
                                  ctx = std::move(ctx),
                                  buf = std::move(buf),
                                  header = std::move(header)]() mutable {
          // Calling asyncComplete before sending because
          // sendOnewayRequest moves from ctx and clears it.
          ctx->asyncComplete();
          sendOnewayRequest(
              rpcOptions,
              std::move(callback),
              std::move(ctx),
              std::move(buf),
              std::move(header));
        });
        break;
      case RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE:
        eb->runInEventBaseThread([this,
                                  rpcOptions,
                                  callback = std::move(callback),
                                  ctx = std::move(ctx),
                                  buf = std::move(buf),
                                  header = std::move(header)]() mutable {
          sendRequest(
              rpcOptions,
              std::move(callback),
              std::move(ctx),
              std::move(buf),
              std::move(header));
        });
        break;
      case RpcKind::SINGLE_REQUEST_STREAMING_RESPONSE:
        eb->runInEventBaseThread([this,
                                  rpcOptions,
                                  callback = std::move(callback),
                                  ctx = std::move(ctx),
                                  buf = std::move(buf),
                                  header = std::move(header)]() mutable {
          sendStreamRequest(
              rpcOptions,
              std::move(callback),
              std::move(ctx),
              std::move(buf),
              std::move(header));
        });
        break;
      default:
        folly::assume_unreachable();
        break;
    }
  }
}