proxygen
DelayedDestructionBaseTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-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 
18 
19 #include <functional>
20 
22 
23 using namespace folly;
24 
26  public:
27  DestructionOnCallback() : state_(0), deleted_(false) {}
28 
29  void onComplete(int n, int& state) {
30  DestructorGuard dg(this);
31  for (auto i = n; i >= 0; --i) {
32  onStackedComplete(i);
33  }
34  state = state_;
35  }
36 
37  int state() const {
38  return state_;
39  }
40  bool deleted() const {
41  return deleted_;
42  }
43 
44  protected:
45  void onStackedComplete(int recur) {
46  DestructorGuard dg(this);
47  ++state_;
48  if (recur <= 0) {
49  return;
50  }
51  onStackedComplete(--recur);
52  }
53 
54  private:
55  int state_;
56  bool deleted_;
57 
58  void onDelayedDestroy(bool delayed) override {
59  deleted_ = true;
60  delete this;
61  (void)delayed; // prevent unused variable warnings
62  }
63 };
64 
66 
69  EXPECT_NE(d, nullptr);
70  int32_t state;
71  d->onComplete(3, state);
72  EXPECT_EQ(state, 10); // 10 = 6 + 3 + 1
73 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static void basic()
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void onComplete(int n, int &state)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
void onDelayedDestroy(bool delayed) override
state
Definition: http_parser.c:272