2 * Copyright (c) 2009-2012 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
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.
27 #ifndef __DISPATCH_DATA_INTERNAL__
28 #define __DISPATCH_DATA_INTERNAL__
30 #ifndef __DISPATCH_INDIRECT__
31 #error "Please #include <dispatch/dispatch.h> instead of this file directly."
32 #include <dispatch/base.h> // for HeaderDoc
35 #if defined(__LP64__) && !defined(DISPATCH_DATA_USE_LEAF_MEMBER) && !USE_OBJC
36 // explicit leaf member is free on 64bit due to padding
37 #define DISPATCH_DATA_USE_LEAF_MEMBER 1
40 typedef struct range_record_s
{
41 dispatch_data_t data_object
;
47 #if OS_OBJECT_USE_OBJC
48 @interface
DISPATCH_CLASS(data
) : NSObject
<DISPATCH_CLASS(data
)>
51 DISPATCH_OBJC_CLASS_DECL(data
);
52 DISPATCH_OBJC_CLASS_DECL(data_empty
);
53 #define DISPATCH_DATA_CLASS DISPATCH_OBJC_CLASS(data)
54 #define DISPATCH_DATA_EMPTY_CLASS DISPATCH_OBJC_CLASS(data_empty)
56 DISPATCH_CLASS_DECL(data
);
57 #define DISPATCH_DATA_CLASS DISPATCH_VTABLE(data)
58 #define DISPATCH_DATA_EMPTY_CLASS DISPATCH_VTABLE(data)
61 struct dispatch_data_s
{
63 const void *do_vtable
;
64 dispatch_queue_t do_targetq
;
68 DISPATCH_STRUCT_HEADER(data
);
70 #if DISPATCH_DATA_USE_LEAF_MEMBER
73 dispatch_block_t destructor
;
74 size_t size
, num_records
;
77 range_record records
[0];
81 #if DISPATCH_DATA_USE_LEAF_MEMBER
82 #define _dispatch_data_leaf(d) ((d)->leaf)
83 #define _dispatch_data_num_records(d) ((d)->num_records)
85 #define _dispatch_data_leaf(d) ((d)->num_records ? 0 : ((d)->size ? 1 : 0))
86 #define _dispatch_data_num_records(d) \
87 (_dispatch_data_leaf(d) ? 1 : (d)->num_records)
88 #endif // DISPATCH_DATA_USE_LEAF_MEMBER
90 typedef dispatch_data_t (*dispatch_transform_t
)(dispatch_data_t data
);
92 struct dispatch_data_format_type_s
{
96 dispatch_transform_t decode
;
97 dispatch_transform_t encode
;
100 void dispatch_data_init(dispatch_data_t data
, const void *buffer
, size_t size
,
101 dispatch_block_t destructor
);
102 void _dispatch_data_dispose(dispatch_data_t data
);
103 size_t _dispatch_data_debug(dispatch_data_t data
, char* buf
, size_t bufsiz
);
104 const dispatch_block_t _dispatch_data_destructor_inline
;
105 #define DISPATCH_DATA_DESTRUCTOR_INLINE (_dispatch_data_destructor_inline)
109 static inline const void*
110 _dispatch_data_map_direct(dispatch_data_t dd
)
113 if (slowpath(!dd
->size
)) {
116 if (slowpath(!_dispatch_data_leaf(dd
)) &&
117 _dispatch_data_num_records(dd
) == 1 &&
118 _dispatch_data_leaf(dd
->records
[0].data_object
)) {
119 offset
= dd
->records
[0].from
;
120 dd
= dd
->records
[0].data_object
;
122 return fastpath(_dispatch_data_leaf(dd
)) ? (dd
->buf
+ offset
) : NULL
;
127 #endif // __DISPATCH_DATA_INTERNAL__