proxygen
UndelayedDestruction.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cassert>
20 #include <cstdlib>
21 #include <type_traits>
22 #include <utility>
23 
24 namespace folly {
25 
43 template <typename TDD>
44 class UndelayedDestruction : public TDD {
45  public:
46  // We could just use constructor inheritance, but not all compilers
47  // support that. So, just use a forwarding constructor.
48  //
49  // Ideally we would use std::enable_if<> and std::is_constructible<> to
50  // provide only constructor methods that are valid for our parent class.
51  // Unfortunately std::is_constructible<> doesn't work for types that aren't
52  // destructible. In gcc-4.6 it results in a compiler error. In the latest
53  // gcc code it looks like it has been fixed to return false. (The language
54  // in the standard seems to indicate that returning false is the correct
55  // behavior for non-destructible types, which is unfortunate.)
56  template <typename... Args>
57  explicit UndelayedDestruction(Args&&... args)
58  : TDD(std::forward<Args>(args)...) {}
59 
71  ~UndelayedDestruction() override {
72  // Crash if the caller is destroying us with outstanding destructor guards.
73  if (this->getDestructorGuardCount() != 0) {
74  abort();
75  }
76  // Invoke destroy. This is necessary since our base class may have
77  // implemented custom behavior in destroy().
78  this->destroy();
79  }
80 
81  void onDelayedDestroy(bool delayed) override {
82  if (delayed && !this->TDD::getDestroyPending()) {
83  return;
84  }
85  // Do nothing. This will always be invoked from the call to destroy
86  // inside our destructor.
87  assert(!delayed);
88  // prevent unused variable warnings when asserts are compiled out.
89  (void)delayed;
90  }
91 
92  protected:
97  void destroy() override {
98  this->TDD::destroy();
99  }
100 
101  private:
102  // Forbidden copy constructor and assignment operator
105 };
106 
107 } // namespace folly
void onDelayedDestroy(bool delayed) override
STL namespace.
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
static void destroy()
UndelayedDestruction & operator=(UndelayedDestruction const &)=delete