proxygen
DelayedDestruction.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 
20 
21 #include <glog/logging.h>
22 
23 namespace folly {
24 
43  public:
51  virtual void destroy() {
52  // If guardCount_ is not 0, just set destroyPending_ to delay
53  // actual destruction.
54  if (getDestructorGuardCount() != 0) {
55  destroyPending_ = true;
56  } else {
57  onDelayedDestroy(false);
58  }
59  }
60 
69  class Destructor {
70  public:
71  void operator()(DelayedDestruction* dd) const {
72  dd->destroy();
73  }
74  };
75 
76  bool getDestroyPending() const {
77  return destroyPending_;
78  }
79 
80  protected:
97  ~DelayedDestruction() override = default;
98 
100 
101  private:
110 
111  void onDelayedDestroy(bool delayed) override {
112  // check if it is ok to destroy now
113  if (delayed && !destroyPending_) {
114  return;
115  }
116  destroyPending_ = false;
117  delete this;
118  }
119 };
120 } // namespace folly
~DelayedDestruction() override=default
void operator()(DelayedDestruction *dd) const
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void onDelayedDestroy(bool delayed) override