/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <assert.h>
#include <cstddef>
+#include <cstdint>
+#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
+
#include <boost/noncopyable.hpp>
-#include <functional>
#include <glog/logging.h>
-#include <inttypes.h>
namespace folly {
*
* Classes needing this functionality should:
* - derive from DelayedDestructionBase directly
- * - pass a callback to onDestroy_ which'll be called before the object is
+ * - implement onDelayedDestroy which'll be called before the object is
* going to be destructed
* - create a DestructorGuard object on the stack in each public method that
* may invoke a callback
assert(dd_->guardCount_ > 0);
--dd_->guardCount_;
if (dd_->guardCount_ == 0) {
- dd_->onDestroy_(true);
+ dd_->onDelayedDestroy(true);
}
}
}
}
/**
- * Implement onDestroy_ in subclasses.
- * onDestroy_() is invoked when the object is potentially being destroyed.
+ * Implement onDelayedDestroy in subclasses.
+ * onDelayedDestroy() is invoked when the object is potentially being
+ * destroyed.
*
* @param delayed This parameter is true if destruction was delayed because
- * of a DestructorGuard object, or false if onDestroy_() is
- * being called directly from the destructor.
+ * of a DestructorGuard object, or false if onDelayedDestroy()
+ * is being called directly from the destructor.
*/
- std::function<void(bool)> onDestroy_;
+ virtual void onDelayedDestroy(bool delayed) = 0;
private:
/**
const DelayedDestructionBase::DestructorGuard& right) {
return left.get() != right.get();
}
-inline bool operator ==(
+inline bool operator==(
const DelayedDestructionBase::DestructorGuard& left,
- std::nullptr_t right) {
- return left.get() == right;
+ std::nullptr_t) {
+ return left.get() == nullptr;
}
-inline bool operator ==(
- std::nullptr_t left,
+inline bool operator==(
+ std::nullptr_t,
const DelayedDestructionBase::DestructorGuard& right) {
- return left == right.get();
+ return nullptr == right.get();
}
-inline bool operator !=(
+inline bool operator!=(
const DelayedDestructionBase::DestructorGuard& left,
- std::nullptr_t right) {
- return left.get() != right;
+ std::nullptr_t) {
+ return left.get() != nullptr;
}
-inline bool operator !=(
- std::nullptr_t left,
+inline bool operator!=(
+ std::nullptr_t,
const DelayedDestructionBase::DestructorGuard& right) {
- return left != right.get();
+ return nullptr != right.get();
}
template <typename LeftAliasType, typename RightAliasType>
return left.get() != right.get();
}
template <typename LeftAliasType>
-inline bool operator ==(
+inline bool operator==(
const DelayedDestructionBase::IntrusivePtr<LeftAliasType>& left,
- std::nullptr_t right) {
- return left.get() == right;
+ std::nullptr_t) {
+ return left.get() == nullptr;
}
template <typename RightAliasType>
-inline bool operator ==(
- std::nullptr_t left,
+inline bool operator==(
+ std::nullptr_t,
const DelayedDestructionBase::IntrusivePtr<RightAliasType>& right) {
- return left == right.get();
+ return nullptr == right.get();
}
template <typename LeftAliasType>
-inline bool operator !=(
+inline bool operator!=(
const DelayedDestructionBase::IntrusivePtr<LeftAliasType>& left,
- std::nullptr_t right) {
- return left.get() != right;
+ std::nullptr_t) {
+ return left.get() != nullptr;
}
template <typename RightAliasType>
-inline bool operator !=(
- std::nullptr_t left,
+inline bool operator!=(
+ std::nullptr_t,
const DelayedDestructionBase::IntrusivePtr<RightAliasType>& right) {
- return left != right.get();
+ return nullptr != right.get();
}
-} // folly
+} // namespace folly