1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 CohortFS, LLC
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "QueueStrategy.h"
16 #define dout_subsys ceph_subsys_ms
17 #include "common/debug.h"
18 #include "common/backport14.h"
20 QueueStrategy::QueueStrategy(int _n_threads)
21 : lock("QueueStrategy::lock"),
22 n_threads(_n_threads),
29 void QueueStrategy::ds_dispatch(Message *m) {
30 msgr->ms_fast_preprocess(m);
31 if (msgr->ms_can_fast_dispatch(m)) {
32 msgr->ms_fast_dispatch(m);
37 if (disp_threads.size()) {
38 if (! disp_threads.empty()) {
39 QSThread *thrd = &disp_threads.front();
40 disp_threads.pop_front();
47 void QueueStrategy::entry(QSThread *thrd)
53 if (! mqueue.empty()) {
54 m = &(mqueue.front());
61 disp_threads.push_front(*thrd);
62 thrd->cond.Wait(lock);
70 get_messenger()->ms_deliver_dispatch(m);
74 void QueueStrategy::shutdown()
79 while (disp_threads.size()) {
80 thrd = &(disp_threads.front());
81 disp_threads.pop_front();
87 void QueueStrategy::wait()
91 for (auto& thread : threads) {
94 // join outside of lock
102 void QueueStrategy::start()
106 threads.reserve(n_threads);
107 for (int ix = 0; ix < n_threads; ++ix) {
108 string thread_name = "ms_xio_qs_";
109 thread_name.append(std::to_string(ix));
110 auto thrd = ceph::make_unique<QSThread>(this);
111 thrd->create(thread_name.c_str());
112 threads.emplace_back(std::move(thrd));