/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <memory> #include <folly/io/async/DelayedDestructionBase.h> namespace folly { /** * DelayedDestruction is a helper class to ensure objects are not deleted * while they still have functions executing in a higher stack frame. * * This is useful for objects that invoke callback functions, to ensure that a * callback does not destroy the calling object. * * Classes needing this functionality should: * - derive from DelayedDestruction * - make their destructor private or protected, so it cannot be called * directly * - create a DestructorGuard object on the stack in each public method that * may invoke a callback * * DelayedDestruction does not perform any locking. It is intended to be used * only from a single thread. */ class DelayedDestruction : public DelayedDestructionBase { … }; DelayedDestructionUniquePtr; template <typename T, typename... A> DelayedDestructionUniquePtr<T> makeDelayedDestructionUniquePtr(A&&... a) { … } } // namespace folly