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.
16 #ifndef QUEUE_STRATEGY_H
17 #define QUEUE_STRATEGY_H
21 #include <boost/intrusive/list.hpp>
22 #include "DispatchStrategy.h"
23 #include "msg/Messenger.h"
25 namespace bi = boost::intrusive;
27 class QueueStrategy : public DispatchStrategy {
32 Message::Queue mqueue;
34 class QSThread : public Thread {
36 bi::list_member_hook<> thread_q;
39 explicit QSThread(QueueStrategy *dq) : thread_q(), dq(dq), cond() {}
45 typedef bi::list< QSThread,
46 bi::member_hook< QSThread,
47 bi::list_member_hook<>,
48 &QSThread::thread_q > > Queue;
51 std::vector<std::unique_ptr<QSThread>> threads; //< all threads
52 QSThread::Queue disp_threads; //< waiting threads
55 explicit QueueStrategy(int n_threads);
56 void ds_dispatch(Message *m) override;
57 void shutdown() override;
58 void start() override;
60 void entry(QSThread *thrd);
61 virtual ~QueueStrategy() {}
63 #endif /* QUEUE_STRATEGY_H */