scoped_dispatch_object.h 840 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
  5. #define BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
  6. #include <dispatch/dispatch.h>
  7. #include "base/mac/scoped_typeref.h"
  8. namespace base {
  9. namespace internal {
  10. template <typename T>
  11. struct ScopedDispatchObjectTraits {
  12. static constexpr T InvalidValue() { return nullptr; }
  13. static T Retain(T object) {
  14. dispatch_retain(object);
  15. return object;
  16. }
  17. static void Release(T object) {
  18. dispatch_release(object);
  19. }
  20. };
  21. } // namepsace internal
  22. template <typename T>
  23. using ScopedDispatchObject =
  24. ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>;
  25. } // namespace base
  26. #endif // BASE_MAC_SCOPED_DISPATCH_OBJECT_H_