]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 <boost/intrusive/list.hpp> | |
20 | #include "DispatchStrategy.h" | |
21 | #include "msg/Messenger.h" | |
22 | ||
23 | namespace bi = boost::intrusive; | |
24 | ||
25 | class QueueStrategy : public DispatchStrategy { | |
26 | Mutex lock; | |
27 | int n_threads; | |
28 | bool stop; | |
29 | ||
30 | Message::Queue mqueue; | |
31 | ||
32 | class QSThread : public Thread { | |
33 | public: | |
34 | bi::list_member_hook<> thread_q; | |
35 | QueueStrategy *dq; | |
36 | Cond cond; | |
37 | explicit QSThread(QueueStrategy *dq) : thread_q(), dq(dq), cond() {} | |
38 | void* entry() { | |
39 | dq->entry(this); | |
40 | delete(this); | |
41 | return NULL; | |
42 | } | |
43 | ||
44 | typedef bi::list< QSThread, | |
45 | bi::member_hook< QSThread, | |
46 | bi::list_member_hook<>, | |
47 | &QSThread::thread_q > > Queue; | |
48 | }; | |
49 | ||
50 | QSThread::Queue disp_threads; | |
51 | ||
52 | public: | |
53 | explicit QueueStrategy(int n_threads); | |
54 | void ds_dispatch(Message *m) override; | |
55 | void shutdown() override; | |
56 | void start() override; | |
57 | void wait() override; | |
58 | void entry(QSThread *thrd); | |
59 | virtual ~QueueStrategy() {} | |
60 | }; | |
61 | #endif /* QUEUE_STRATEGY_H */ |