]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/QueueStrategy.h
update sources to v12.1.1
[ceph.git] / ceph / src / msg / QueueStrategy.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 CohortFS, LLC
7 *
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.
12 *
13 */
14
15
16 #ifndef QUEUE_STRATEGY_H
17 #define QUEUE_STRATEGY_H
18
19 #include <vector>
20 #include <memory>
21 #include <boost/intrusive/list.hpp>
22 #include "DispatchStrategy.h"
23 #include "msg/Messenger.h"
24
25 namespace bi = boost::intrusive;
26
27 class QueueStrategy : public DispatchStrategy {
28 Mutex lock;
29 const int n_threads;
30 bool stop;
31
32 Message::Queue mqueue;
33
34 class QSThread : public Thread {
35 public:
36 bi::list_member_hook<> thread_q;
37 QueueStrategy *dq;
38 Cond cond;
39 explicit QSThread(QueueStrategy *dq) : thread_q(), dq(dq), cond() {}
40 void* entry() {
41 dq->entry(this);
42 return NULL;
43 }
44
45 typedef bi::list< QSThread,
46 bi::member_hook< QSThread,
47 bi::list_member_hook<>,
48 &QSThread::thread_q > > Queue;
49 };
50
51 std::vector<std::unique_ptr<QSThread>> threads; //< all threads
52 QSThread::Queue disp_threads; //< waiting threads
53
54 public:
55 explicit QueueStrategy(int n_threads);
56 void ds_dispatch(Message *m) override;
57 void shutdown() override;
58 void start() override;
59 void wait() override;
60 void entry(QSThread *thrd);
61 virtual ~QueueStrategy() {}
62 };
63 #endif /* QUEUE_STRATEGY_H */