• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
6 #define BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
7 
8 #include <dispatch/dispatch.h>
9 
10 #include "base/mac/scoped_typeref.h"
11 
12 namespace base {
13 
14 namespace internal {
15 
16 template <typename T>
17 struct ScopedDispatchObjectTraits {
InvalidValueScopedDispatchObjectTraits18   static T InvalidValue() { return nullptr; }
RetainScopedDispatchObjectTraits19   static T Retain(T object) {
20     dispatch_retain(object);
21     return object;
22   }
ReleaseScopedDispatchObjectTraits23   static void Release(T object) {
24     dispatch_release(object);
25   }
26 };
27 
28 }  // namepsace internal
29 
30 template <typename T>
31 using ScopedDispatchObject =
32     ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>;
33 
34 }  // namespace base
35 
36 #endif  // BASE_MAC_SCOPED_DISPATCH_OBJECT_H_
37