YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/gutil/bind_helpers.h
Line
Count
Source
1
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
//
5
// The following only applies to changes made to this file as part of YugaByte development.
6
//
7
// Portions Copyright (c) YugaByte, Inc.
8
//
9
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
10
// in compliance with the License.  You may obtain a copy of the License at
11
//
12
// http://www.apache.org/licenses/LICENSE-2.0
13
//
14
// Unless required by applicable law or agreed to in writing, software distributed under the License
15
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
16
// or implied.  See the License for the specific language governing permissions and limitations
17
// under the License.
18
//
19
20
// This defines a set of argument wrappers and related factory methods that
21
// can be used specify the refcounting and reference semantics of arguments
22
// that are bound by the Bind() function in yb/gutil/bind.h.
23
//
24
// It also defines a set of simple functions and utilities that people want
25
// when using Callback<> and Bind().
26
//
27
//
28
// ARGUMENT BINDING WRAPPERS
29
//
30
// The wrapper functions are yb::Unretained(), yb::Owned(), yb::Passed(),
31
// yb::ConstRef(), and yb::IgnoreResult().
32
//
33
// Unretained() allows Bind() to bind a non-refcounted class, and to disable
34
// refcounting on arguments that are refcounted objects.
35
//
36
// Owned() transfers ownership of an object to the Callback resulting from
37
// bind; the object will be deleted when the Callback is deleted.
38
//
39
// Passed() is for transferring movable-but-not-copyable types (eg. scoped_ptr)
40
// through a Callback. Logically, this signifies a destructive transfer of
41
// the state of the argument into the target function.  Invoking
42
// Callback::Run() twice on a Callback that was created with a Passed()
43
// argument will CHECK() because the first invocation would have already
44
// transferred ownership to the target function.
45
//
46
// ConstRef() allows binding a constant reference to an argument rather
47
// than a copy.
48
//
49
// IgnoreResult() is used to adapt a function or Callback with a return type to
50
// one with a void return. This is most useful if you have a function with,
51
// say, a pesky ignorable bool return that you want to use with PostTask or
52
// something else that expect a Callback with a void return.
53
//
54
// EXAMPLE OF Unretained():
55
//
56
//   class Foo {
57
//    public:
58
//     void func() { cout << "Foo:f" << endl; }
59
//   };
60
//
61
//   // In some function somewhere.
62
//   Foo foo;
63
//   Closure foo_callback =
64
//       Bind(&Foo::func, Unretained(&foo));
65
//   foo_callback.Run();  // Prints "Foo:f".
66
//
67
// Without the Unretained() wrapper on |&foo|, the above call would fail
68
// to compile because Foo does not support the AddRef() and Release() methods.
69
//
70
//
71
// EXAMPLE OF Owned():
72
//
73
//   void foo(int* arg) { cout << *arg << endl }
74
//
75
//   int* pn = new int(1);
76
//   Closure foo_callback = Bind(&foo, Owned(pn));
77
//
78
//   foo_callback.Run();  // Prints "1"
79
//   foo_callback.Run();  // Prints "1"
80
//   *n = 2;
81
//   foo_callback.Run();  // Prints "2"
82
//
83
//   foo_callback.Reset();  // |pn| is deleted.  Also will happen when
84
//                          // |foo_callback| goes out of scope.
85
//
86
// Without Owned(), someone would have to know to delete |pn| when the last
87
// reference to the Callback is deleted.
88
//
89
//
90
// EXAMPLE OF ConstRef():
91
//
92
//   void foo(int arg) { cout << arg << endl }
93
//
94
//   int n = 1;
95
//   Closure no_ref = Bind(&foo, n);
96
//   Closure has_ref = Bind(&foo, ConstRef(n));
97
//
98
//   no_ref.Run();  // Prints "1"
99
//   has_ref.Run();  // Prints "1"
100
//
101
//   n = 2;
102
//   no_ref.Run();  // Prints "1"
103
//   has_ref.Run();  // Prints "2"
104
//
105
// Note that because ConstRef() takes a reference on |n|, |n| must outlive all
106
// its bound callbacks.
107
//
108
//
109
// EXAMPLE OF IgnoreResult():
110
//
111
//   int DoSomething(int arg) { cout << arg << endl; }
112
//
113
//   // Assign to a Callback with a void return type.
114
//   Callback<void(int)> cb = Bind(IgnoreResult(&DoSomething));
115
//   cb->Run(1);  // Prints "1".
116
//
117
//   // Prints "1" on |ml|.
118
//   ml->PostTask(FROM_HERE, Bind(IgnoreResult(&DoSomething), 1);
119
//
120
//
121
// EXAMPLE OF Passed():
122
//
123
//   void TakesOwnership(scoped_ptr<Foo> arg) { }
124
//   scoped_ptr<Foo> CreateFoo() { return scoped_ptr<Foo>(new Foo()); }
125
//
126
//   scoped_ptr<Foo> f(new Foo());
127
//
128
//   // |cb| is given ownership of Foo(). |f| is now NULL.
129
//   // You can use f.Pass() in place of &f, but it's more verbose.
130
//   Closure cb = Bind(&TakesOwnership, Passed(&f));
131
//
132
//   // Run was never called so |cb| still owns Foo() and deletes
133
//   // it on Reset().
134
//   cb.Reset();
135
//
136
//   // |cb| is given a new Foo created by CreateFoo().
137
//   cb = Bind(&TakesOwnership, Passed(CreateFoo()));
138
//
139
//   // |arg| in TakesOwnership() is given ownership of Foo(). |cb|
140
//   // no longer owns Foo() and, if reset, would not delete Foo().
141
//   cb.Run();  // Foo() is now transferred to |arg| and deleted.
142
//   cb.Run();  // This CHECK()s since Foo() already been used once.
143
//
144
// Passed() is particularly useful with PostTask() when you are transferring
145
// ownership of an argument into a task, but don't necessarily know if the
146
// task will always be executed. This can happen if the task is cancellable
147
// or if it is posted to a MessageLoopProxy.
148
//
149
//
150
// SIMPLE FUNCTIONS AND UTILITIES.
151
//
152
//   DoNothing() - Useful for creating a Closure that does nothing when called.
153
//   DeletePointer<T>() - Useful for creating a Closure that will delete a
154
//                        pointer when invoked. Only use this when necessary.
155
//                        In most cases MessageLoop::DeleteSoon() is a better
156
//                        fit.
157
158
#ifndef YB_GUTIL_BIND_HELPERS_H_
159
#define YB_GUTIL_BIND_HELPERS_H_
160
161
#include <assert.h>
162
163
#include "yb/gutil/callback.h"
164
#include "yb/gutil/integral_types.h"
165
#include "yb/gutil/macros.h"
166
#include "yb/gutil/template_util.h"
167
168
// Unneeded define from Chromium
169
#define BASE_EXPORT
170
171
172
namespace yb {
173
namespace internal {
174
175
// Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T
176
// for the existence of AddRef() and Release() functions of the correct
177
// signature.
178
//
179
// http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
180
// http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
181
// http://stackoverflow.com/questions/4358584/sfinae-approach-comparison
182
// http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
183
//
184
// The last link in particular show the method used below.
185
//
186
// For SFINAE to work with inherited methods, we need to pull some extra tricks
187
// with multiple inheritance.  In the more standard formulation, the overloads
188
// of Check would be:
189
//
190
//   template <typename C>
191
//   Yes NotTheCheckWeWant(Helper<&C::TargetFunc>*);
192
//
193
//   template <typename C>
194
//   No NotTheCheckWeWant(...);
195
//
196
//   static const bool value = sizeof(NotTheCheckWeWant<T>(0)) == sizeof(Yes);
197
//
198
// The problem here is that template resolution will not match
199
// C::TargetFunc if TargetFunc does not exist directly in C.  That is, if
200
// TargetFunc in inherited from an ancestor, &C::TargetFunc will not match,
201
// |value| will be false.  This formulation only checks for whether or
202
// not TargetFunc exist directly in the class being introspected.
203
//
204
// To get around this, we play a dirty trick with multiple inheritance.
205
// First, We create a class BaseMixin that declares each function that we
206
// want to probe for.  Then we create a class Base that inherits from both T
207
// (the class we wish to probe) and BaseMixin.  Note that the function
208
// signature in BaseMixin does not need to match the signature of the function
209
// we are probing for; thus it's easiest to just use void(void).
210
//
211
// Now, if TargetFunc exists somewhere in T, then &Base::TargetFunc has an
212
// ambiguous resolution between BaseMixin and T.  This lets us write the
213
// following:
214
//
215
//   template <typename C>
216
//   No GoodCheck(Helper<&C::TargetFunc>*);
217
//
218
//   template <typename C>
219
//   Yes GoodCheck(...);
220
//
221
//   static const bool value = sizeof(GoodCheck<Base>(0)) == sizeof(Yes);
222
//
223
// Notice here that the variadic version of GoodCheck() returns Yes here
224
// instead of No like the previous one. Also notice that we calculate |value|
225
// by specializing GoodCheck() on Base instead of T.
226
//
227
// We've reversed the roles of the variadic, and Helper overloads.
228
// GoodCheck(Helper<&C::TargetFunc>*), when C = Base, fails to be a valid
229
// substitution if T::TargetFunc exists. Thus GoodCheck<Base>(0) will resolve
230
// to the variadic version if T has TargetFunc.  If T::TargetFunc does not
231
// exist, then &C::TargetFunc is not ambiguous, and the overload resolution
232
// will prefer GoodCheck(Helper<&C::TargetFunc>*).
233
//
234
// This method of SFINAE will correctly probe for inherited names, but it cannot
235
// typecheck those names.  It's still a good enough sanity check though.
236
//
237
// Works on gcc-4.2, gcc-4.4, and Visual Studio 2008.
238
//
239
// TODO(ajwong): Move to ref_counted.h or template_util.h when we've vetted
240
// this works well.
241
//
242
// TODO(ajwong): Make this check for Release() as well.
243
// See http://crbug.com/82038.
244
template <typename T>
245
class SupportsAddRefAndRelease {
246
  typedef char Yes[1];
247
  typedef char No[2];
248
249
  struct BaseMixin {
250
    void AddRef();
251
  };
252
253
// MSVC warns when you try to use Base if T has a private destructor, the
254
// common pattern for refcounted types. It does this even though no attempt to
255
// instantiate Base is made.  We disable the warning for this definition.
256
#if defined(OS_WIN)
257
#pragma warning(push)
258
#pragma warning(disable:4624)
259
#endif
260
  struct Base : public T, public BaseMixin {
261
  };
262
#if defined(OS_WIN)
263
#pragma warning(pop)
264
#endif
265
266
  template <void(BaseMixin::*)(void)> struct Helper {};
267
268
  template <typename C>
269
  static No& Check(Helper<&C::AddRef>*);
270
271
  template <typename >
272
  static Yes& Check(...);
273
274
 public:
275
  static const bool value = sizeof(Check<Base>(0)) == sizeof(Yes);
276
};
277
278
// Helpers to assert that arguments of a recounted type are bound with a
279
// scoped_refptr.
280
template <bool IsClasstype, typename T>
281
struct UnsafeBindtoRefCountedArgHelper : base::false_type {
282
};
283
284
template <typename T>
285
struct UnsafeBindtoRefCountedArgHelper<true, T>
286
    : base::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
287
};
288
289
template <typename T>
290
struct UnsafeBindtoRefCountedArg : base::false_type {
291
};
292
293
template <typename T>
294
struct UnsafeBindtoRefCountedArg<T*>
295
    : UnsafeBindtoRefCountedArgHelper<base::is_class<T>::value, T> {
296
};
297
298
template <typename T>
299
class HasIsMethodTag {
300
  typedef char Yes[1];
301
  typedef char No[2];
302
303
  template <typename U>
304
  static Yes& Check(typename U::IsMethod*);
305
306
  template <typename U>
307
  static No& Check(...);
308
309
 public:
310
  static const bool value = sizeof(Check<T>(0)) == sizeof(Yes);
311
};
312
313
template <typename T>
314
class UnretainedWrapper {
315
 public:
316
85.4M
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::server::HybridClock>::UnretainedWrapper(yb::server::HybridClock*)
Line
Count
Source
316
77.3k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::server::LogicalClock>::UnretainedWrapper(yb::server::LogicalClock*)
Line
Count
Source
316
72
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet>::UnretainedWrapper(yb::tablet::AbstractTablet*)
Line
Count
Source
316
84.6k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::RedisResponsePB>::UnretainedWrapper(yb::RedisResponsePB*)
Line
Count
Source
316
84.6k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager>::UnretainedWrapper(yb::tserver::TSTabletManager*)
Line
Count
Source
316
142k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor>::UnretainedWrapper(yb::ql::TestQLProcessor*)
yb::internal::UnretainedWrapper<yb::ql::QLProcessor>::UnretainedWrapper(yb::ql::QLProcessor*)
Line
Count
Source
316
336k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::ql::ParseTree>::UnretainedWrapper(yb::ql::ParseTree*)
yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest>::UnretainedWrapper(yb::tserver::RemoteBootstrapSessionTest*)
Line
Count
Source
316
4
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue>::UnretainedWrapper(yb::consensus::PeerMessageQueue*)
Line
Count
Source
316
59.0M
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::consensus::LogCache>::UnretainedWrapper(yb::consensus::LogCache*)
Line
Count
Source
316
24.2M
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<char const>::UnretainedWrapper(char const*)
Line
Count
Source
316
158k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::master::CatalogManager>::UnretainedWrapper(yb::master::CatalogManager*)
Line
Count
Source
316
11.1k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::master::Master>::UnretainedWrapper(yb::master::Master*)
Line
Count
Source
316
8.03k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::master::SysCatalogTable>::UnretainedWrapper(yb::master::SysCatalogTable*)
Line
Count
Source
316
7.94k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager>::UnretainedWrapper(yb::master::enterprise::CatalogManager*)
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback>::UnretainedWrapper(yb::client::YBLoggingCallback*)
yb::internal::UnretainedWrapper<yb::client::YBClient::Data>::UnretainedWrapper(yb::client::YBClient::Data*)
Line
Count
Source
316
42.2k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer>::UnretainedWrapper(yb::debug::TraceResultBuffer*)
Line
Count
Source
316
23
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::debug::TraceLog>::UnretainedWrapper(yb::debug::TraceLog*)
Line
Count
Source
316
8
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
thread.cc:yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr>::UnretainedWrapper(yb::(anonymous namespace)::ThreadMgr*)
Line
Count
Source
316
52.8k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::Synchronizer>::UnretainedWrapper(yb::Synchronizer*)
Line
Count
Source
316
907k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor>::UnretainedWrapper(yb::cqlserver::CQLProcessor*)
Line
Count
Source
316
17.9k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
yb::internal::UnretainedWrapper<yb::log::Log>::UnretainedWrapper(yb::log::Log*)
Line
Count
Source
316
159k
  explicit UnretainedWrapper(T* o) : ptr_(o) {}
317
94.6M
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::server::HybridClock>::get() const
Line
Count
Source
317
46.4k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::server::LogicalClock>::get() const
Line
Count
Source
317
11
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet>::get() const
Line
Count
Source
317
84.6k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::RedisResponsePB>::get() const
Line
Count
Source
317
84.6k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager>::get() const
Line
Count
Source
317
592k
  T* get() const { return ptr_; }
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor>::get() const
yb::internal::UnretainedWrapper<yb::ql::QLProcessor>::get() const
Line
Count
Source
317
335k
  T* get() const { return ptr_; }
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::ql::ParseTree>::get() const
yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest>::get() const
Line
Count
Source
317
12
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue>::get() const
Line
Count
Source
317
59.0M
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::consensus::LogCache>::get() const
Line
Count
Source
317
24.3M
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<char const>::get() const
Line
Count
Source
317
91.9k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::master::CatalogManager>::get() const
Line
Count
Source
317
6.04k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::master::Master>::get() const
Line
Count
Source
317
8.03k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::master::SysCatalogTable>::get() const
Line
Count
Source
317
28.3k
  T* get() const { return ptr_; }
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager>::get() const
Unexecuted instantiation: yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback>::get() const
yb::internal::UnretainedWrapper<yb::client::YBClient::Data>::get() const
Line
Count
Source
317
38.7k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer>::get() const
Line
Count
Source
317
350
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::debug::TraceLog>::get() const
Line
Count
Source
317
8
  T* get() const { return ptr_; }
thread.cc:yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr>::get() const
Line
Count
Source
317
30.6k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::Synchronizer>::get() const
Line
Count
Source
317
907k
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor>::get() const
Line
Count
Source
317
8.90M
  T* get() const { return ptr_; }
yb::internal::UnretainedWrapper<yb::log::Log>::get() const
Line
Count
Source
317
160k
  T* get() const { return ptr_; }
318
 private:
319
  T* ptr_;
320
};
321
322
template <typename T>
323
class ConstRefWrapper {
324
 public:
325
672k
  explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::ConstRefWrapper(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
325
336k
  explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
yb::internal::ConstRefWrapper<yb::ql::StatementParameters>::ConstRefWrapper(yb::ql::StatementParameters const&)
Line
Count
Source
325
336k
  explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
326
669k
  const T& get() const { return *ptr_; }
yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::get() const
Line
Count
Source
326
334k
  const T& get() const { return *ptr_; }
yb::internal::ConstRefWrapper<yb::ql::StatementParameters>::get() const
Line
Count
Source
326
335k
  const T& get() const { return *ptr_; }
327
 private:
328
  const T* ptr_;
329
};
330
331
template <typename T>
332
struct IgnoreResultHelper {
333
  explicit IgnoreResultHelper(T functor) : functor_(functor) {}
334
335
  T functor_;
336
};
337
338
template <typename T>
339
struct IgnoreResultHelper<Callback<T> > {
340
  explicit IgnoreResultHelper(const Callback<T>& functor) : functor_(functor) {}
341
342
  const Callback<T>& functor_;
343
};
344
345
// An alternate implementation is to avoid the destructive copy, and instead
346
// specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to
347
// a class that is essentially a scoped_ptr<>.
348
//
349
// The current implementation has the benefit though of leaving ParamTraits<>
350
// fully in callback_internal.h as well as avoiding type conversions during
351
// storage.
352
template <typename T>
353
class OwnedWrapper {
354
 public:
355
336k
  explicit OwnedWrapper(T* o) : ptr_(o) {}
356
1.00M
  ~OwnedWrapper() { delete ptr_; }
357
334k
  T* get() const { return ptr_; }
358
670k
  OwnedWrapper(const OwnedWrapper& other) {
359
670k
    ptr_ = other.ptr_;
360
670k
    other.ptr_ = NULL;
361
670k
  }
362
363
 private:
364
  mutable T* ptr_;
365
};
366
367
// PassedWrapper is a copyable adapter for a scoper that ignores const.
368
//
369
// It is needed to get around the fact that Bind() takes a const reference to
370
// all its arguments.  Because Bind() takes a const reference to avoid
371
// unnecessary copies, it is incompatible with movable-but-not-copyable
372
// types; doing a destructive "move" of the type into Bind() would violate
373
// the const correctness.
374
//
375
// This conundrum cannot be solved without either C++11 rvalue references or
376
// a O(2^n) blowup of Bind() templates to handle each combination of regular
377
// types and movable-but-not-copyable types.  Thus we introduce a wrapper type
378
// that is copyable to transmit the correct type information down into
379
// BindState<>. Ignoring const in this type makes sense because it is only
380
// created when we are explicitly trying to do a destructive move.
381
//
382
// Two notes:
383
//  1) PassedWrapper supports any type that has a "Pass()" function.
384
//     This is intentional. The whitelisting of which specific types we
385
//     support is maintained by CallbackParamTraits<>.
386
//  2) is_valid_ is distinct from NULL because it is valid to bind a "NULL"
387
//     scoper to a Callback and allow the Callback to execute once.
388
template <typename T>
389
class PassedWrapper {
390
 public:
391
  explicit PassedWrapper(T scoper) : is_valid_(true), scoper_(scoper.Pass()) {}
392
  PassedWrapper(const PassedWrapper& other)
393
      : is_valid_(other.is_valid_), scoper_(other.scoper_.Pass()) {
394
  }
395
  T Pass() const {
396
    assert(is_valid_);
397
    is_valid_ = false;
398
    return scoper_.Pass();
399
  }
400
401
 private:
402
  mutable bool is_valid_;
403
  mutable T scoper_;
404
};
405
406
// Unwrap the stored parameters for the wrappers above.
407
template <typename T>
408
struct UnwrapTraits {
409
  typedef const T& ForwardType;
410
110M
  static ForwardType Unwrap(const T& o) { return o; }
Unexecuted instantiation: yb::internal::UnwrapTraits<unsigned long long>::Unwrap(unsigned long long const&)
yb::internal::UnwrapTraits<long long>::Unwrap(long long const&)
Line
Count
Source
410
24.3M
  static ForwardType Unwrap(const T& o) { return o; }
heartbeater.cc:yb::internal::UnwrapTraits<std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> >::Unwrap(std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> const&)
Line
Count
Source
410
417k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > >::Unwrap(std::__1::chrono::time_point<yb::CoarseMonoClock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > const&)
Line
Count
Source
410
84.6k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::ReadHybridTime>::Unwrap(yb::ReadHybridTime const&)
Line
Count
Source
410
84.6k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::RedisReadRequestPB>::Unwrap(yb::RedisReadRequestPB const&)
Line
Count
Source
410
84.6k
  static ForwardType Unwrap(const T& o) { return o; }
read_query.cc:yb::internal::UnwrapTraits<yb::tserver::(anonymous namespace)::ReadQuery::DoReadImpl()::$_1>::Unwrap(yb::tserver::(anonymous namespace)::ReadQuery::DoReadImpl()::$_1 const&)
Line
Count
Source
410
84.6k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Unwrap(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
410
625k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::Callback<void (yb::Status const&)> >::Unwrap(yb::Callback<void (yb::Status const&)> const&)
Line
Count
Source
410
24.3M
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::Callback<void (yb::Status const&, std::__1::shared_ptr<yb::ql::ExecutedResult> const&)> >::Unwrap(yb::Callback<void (yb::Status const&, std::__1::shared_ptr<yb::ql::ExecutedResult> const&)> const&)
Line
Count
Source
410
334k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::OpId>::Unwrap(yb::OpId const&)
Line
Count
Source
410
24.3M
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::consensus::MajorityReplicatedData>::Unwrap(yb::consensus::MajorityReplicatedData const&)
Line
Count
Source
410
34.7M
  static ForwardType Unwrap(const T& o) { return o; }
Unexecuted instantiation: yb::internal::UnwrapTraits<std::__1::shared_ptr<std::__1::vector<yb::client::YBTableInfo, std::__1::allocator<yb::client::YBTableInfo> > > >::Unwrap(std::__1::shared_ptr<std::__1::vector<yb::client::YBTableInfo, std::__1::allocator<yb::client::YBTableInfo> > > const&)
Unexecuted instantiation: yb::internal::UnwrapTraits<std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > >::Unwrap(std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&)
Unexecuted instantiation: yb::internal::UnwrapTraits<std::__1::shared_ptr<yb::client::YBTableInfo> >::Unwrap(std::__1::shared_ptr<yb::client::YBTableInfo> const&)
yb::internal::UnwrapTraits<std::__1::shared_ptr<yb::tools::YsckTabletServer> >::Unwrap(std::__1::shared_ptr<yb::tools::YsckTabletServer> const&)
Line
Count
Source
410
4.37k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<std::__1::shared_ptr<yb::BlockingQueue<std::__1::pair<yb::Schema, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, yb::DefaultLogicalSize> > >::Unwrap(std::__1::shared_ptr<yb::BlockingQueue<std::__1::pair<yb::Schema, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, yb::DefaultLogicalSize> > const&)
Line
Count
Source
410
4.37k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::tools::ChecksumOptions>::Unwrap(yb::tools::ChecksumOptions const&)
Line
Count
Source
410
4.37k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::HostPort*>::Unwrap(yb::HostPort* const&)
Line
Count
Source
410
2.93k
  static ForwardType Unwrap(const T& o) { return o; }
yb::internal::UnwrapTraits<yb::Synchronizer*>::Unwrap(yb::Synchronizer* const&)
Line
Count
Source
410
602k
  static ForwardType Unwrap(const T& o) { return o; }
Unexecuted instantiation: yb::internal::UnwrapTraits<std::__1::weak_ptr<yb::Synchronizer> >::Unwrap(std::__1::weak_ptr<yb::Synchronizer> const&)
yb::internal::UnwrapTraits<std::__1::shared_ptr<yb::ql::ExecutedResult>*>::Unwrap(std::__1::shared_ptr<yb::ql::ExecutedResult>* const&)
Line
Count
Source
410
177k
  static ForwardType Unwrap(const T& o) { return o; }
411
};
412
413
template <typename T>
414
struct UnwrapTraits<UnretainedWrapper<T> > {
415
  typedef T* ForwardType;
416
94.6M
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
94.6M
    return unretained.get();
418
94.6M
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::server::HybridClock> >::Unwrap(yb::internal::UnretainedWrapper<yb::server::HybridClock>)
Line
Count
Source
416
46.4k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
46.4k
    return unretained.get();
418
46.4k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::server::LogicalClock> >::Unwrap(yb::internal::UnretainedWrapper<yb::server::LogicalClock>)
Line
Count
Source
416
11
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
11
    return unretained.get();
418
11
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> >::Unwrap(yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet>)
Line
Count
Source
416
84.6k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
84.6k
    return unretained.get();
418
84.6k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::RedisResponsePB> >::Unwrap(yb::internal::UnretainedWrapper<yb::RedisResponsePB>)
Line
Count
Source
416
84.6k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
84.6k
    return unretained.get();
418
84.6k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> >::Unwrap(yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager>)
Line
Count
Source
416
592k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
592k
    return unretained.get();
418
592k
  }
Unexecuted instantiation: yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> >::Unwrap(yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor>)
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::ql::QLProcessor> >::Unwrap(yb::internal::UnretainedWrapper<yb::ql::QLProcessor>)
Line
Count
Source
416
333k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
333k
    return unretained.get();
418
333k
  }
Unexecuted instantiation: yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::ql::ParseTree> >::Unwrap(yb::internal::UnretainedWrapper<yb::ql::ParseTree>)
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> >::Unwrap(yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest>)
Line
Count
Source
416
12
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
12
    return unretained.get();
418
12
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> >::Unwrap(yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue>)
Line
Count
Source
416
59.0M
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
59.0M
    return unretained.get();
418
59.0M
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::consensus::LogCache> >::Unwrap(yb::internal::UnretainedWrapper<yb::consensus::LogCache>)
Line
Count
Source
416
24.3M
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
24.3M
    return unretained.get();
418
24.3M
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<char const> >::Unwrap(yb::internal::UnretainedWrapper<char const>)
Line
Count
Source
416
91.9k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
91.9k
    return unretained.get();
418
91.9k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::master::CatalogManager> >::Unwrap(yb::internal::UnretainedWrapper<yb::master::CatalogManager>)
Line
Count
Source
416
6.04k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
6.04k
    return unretained.get();
418
6.04k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::master::Master> >::Unwrap(yb::internal::UnretainedWrapper<yb::master::Master>)
Line
Count
Source
416
8.03k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
8.03k
    return unretained.get();
418
8.03k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> >::Unwrap(yb::internal::UnretainedWrapper<yb::master::SysCatalogTable>)
Line
Count
Source
416
28.3k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
28.3k
    return unretained.get();
418
28.3k
  }
Unexecuted instantiation: yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> >::Unwrap(yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager>)
Unexecuted instantiation: yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> >::Unwrap(yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback>)
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::client::YBClient::Data> >::Unwrap(yb::internal::UnretainedWrapper<yb::client::YBClient::Data>)
Line
Count
Source
416
38.7k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
38.7k
    return unretained.get();
418
38.7k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> >::Unwrap(yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer>)
Line
Count
Source
416
350
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
350
    return unretained.get();
418
350
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::debug::TraceLog> >::Unwrap(yb::internal::UnretainedWrapper<yb::debug::TraceLog>)
Line
Count
Source
416
8
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
8
    return unretained.get();
418
8
  }
thread.cc:yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> >::Unwrap(yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr>)
Line
Count
Source
416
30.6k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
30.6k
    return unretained.get();
418
30.6k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::Synchronizer> >::Unwrap(yb::internal::UnretainedWrapper<yb::Synchronizer>)
Line
Count
Source
416
907k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
907k
    return unretained.get();
418
907k
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> >::Unwrap(yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor>)
Line
Count
Source
416
8.89M
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
8.89M
    return unretained.get();
418
8.89M
  }
yb::internal::UnwrapTraits<yb::internal::UnretainedWrapper<yb::log::Log> >::Unwrap(yb::internal::UnretainedWrapper<yb::log::Log>)
Line
Count
Source
416
160k
  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
417
160k
    return unretained.get();
418
160k
  }
419
};
420
421
template <typename T>
422
struct UnwrapTraits<ConstRefWrapper<T> > {
423
  typedef const T& ForwardType;
424
668k
  static ForwardType Unwrap(ConstRefWrapper<T> const_ref) {
425
668k
    return const_ref.get();
426
668k
  }
yb::internal::UnwrapTraits<yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::Unwrap(yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >)
Line
Count
Source
424
333k
  static ForwardType Unwrap(ConstRefWrapper<T> const_ref) {
425
333k
    return const_ref.get();
426
333k
  }
yb::internal::UnwrapTraits<yb::internal::ConstRefWrapper<yb::ql::StatementParameters> >::Unwrap(yb::internal::ConstRefWrapper<yb::ql::StatementParameters>)
Line
Count
Source
424
334k
  static ForwardType Unwrap(ConstRefWrapper<T> const_ref) {
425
334k
    return const_ref.get();
426
334k
  }
427
};
428
429
template <typename T>
430
struct UnwrapTraits<scoped_refptr<T> > {
431
  typedef T* ForwardType;
432
4.37k
  static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); }
433
};
434
435
// We didn't import WeakPtr from Chromium.
436
//
437
// template <typename T>
438
// struct UnwrapTraits<WeakPtr<T> > {
439
//   typedef const WeakPtr<T>& ForwardType;
440
//   static ForwardType Unwrap(const WeakPtr<T>& o) { return o; }
441
// };
442
443
template <typename T>
444
struct UnwrapTraits<OwnedWrapper<T> > {
445
  typedef T* ForwardType;
446
334k
  static ForwardType Unwrap(const OwnedWrapper<T>& o) {
447
334k
    return o.get();
448
334k
  }
449
};
450
451
template <typename T>
452
struct UnwrapTraits<PassedWrapper<T> > {
453
  typedef T ForwardType;
454
  static T Unwrap(PassedWrapper<T>& o) { // NOLINT
455
    return o.Pass();
456
  }
457
};
458
459
// Utility for handling different refcounting semantics in the Bind()
460
// function.
461
template <bool is_method, typename T>
462
struct MaybeRefcount;
463
464
template <typename T>
465
struct MaybeRefcount<false, T> {
466
1.26M
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<false, unsigned long long>::AddRef(unsigned long long const&)
Line
Count
Source
466
331
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<false, long long>::AddRef(long long const&)
Line
Count
Source
466
164
  static void AddRef(const T&) {}
heartbeater.cc:yb::internal::MaybeRefcount<false, std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> >::AddRef(std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> const&)
Line
Count
Source
466
418k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> >::AddRef(yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> const&)
Line
Count
Source
466
84.6k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<char const> >::AddRef(yb::internal::UnretainedWrapper<char const> const&)
Line
Count
Source
466
158k
  static void AddRef(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> >::AddRef(yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> const&)
yb::internal::MaybeRefcount<false, scoped_refptr<yb::tools::ChecksumResultReporter> >::AddRef(scoped_refptr<yb::tools::ChecksumResultReporter> const&)
Line
Count
Source
466
4.37k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<false, yb::HostPort*>::AddRef(yb::HostPort* const&)
Line
Count
Source
466
2.93k
  static void AddRef(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<false, std::__1::weak_ptr<yb::Synchronizer> >::AddRef(std::__1::weak_ptr<yb::Synchronizer> const&)
yb::internal::MaybeRefcount<false, yb::Synchronizer*>::AddRef(yb::Synchronizer* const&)
Line
Count
Source
466
599k
  static void AddRef(const T&) {}
467
1.11M
  static void Release(const T&) {}
yb::internal::MaybeRefcount<false, unsigned long long>::Release(unsigned long long const&)
Line
Count
Source
467
314
  static void Release(const T&) {}
yb::internal::MaybeRefcount<false, long long>::Release(long long const&)
Line
Count
Source
467
157
  static void Release(const T&) {}
heartbeater.cc:yb::internal::MaybeRefcount<false, std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> >::Release(std::__1::shared_ptr<yb::tserver::(anonymous namespace)::FindLeaderMasterData> const&)
Line
Count
Source
467
417k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> >::Release(yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> const&)
Line
Count
Source
467
84.6k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<char const> >::Release(yb::internal::UnretainedWrapper<char const> const&)
Line
Count
Source
467
984
  static void Release(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<false, yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> >::Release(yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> const&)
yb::internal::MaybeRefcount<false, scoped_refptr<yb::tools::ChecksumResultReporter> >::Release(scoped_refptr<yb::tools::ChecksumResultReporter> const&)
Line
Count
Source
467
4.37k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<false, yb::HostPort*>::Release(yb::HostPort* const&)
Line
Count
Source
467
2.93k
  static void Release(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<false, std::__1::weak_ptr<yb::Synchronizer> >::Release(std::__1::weak_ptr<yb::Synchronizer> const&)
yb::internal::MaybeRefcount<false, yb::Synchronizer*>::Release(yb::Synchronizer* const&)
Line
Count
Source
467
599k
  static void Release(const T&) {}
468
};
469
470
template <typename T, size_t n>
471
struct MaybeRefcount<false, T[n]> {
472
  static void AddRef(const T*) {}
473
  static void Release(const T*) {}
474
};
475
476
template <typename T>
477
struct MaybeRefcount<true, T> {
478
85.1M
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::server::HybridClock> >::AddRef(yb::internal::UnretainedWrapper<yb::server::HybridClock> const&)
Line
Count
Source
478
77.3k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::server::LogicalClock> >::AddRef(yb::internal::UnretainedWrapper<yb::server::LogicalClock> const&)
Line
Count
Source
478
72
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> >::AddRef(yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> const&)
Line
Count
Source
478
142k
  static void AddRef(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> >::AddRef(yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> const&)
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::ql::QLProcessor> >::AddRef(yb::internal::UnretainedWrapper<yb::ql::QLProcessor> const&)
Line
Count
Source
478
336k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> >::AddRef(yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> const&)
Line
Count
Source
478
4
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> >::AddRef(yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> const&)
Line
Count
Source
478
59.0M
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::consensus::LogCache> >::AddRef(yb::internal::UnretainedWrapper<yb::consensus::LogCache> const&)
Line
Count
Source
478
24.3M
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::CatalogManager> >::AddRef(yb::internal::UnretainedWrapper<yb::master::CatalogManager> const&)
Line
Count
Source
478
11.1k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::Master> >::AddRef(yb::internal::UnretainedWrapper<yb::master::Master> const&)
Line
Count
Source
478
8.03k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> >::AddRef(yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> const&)
Line
Count
Source
478
7.94k
  static void AddRef(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> >::AddRef(yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> const&)
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::client::YBClient::Data> >::AddRef(yb::internal::UnretainedWrapper<yb::client::YBClient::Data> const&)
Line
Count
Source
478
41.0k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> >::AddRef(yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> const&)
Line
Count
Source
478
23
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::debug::TraceLog> >::AddRef(yb::internal::UnretainedWrapper<yb::debug::TraceLog> const&)
Line
Count
Source
478
8
  static void AddRef(const T&) {}
thread.cc:yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> >::AddRef(yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> const&)
Line
Count
Source
478
52.8k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::Synchronizer> >::AddRef(yb::internal::UnretainedWrapper<yb::Synchronizer> const&)
Line
Count
Source
478
907k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> >::AddRef(yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> const&)
Line
Count
Source
478
18.1k
  static void AddRef(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::log::Log> >::AddRef(yb::internal::UnretainedWrapper<yb::log::Log> const&)
Line
Count
Source
478
159k
  static void AddRef(const T&) {}
479
84.8M
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::server::HybridClock> >::Release(yb::internal::UnretainedWrapper<yb::server::HybridClock> const&)
Line
Count
Source
479
480
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::server::LogicalClock> >::Release(yb::internal::UnretainedWrapper<yb::server::LogicalClock> const&)
Line
Count
Source
479
11
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> >::Release(yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> const&)
Line
Count
Source
479
74.0k
  static void Release(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> >::Release(yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> const&)
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::ql::QLProcessor> >::Release(yb::internal::UnretainedWrapper<yb::ql::QLProcessor> const&)
Line
Count
Source
479
336k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> >::Release(yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> const&)
Line
Count
Source
479
4
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> >::Release(yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> const&)
Line
Count
Source
479
59.0M
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::consensus::LogCache> >::Release(yb::internal::UnretainedWrapper<yb::consensus::LogCache> const&)
Line
Count
Source
479
24.3M
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::CatalogManager> >::Release(yb::internal::UnretainedWrapper<yb::master::CatalogManager> const&)
Line
Count
Source
479
3.10k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::Master> >::Release(yb::internal::UnretainedWrapper<yb::master::Master> const&)
Line
Count
Source
479
7.95k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> >::Release(yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> const&)
Line
Count
Source
479
102
  static void Release(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> >::Release(yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> const&)
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::client::YBClient::Data> >::Release(yb::internal::UnretainedWrapper<yb::client::YBClient::Data> const&)
Line
Count
Source
479
38.6k
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> >::Release(yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> const&)
Line
Count
Source
479
23
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::debug::TraceLog> >::Release(yb::internal::UnretainedWrapper<yb::debug::TraceLog> const&)
Line
Count
Source
479
8
  static void Release(const T&) {}
thread.cc:yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> >::Release(yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> const&)
Line
Count
Source
479
332
  static void Release(const T&) {}
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::Synchronizer> >::Release(yb::internal::UnretainedWrapper<yb::Synchronizer> const&)
Line
Count
Source
479
907k
  static void Release(const T&) {}
Unexecuted instantiation: yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> >::Release(yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> const&)
yb::internal::MaybeRefcount<true, yb::internal::UnretainedWrapper<yb::log::Log> >::Release(yb::internal::UnretainedWrapper<yb::log::Log> const&)
Line
Count
Source
479
160k
  static void Release(const T&) {}
480
};
481
482
template <typename T>
483
struct MaybeRefcount<true, T*> {
484
  static void AddRef(T* o) { o->AddRef(); }
485
  static void Release(T* o) { o->Release(); }
486
};
487
488
// No need to additionally AddRef() and Release() since we are storing a
489
// scoped_refptr<> inside the storage object already.
490
template <typename T>
491
struct MaybeRefcount<true, scoped_refptr<T> > {
492
  static void AddRef(const scoped_refptr<T>& o) {}
493
  static void Release(const scoped_refptr<T>& o) {}
494
};
495
496
template <typename T>
497
struct MaybeRefcount<true, const T*> {
498
  static void AddRef(const T* o) { o->AddRef(); }
499
  static void Release(const T* o) { o->Release(); }
500
};
501
502
// We didn't import WeakPtr from Chromium.
503
//
504
//// IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a
505
//// method.  It is used internally by Bind() to select the correct
506
//// InvokeHelper that will no-op itself in the event the WeakPtr<> for
507
//// the target object is invalidated.
508
////
509
//// P1 should be the type of the object that will be received of the method.
510
// template <bool IsMethod, typename P1>
511
// struct IsWeakMethod : public false_type {};
512
//
513
// template <typename T>
514
// struct IsWeakMethod<true, WeakPtr<T> > : public true_type {};
515
//
516
// template <typename T>
517
// struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T> > > : public true_type {};
518
519
}  // namespace internal
520
521
template <typename T>
522
85.4M
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
85.4M
  return internal::UnretainedWrapper<T>(o);
524
85.4M
}
hybrid_clock.cc:yb::internal::UnretainedWrapper<yb::server::HybridClock> yb::Unretained<yb::server::HybridClock>(yb::server::HybridClock*)
Line
Count
Source
522
77.3k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
77.3k
  return internal::UnretainedWrapper<T>(o);
524
77.3k
}
logical_clock.cc:yb::internal::UnretainedWrapper<yb::server::LogicalClock> yb::Unretained<yb::server::LogicalClock>(yb::server::LogicalClock*)
Line
Count
Source
522
72
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
72
  return internal::UnretainedWrapper<T>(o);
524
72
}
read_query.cc:yb::internal::UnretainedWrapper<yb::tablet::AbstractTablet> yb::Unretained<yb::tablet::AbstractTablet>(yb::tablet::AbstractTablet*)
Line
Count
Source
522
84.6k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
84.6k
  return internal::UnretainedWrapper<T>(o);
524
84.6k
}
read_query.cc:yb::internal::UnretainedWrapper<yb::RedisResponsePB> yb::Unretained<yb::RedisResponsePB>(yb::RedisResponsePB*)
Line
Count
Source
522
84.6k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
84.6k
  return internal::UnretainedWrapper<T>(o);
524
84.6k
}
ts_tablet_manager.cc:yb::internal::UnretainedWrapper<yb::tserver::TSTabletManager> yb::Unretained<yb::tserver::TSTabletManager>(yb::tserver::TSTabletManager*)
Line
Count
Source
522
142k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
142k
  return internal::UnretainedWrapper<T>(o);
524
142k
}
Unexecuted instantiation: ql-test-base.cc:yb::internal::UnretainedWrapper<yb::ql::TestQLProcessor> yb::Unretained<yb::ql::TestQLProcessor>(yb::ql::TestQLProcessor*)
Unexecuted instantiation: ql-test-base.cc:yb::internal::UnretainedWrapper<yb::ql::QLProcessor> yb::Unretained<yb::ql::QLProcessor>(yb::ql::QLProcessor*)
Unexecuted instantiation: ql-test-base.cc:yb::internal::UnretainedWrapper<yb::ql::ParseTree> yb::Unretained<yb::ql::ParseTree>(yb::ql::ParseTree*)
remote_bootstrap_session-test.cc:yb::internal::UnretainedWrapper<yb::tserver::RemoteBootstrapSessionTest> yb::Unretained<yb::tserver::RemoteBootstrapSessionTest>(yb::tserver::RemoteBootstrapSessionTest*)
Line
Count
Source
522
4
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
4
  return internal::UnretainedWrapper<T>(o);
524
4
}
consensus_queue.cc:yb::internal::UnretainedWrapper<yb::consensus::PeerMessageQueue> yb::Unretained<yb::consensus::PeerMessageQueue>(yb::consensus::PeerMessageQueue*)
Line
Count
Source
522
59.0M
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
59.0M
  return internal::UnretainedWrapper<T>(o);
524
59.0M
}
log_cache.cc:yb::internal::UnretainedWrapper<yb::consensus::LogCache> yb::Unretained<yb::consensus::LogCache>(yb::consensus::LogCache*)
Line
Count
Source
522
24.2M
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
24.2M
  return internal::UnretainedWrapper<T>(o);
524
24.2M
}
tcmalloc_metrics.cc:yb::internal::UnretainedWrapper<char const> yb::Unretained<char const>(char const*)
Line
Count
Source
522
158k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
158k
  return internal::UnretainedWrapper<T>(o);
524
158k
}
catalog_manager.cc:yb::internal::UnretainedWrapper<yb::master::CatalogManager> yb::Unretained<yb::master::CatalogManager>(yb::master::CatalogManager*)
Line
Count
Source
522
11.1k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
11.1k
  return internal::UnretainedWrapper<T>(o);
524
11.1k
}
master.cc:yb::internal::UnretainedWrapper<yb::master::Master> yb::Unretained<yb::master::Master>(yb::master::Master*)
Line
Count
Source
522
8.03k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
8.03k
  return internal::UnretainedWrapper<T>(o);
524
8.03k
}
sys_catalog.cc:yb::internal::UnretainedWrapper<yb::master::SysCatalogTable> yb::Unretained<yb::master::SysCatalogTable>(yb::master::SysCatalogTable*)
Line
Count
Source
522
7.94k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
7.94k
  return internal::UnretainedWrapper<T>(o);
524
7.94k
}
Unexecuted instantiation: catalog_manager_ent.cc:yb::internal::UnretainedWrapper<yb::master::enterprise::CatalogManager> yb::Unretained<yb::master::enterprise::CatalogManager>(yb::master::enterprise::CatalogManager*)
Unexecuted instantiation: client.cc:yb::internal::UnretainedWrapper<yb::client::YBLoggingCallback> yb::Unretained<yb::client::YBLoggingCallback>(yb::client::YBLoggingCallback*)
client-internal.cc:yb::internal::UnretainedWrapper<yb::client::YBClient::Data> yb::Unretained<yb::client::YBClient::Data>(yb::client::YBClient::Data*)
Line
Count
Source
522
42.3k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
42.3k
  return internal::UnretainedWrapper<T>(o);
524
42.3k
}
ql_processor.cc:yb::internal::UnretainedWrapper<yb::ql::QLProcessor> yb::Unretained<yb::ql::QLProcessor>(yb::ql::QLProcessor*)
Line
Count
Source
522
336k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
336k
  return internal::UnretainedWrapper<T>(o);
524
336k
}
trace_event_impl.cc:yb::internal::UnretainedWrapper<yb::debug::TraceResultBuffer> yb::Unretained<yb::debug::TraceResultBuffer>(yb::debug::TraceResultBuffer*)
Line
Count
Source
522
23
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
23
  return internal::UnretainedWrapper<T>(o);
524
23
}
trace_event_impl.cc:yb::internal::UnretainedWrapper<yb::debug::TraceLog> yb::Unretained<yb::debug::TraceLog>(yb::debug::TraceLog*)
Line
Count
Source
522
8
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
8
  return internal::UnretainedWrapper<T>(o);
524
8
}
thread.cc:yb::internal::UnretainedWrapper<yb::(anonymous namespace)::ThreadMgr> yb::Unretained<yb::(anonymous namespace)::ThreadMgr>(yb::(anonymous namespace)::ThreadMgr*)
Line
Count
Source
522
52.8k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
52.8k
  return internal::UnretainedWrapper<T>(o);
524
52.8k
}
async_util.cc:yb::internal::UnretainedWrapper<yb::Synchronizer> yb::Unretained<yb::Synchronizer>(yb::Synchronizer*)
Line
Count
Source
522
907k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
907k
  return internal::UnretainedWrapper<T>(o);
524
907k
}
cql_processor.cc:yb::internal::UnretainedWrapper<yb::cqlserver::CQLProcessor> yb::Unretained<yb::cqlserver::CQLProcessor>(yb::cqlserver::CQLProcessor*)
Line
Count
Source
522
18.0k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
18.0k
  return internal::UnretainedWrapper<T>(o);
524
18.0k
}
log.cc:yb::internal::UnretainedWrapper<yb::log::Log> yb::Unretained<yb::log::Log>(yb::log::Log*)
Line
Count
Source
522
159k
static inline internal::UnretainedWrapper<T> Unretained(T* o) {
523
159k
  return internal::UnretainedWrapper<T>(o);
524
159k
}
525
526
template <typename T>
527
671k
static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
528
671k
  return internal::ConstRefWrapper<T>(o);
529
671k
}
Unexecuted instantiation: ql-test-base.cc:yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > yb::ConstRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: ql-test-base.cc:yb::internal::ConstRefWrapper<yb::ql::StatementParameters> yb::ConstRef<yb::ql::StatementParameters>(yb::ql::StatementParameters const&)
ql_processor.cc:yb::internal::ConstRefWrapper<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > yb::ConstRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
527
335k
static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
528
335k
  return internal::ConstRefWrapper<T>(o);
529
335k
}
ql_processor.cc:yb::internal::ConstRefWrapper<yb::ql::StatementParameters> yb::ConstRef<yb::ql::StatementParameters>(yb::ql::StatementParameters const&)
Line
Count
Source
527
335k
static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
528
335k
  return internal::ConstRefWrapper<T>(o);
529
335k
}
530
531
template <typename T>
532
336k
static inline internal::OwnedWrapper<T> Owned(T* o) {
533
336k
  return internal::OwnedWrapper<T>(o);
534
336k
}
535
536
// We offer 2 syntaxes for calling Passed().  The first takes a temporary and
537
// is best suited for use with the return value of a function. The second
538
// takes a pointer to the scoper and is just syntactic sugar to avoid having
539
// to write Passed(scoper.Pass()).
540
template <typename T>
541
static inline internal::PassedWrapper<T> Passed(T scoper) {
542
  return internal::PassedWrapper<T>(scoper.Pass());
543
}
544
template <typename T>
545
static inline internal::PassedWrapper<T> Passed(T* scoper) {
546
  return internal::PassedWrapper<T>(scoper->Pass());
547
}
548
549
template <typename T>
550
static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) {
551
  return internal::IgnoreResultHelper<T>(data);
552
}
553
554
template <typename T>
555
static inline internal::IgnoreResultHelper<Callback<T> >
556
IgnoreResult(const Callback<T>& data) {
557
  return internal::IgnoreResultHelper<Callback<T> >(data);
558
}
559
560
template<typename T>
561
void DeletePointer(T* obj) {
562
  delete obj;
563
}
564
565
}  // namespace yb
566
567
#endif  // YB_GUTIL_BIND_HELPERS_H_