2 * Copyright (c) 2009-2011 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_IO_INTERNAL__
28 #define __DISPATCH_IO_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 #define _DISPATCH_IO_LABEL_SIZE 16
37 #ifndef DISPATCH_IO_DEBUG
38 #define DISPATCH_IO_DEBUG 0
41 #if TARGET_OS_EMBEDDED // rdar://problem/9032036
42 #define DIO_MAX_CHUNK_PAGES 128u // 512kB chunk size
44 #define DIO_MAX_CHUNK_PAGES 256u // 1024kB chunk size
47 #define DIO_DEFAULT_LOW_WATER_CHUNKS 1u // default low-water mark
48 #define DIO_MAX_PENDING_IO_REQS 6u // Pending I/O read advises
50 typedef unsigned int dispatch_op_direction_t
;
55 DOP_DIR_IGNORE
= UINT_MAX
,
58 typedef unsigned int dispatch_op_flags_t
;
59 #define DOP_DEFAULT 0u // check conditions to determine delivery
60 #define DOP_DELIVER 1u // always deliver operation
61 #define DOP_DONE 2u // operation is done (implies deliver)
62 #define DOP_STOP 4u // operation interrupted by chan stop (implies done)
63 #define DOP_NO_EMPTY 8u // don't deliver empty data
65 // dispatch_io_t atomic_flags
66 #define DIO_CLOSED 1u // channel has been closed
67 #define DIO_STOPPED 2u // channel has been stopped (implies closed)
69 #define _dispatch_io_data_retain(x) dispatch_retain(x)
70 #define _dispatch_io_data_release(x) dispatch_release(x)
73 #define _dispatch_io_debug(msg, fd, args...) \
74 _dispatch_debug("fd %d: " msg, (fd), ##args)
76 #define _dispatch_io_debug(msg, fd, args...)
79 DISPATCH_DECL(dispatch_operation
);
80 DISPATCH_DECL(dispatch_disk
);
82 struct dispatch_stream_s
{
84 dispatch_source_t source
;
85 dispatch_operation_t op
;
87 TAILQ_HEAD(, dispatch_operation_s
) operations
[2];
90 typedef struct dispatch_stream_s
*dispatch_stream_t
;
92 struct dispatch_io_path_data_s
{
93 dispatch_io_t channel
;
100 typedef struct dispatch_io_path_data_s
*dispatch_io_path_data_t
;
102 struct dispatch_stat_s
{
107 struct dispatch_disk_vtable_s
{
108 DISPATCH_VTABLE_HEADER(dispatch_disk_s
);
111 struct dispatch_disk_s
{
112 DISPATCH_STRUCT_HEADER(dispatch_disk_s
, dispatch_disk_vtable_s
);
114 TAILQ_HEAD(dispatch_disk_operations_s
, dispatch_operation_s
) operations
;
115 dispatch_operation_t cur_rq
;
116 dispatch_queue_t pick_queue
;
123 TAILQ_ENTRY(dispatch_disk_s
) disk_list
;
124 size_t advise_list_depth
;
125 dispatch_operation_t advise_list
[];
128 struct dispatch_fd_entry_s
{
130 dispatch_io_path_data_t path_data
;
131 int orig_flags
, orig_nosigpipe
, err
;
132 struct dispatch_stat_s stat
;
133 dispatch_stream_t streams
[2];
134 dispatch_disk_t disk
;
135 dispatch_queue_t close_queue
, barrier_queue
;
136 dispatch_group_t barrier_group
;
137 dispatch_io_t convenience_channel
;
138 TAILQ_HEAD(, dispatch_operation_s
) stream_ops
;
139 TAILQ_ENTRY(dispatch_fd_entry_s
) fd_list
;
142 typedef struct dispatch_fd_entry_s
*dispatch_fd_entry_t
;
144 typedef struct dispatch_io_param_s
{
145 dispatch_io_type_t type
; // STREAM OR RANDOM
149 unsigned long interval_flags
;
150 } dispatch_io_param_s
;
152 struct dispatch_operation_vtable_s
{
153 DISPATCH_VTABLE_HEADER(dispatch_operation_s
);
156 struct dispatch_operation_s
{
157 DISPATCH_STRUCT_HEADER(dispatch_operation_s
, dispatch_operation_vtable_s
);
158 dispatch_queue_t op_q
;
159 dispatch_op_direction_t direction
; // READ OR WRITE
160 dispatch_io_param_s params
;
164 dispatch_io_handler_t handler
;
165 dispatch_io_t channel
;
166 dispatch_fd_entry_t fd_entry
;
167 dispatch_source_t timer
;
172 dispatch_op_flags_t flags
;
173 size_t buf_siz
, buf_len
, undelivered
, total
;
174 dispatch_data_t buf_data
, data
;
175 TAILQ_ENTRY(dispatch_operation_s
) operation_list
;
176 // the request list in the fd_entry stream_ops
177 TAILQ_ENTRY(dispatch_operation_s
) stream_list
;
180 struct dispatch_io_vtable_s
{
181 DISPATCH_VTABLE_HEADER(dispatch_io_s
);
184 struct dispatch_io_s
{
185 DISPATCH_STRUCT_HEADER(dispatch_io_s
, dispatch_io_vtable_s
);
186 dispatch_queue_t queue
, barrier_queue
;
187 dispatch_group_t barrier_group
;
188 dispatch_io_param_s params
;
189 dispatch_fd_entry_t fd_entry
;
190 unsigned int atomic_flags
;
191 dispatch_fd_t fd
, fd_actual
;
193 int err
; // contains creation errors only
196 void _dispatch_io_set_target_queue(dispatch_io_t channel
, dispatch_queue_t dq
);
198 #endif // __DISPATCH_IO_INTERNAL__