2 * Copyright (c) 2009-2013 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 #if TARGET_OS_EMBEDDED // rdar://problem/9032036
38 #define DIO_MAX_CHUNK_SIZE (512u * 1024)
39 #define DIO_HASH_SIZE 64u // must be a power of two
41 #define DIO_MAX_CHUNK_SIZE (1024u * 1024)
42 #define DIO_HASH_SIZE 256u // must be a power of two
45 #define DIO_HASH(x) ((uintptr_t)(x) & (DIO_HASH_SIZE - 1))
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 DISPATCH_INTERNAL_CLASS_DECL(operation
);
70 DISPATCH_INTERNAL_CLASS_DECL(disk
);
72 struct dispatch_stream_s
{
74 dispatch_source_t source
;
75 dispatch_operation_t op
;
77 TAILQ_HEAD(, dispatch_operation_s
) operations
[2];
80 typedef struct dispatch_stream_s
*dispatch_stream_t
;
82 struct dispatch_io_path_data_s
{
83 dispatch_io_t channel
;
90 typedef struct dispatch_io_path_data_s
*dispatch_io_path_data_t
;
92 struct dispatch_stat_s
{
97 struct dispatch_disk_s
{
98 DISPATCH_OBJECT_HEADER(disk
);
99 TAILQ_HEAD(dispatch_disk_operations_s
, dispatch_operation_s
) operations
;
100 dispatch_operation_t cur_rq
;
101 dispatch_queue_t pick_queue
;
108 TAILQ_ENTRY(dispatch_disk_s
) disk_list
;
109 size_t advise_list_depth
;
110 dispatch_operation_t advise_list
[];
113 struct dispatch_fd_entry_s
{
115 dispatch_io_path_data_t path_data
;
116 int orig_flags
, orig_nosigpipe
, err
;
117 #if DISPATCH_USE_GUARDED_FD_CHANGE_FDGUARD
120 #if DISPATCH_USE_GUARDED_FD
121 unsigned int guard_flags
;
123 struct dispatch_stat_s stat
;
124 dispatch_stream_t streams
[2];
125 dispatch_disk_t disk
;
126 dispatch_queue_t close_queue
, barrier_queue
;
127 dispatch_group_t barrier_group
;
128 dispatch_io_t convenience_channel
;
129 TAILQ_HEAD(, dispatch_operation_s
) stream_ops
;
130 TAILQ_ENTRY(dispatch_fd_entry_s
) fd_list
;
133 typedef struct dispatch_fd_entry_s
*dispatch_fd_entry_t
;
135 typedef struct dispatch_io_param_s
{
136 dispatch_io_type_t type
; // STREAM OR RANDOM
140 unsigned long interval_flags
;
141 } dispatch_io_param_s
;
143 struct dispatch_operation_s
{
144 DISPATCH_OBJECT_HEADER(operation
);
145 dispatch_queue_t op_q
;
146 dispatch_op_direction_t direction
; // READ OR WRITE
147 dispatch_io_param_s params
;
151 dispatch_io_handler_t handler
;
152 dispatch_io_t channel
;
153 dispatch_fd_entry_t fd_entry
;
154 dispatch_source_t timer
;
158 dispatch_op_flags_t flags
;
159 size_t buf_siz
, buf_len
, undelivered
, total
;
160 dispatch_data_t buf_data
, data
;
161 TAILQ_ENTRY(dispatch_operation_s
) operation_list
;
162 // the request list in the fd_entry stream_ops
163 TAILQ_ENTRY(dispatch_operation_s
) stream_list
;
166 DISPATCH_CLASS_DECL(io
);
167 struct dispatch_io_s
{
168 DISPATCH_OBJECT_HEADER(io
);
169 dispatch_queue_t queue
, barrier_queue
;
170 dispatch_group_t barrier_group
;
171 dispatch_io_param_s params
;
172 dispatch_fd_entry_t fd_entry
;
173 unsigned int atomic_flags
;
174 dispatch_fd_t fd
, fd_actual
;
176 int err
; // contains creation errors only
179 void _dispatch_io_set_target_queue(dispatch_io_t channel
, dispatch_queue_t dq
);
180 size_t _dispatch_io_debug(dispatch_io_t channel
, char* buf
, size_t bufsiz
);
181 void _dispatch_io_dispose(dispatch_io_t channel
);
182 size_t _dispatch_operation_debug(dispatch_operation_t op
, char* buf
,
184 void _dispatch_operation_dispose(dispatch_operation_t operation
);
185 void _dispatch_disk_dispose(dispatch_disk_t disk
);
187 #endif // __DISPATCH_IO_INTERNAL__