YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
7.11k
      : Poller(/* log_prefix= */ std::string(), std::move(callback)) {}
_ZN2yb3rpc6PollerC1ENSt3__18functionIFvvEEE
Line
Count
Source
36
7.11k
      : Poller(/* log_prefix= */ std::string(), std::move(callback)) {}
Unexecuted instantiation: _ZN2yb3rpc6PollerC2ENSt3__18functionIFvvEEE
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
21.3k
  const std::string& LogPrefix() {
49
21.3k
    return log_prefix_;
50
21.3k
  }
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