summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/Threads.cc
blob: b0c762641190f580c502943b61a4cd3a7e8fe23d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "tools/rbd_mirror/Threads.h"
#include "common/Timer.h"
#include "librbd/AsioEngine.h"
#include "librbd/ImageCtx.h"
#include "librbd/asio/ContextWQ.h"

namespace rbd {
namespace mirror {

template <typename I>
Threads<I>::Threads(std::shared_ptr<librados::Rados>& rados) {
  auto cct = static_cast<CephContext*>(rados->cct());
  asio_engine = new librbd::AsioEngine(rados);
  work_queue = asio_engine->get_work_queue();

  timer = new SafeTimer(cct, timer_lock, true);
  timer->init();
}

template <typename I>
Threads<I>::~Threads() {
  {
    std::lock_guard timer_locker{timer_lock};
    timer->shutdown();
  }
  delete timer;

  work_queue->drain();
  delete asio_engine;
}

} // namespace mirror
} // namespace rbd

template class rbd::mirror::Threads<librbd::ImageCtx>;