xref: /NextBSD/lib/libdispatch/os/object_private.h (revision 33da5adc555b3bc29986eeadca03829e4ad06b1e)
1 /*
2  * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
3  *
4  * @APPLE_APACHE_LICENSE_HEADER_START@
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * @APPLE_APACHE_LICENSE_HEADER_END@
19  */
20 
21 /*
22  * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23  * which are subject to change in future releases of Mac OS X. Any applications
24  * relying on these interfaces WILL break.
25  */
26 
27 #ifndef __OS_OBJECT_PRIVATE__
28 #define __OS_OBJECT_PRIVATE__
29 
30 #include <sys/cdefs.h>
31 #include <stddef.h>
32 #include <os/object.h>
33 
34 #ifndef __OSX_AVAILABLE_STARTING
35 #define __OSX_AVAILABLE_STARTING(x, y)
36 #endif
37 
38 #if __GNUC__
39 #define OS_OBJECT_NOTHROW __attribute__((__nothrow__))
40 #define OS_OBJECT_NONNULL __attribute__((__nonnull__))
41 #define OS_OBJECT_WARN_RESULT __attribute__((__warn_unused_result__))
42 #define OS_OBJECT_MALLOC __attribute__((__malloc__))
43 #define OS_OBJECT_EXPORT extern __attribute__((visibility("default")))
44 #else
45 /*! @parseOnly */
46 #define OS_OBJECT_NOTHROW
47 /*! @parseOnly */
48 #define OS_OBJECT_NONNULL
49 /*! @parseOnly */
50 #define OS_OBJECT_WARN_RESULT
51 /*! @parseOnly */
52 #define OS_OBJECT_MALLOC
53 #define OS_OBJECT_EXPORT extern
54 #endif
55 
56 #if OS_OBJECT_USE_OBJC && defined(__has_feature)
57 #if __has_feature(objc_arc)
58 #define _OS_OBJECT_OBJC_ARC 1
59 #else
60 #define _OS_OBJECT_OBJC_ARC 0
61 #endif
62 #else
63 #define _OS_OBJECT_OBJC_ARC 0
64 #endif
65 
66 #define _OS_OBJECT_GLOBAL_REFCNT INT_MAX
67 
68 #define _OS_OBJECT_HEADER(isa, ref_cnt, xref_cnt) \
69         isa; /* must be pointer-sized */ \
70         int volatile ref_cnt; \
71         int volatile xref_cnt
72 
73 #if OS_OBJECT_HAVE_OBJC_SUPPORT
74 // Must match size of compiler-generated OBJC_CLASS structure rdar://10640168
75 #define _OS_OBJECT_CLASS_HEADER() \
76 		void *_os_obj_objc_class_t[5]
77 #else
78 #define _OS_OBJECT_CLASS_HEADER() \
79 		void (*_os_obj_xref_dispose)(_os_object_t); \
80 		void (*_os_obj_dispose)(_os_object_t)
81 #endif
82 
83 #define OS_OBJECT_CLASS(name) OS_##name
84 
85 #if OS_OBJECT_USE_OBJC
86 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
87 OS_OBJECT_EXPORT
88 @interface OS_OBJECT_CLASS(object) : NSObject
89 - (void)_xref_dispose;
90 - (void)_dispose;
91 @end
92 typedef OS_OBJECT_CLASS(object) *_os_object_t;
93 #define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
94 		@interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
95 		<OS_OBJECT_CLASS(name)> \
96 		@end
97 #else
98 typedef struct _os_object_s *_os_object_t;
99 #endif
100 
101 __BEGIN_DECLS
102 
103 #if !_OS_OBJECT_OBJC_ARC
104 
105 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
106 OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
107 _os_object_t
108 _os_object_alloc(const void *cls, size_t size);
109 
110 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
111 OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
112 _os_object_t
113 _os_object_alloc_realized(const void *cls, size_t size);
114 
115 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
116 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
117 void _os_object_dealloc(_os_object_t object);
118 
119 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
120 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
121 _os_object_t
122 _os_object_retain(_os_object_t object);
123 
124 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
125 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
126 void
127 _os_object_release(_os_object_t object);
128 
129 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
130 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
131 _os_object_t
132 _os_object_retain_internal(_os_object_t object);
133 
134 __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
135 OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
136 void
137 _os_object_release_internal(_os_object_t object);
138 
139 #endif // !_OS_OBJECT_OBJC_ARC
140 
141 __END_DECLS
142 
143 #endif
144