YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rpc/poller.h
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_RPC_POLLER_H
15
#define YB_RPC_POLLER_H
16
17
#include <condition_variable>
18
19
#include "yb/gutil/thread_annotations.h"
20
21
#include "yb/rpc/rpc_fwd.h"
22
23
#include "yb/util/status_fwd.h"
24
#include "yb/util/monotime.h"
25
26
namespace yb {
27
namespace rpc {
28
29
// Utility class to invoke specified callback with defined interval using scheduler.
30
// TODO Add separate test for poller.
31
class Poller {
32
 public:
33
  explicit Poller(const std::string& log_prefix, std::function<void()> callback);
34
35
  explicit Poller(std::function<void()> callback)
36
14.1k
      : Poller(/* log_prefix= */ std::string(), std::move(callback)) {}
Unexecuted instantiation: yb::rpc::Poller::Poller(std::__1::function<void ()>)
yb::rpc::Poller::Poller(std::__1::function<void ()>)
Line
Count
Source
36
14.1k
      : Poller(/* log_prefix= */ std::string(), std::move(callback)) {}
37
38
  Poller(Poller&&) = delete;
39
  void operator=(Poller&&) = delete;
40
41
  void Start(Scheduler* scheduler, MonoDelta interval);
42
  void Shutdown();
43
44
 private:
45
  void Schedule() REQUIRES(mutex_);
46
  void Poll(const Status& status);
47
48
51.5k
  const std::string& LogPrefix() {
49
51.5k
    return log_prefix_;
50
51.5k
  }
51
52
  const std::string log_prefix_;
53
  const std::function<void()> callback_;
54
55
  Scheduler* scheduler_ = nullptr;
56
  MonoDelta interval_;
57
58
  std::mutex mutex_;
59
  bool closing_ GUARDED_BY(mutex_) = false;
60
  rpc::ScheduledTaskId poll_task_id_ GUARDED_BY(mutex_);
61
  std::condition_variable cond_ GUARDED_BY(mutex_);
62
};
63
64
} // namespace rpc
65
} // namespace yb
66
67
#endif // YB_RPC_POLLER_H