src/wire/libevent_thread.cpp
void LibeventMasterThread::DispatchConnection(int new_conn_fd,
                                              short event_flags) {
  char buf[1];
  buf[0] = 'c';
  auto &threads = GetWorkerThreads();

  // Dispatch by rand number
  int thread_id = next_thread_id_;

  // update next threadID
  next_thread_id_ = (next_thread_id_ + 1) % num_threads_;

  std::shared_ptr<LibeventWorkerThread> worker_thread = threads[thread_id];
  LOG_DEBUG("Dispatching connection to worker %d", thread_id);

  std::shared_ptr<NewConnQueueItem> item(
      new NewConnQueueItem(new_conn_fd, event_flags, CONN_READ));
  worker_thread->new_conn_queue.Enqueue(item);

  if (write(worker_thread->new_conn_send_fd, buf, 1) != 1) {
    LOG_ERROR("Failed to write to thread notify pipe");
  }
}
/*
* Dispatch a new connection event to a random worker thread by
* writing to the worker's pipe
*/
Dispatch a new connection event to a random worker thread by
writing to the worker's pipe
Dispatch a new connection event to a random worker thread by writing to the worker ' s pipe
void LibeventMasterThread::DispatchConnection(int new_conn_fd,
                                              short event_flags) {
  char buf[1];
  buf[0] = 'c';
  auto &threads = GetWorkerThreads();
  int thread_id = next_thread_id_;
  next_thread_id_ = (next_thread_id_ + 1) % num_threads_;
  std::shared_ptr<LibeventWorkerThread> worker_thread = threads[thread_id];
  LOG_DEBUG("Dispatching connection to worker %d", thread_id);
  std::shared_ptr<NewConnQueueItem> item(
      new NewConnQueueItem(new_conn_fd, event_flags, CONN_READ));
  worker_thread->new_conn_queue.Enqueue(item);
  if (write(worker_thread->new_conn_send_fd, buf, 1) != 1) {
    LOG_ERROR("Failed to write to thread notify pipe");
  }
}
void LibeventMasterThread :: DispatchConnection ( int new_conn_fd , short event_flags ) { char buf [ 1 ] ; buf [ 0 ] = ' ' ; auto & threads = GetWorkerThreads ( ) ; int thread_id = next_thread_id_ ; next_thread_id_ = ( next_thread_id_ + 1 ) % num_threads_ ; std :: shared_ptr < LibeventWorkerThread > worker_thread = threads [ thread_id ] ; LOG_DEBUG ( " " , thread_id ) ; std :: shared_ptr < NewConnQueueItem > item ( new NewConnQueueItem ( new_conn_fd , event_flags , CONN_READ ) ) ; worker_thread -> new_conn_queue . Enqueue ( item ) ; if ( write ( worker_thread -> new_conn_send_fd , buf , 1 ) != 1 ) { LOG_ERROR ( " " ) ; } }
Dispatch a new connection event to a random worker thread by
writing to the worker's pipe
Dispatch a new connection event to a random worker thread by writing to the worker ' s pipe
// Dispatch by rand number // update next threadID