X-Git-Url: https://git.saurik.com/apple/libdispatch.git/blobdiff_plain/e85f44377864e428703fb21503e29f422c11288f..refs/heads/master:/src/io_internal.h diff --git a/src/io_internal.h b/src/io_internal.h index c43bd75..672727f 100644 --- a/src/io_internal.h +++ b/src/io_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2011 Apple Inc. All rights reserved. + * Copyright (c) 2009-2013 Apple Inc. All rights reserved. * * @APPLE_APACHE_LICENSE_HEADER_START@ * @@ -34,16 +34,16 @@ #define _DISPATCH_IO_LABEL_SIZE 16 -#ifndef DISPATCH_IO_DEBUG -#define DISPATCH_IO_DEBUG 0 -#endif - #if TARGET_OS_EMBEDDED // rdar://problem/9032036 -#define DIO_MAX_CHUNK_PAGES 128u // 512kB chunk size +#define DIO_MAX_CHUNK_SIZE (512u * 1024) +#define DIO_HASH_SIZE 64u // must be a power of two #else -#define DIO_MAX_CHUNK_PAGES 256u // 1024kB chunk size +#define DIO_MAX_CHUNK_SIZE (1024u * 1024) +#define DIO_HASH_SIZE 256u // must be a power of two #endif +#define DIO_HASH(x) ((uintptr_t)(x) & (DIO_HASH_SIZE - 1)) + #define DIO_DEFAULT_LOW_WATER_CHUNKS 1u // default low-water mark #define DIO_MAX_PENDING_IO_REQS 6u // Pending I/O read advises @@ -66,18 +66,8 @@ typedef unsigned int dispatch_op_flags_t; #define DIO_CLOSED 1u // channel has been closed #define DIO_STOPPED 2u // channel has been stopped (implies closed) -#define _dispatch_io_data_retain(x) dispatch_retain(x) -#define _dispatch_io_data_release(x) dispatch_release(x) - -#if DISPATCH_IO_DEBUG -#define _dispatch_io_debug(msg, fd, args...) \ - _dispatch_debug("fd %d: " msg, (fd), ##args) -#else -#define _dispatch_io_debug(msg, fd, args...) -#endif - -DISPATCH_DECL(dispatch_operation); -DISPATCH_DECL(dispatch_disk); +DISPATCH_INTERNAL_CLASS_DECL(operation); +DISPATCH_INTERNAL_CLASS_DECL(disk); struct dispatch_stream_s { dispatch_queue_t dq; @@ -104,13 +94,8 @@ struct dispatch_stat_s { mode_t mode; }; -struct dispatch_disk_vtable_s { - DISPATCH_VTABLE_HEADER(dispatch_disk_s); -}; - struct dispatch_disk_s { - DISPATCH_STRUCT_HEADER(dispatch_disk_s, dispatch_disk_vtable_s); - dev_t dev; + DISPATCH_OBJECT_HEADER(disk); TAILQ_HEAD(dispatch_disk_operations_s, dispatch_operation_s) operations; dispatch_operation_t cur_rq; dispatch_queue_t pick_queue; @@ -118,8 +103,8 @@ struct dispatch_disk_s { size_t free_idx; size_t req_idx; size_t advise_idx; + dev_t dev; bool io_active; - int err; TAILQ_ENTRY(dispatch_disk_s) disk_list; size_t advise_list_depth; dispatch_operation_t advise_list[]; @@ -129,6 +114,12 @@ struct dispatch_fd_entry_s { dispatch_fd_t fd; dispatch_io_path_data_t path_data; int orig_flags, orig_nosigpipe, err; +#if DISPATCH_USE_GUARDED_FD_CHANGE_FDGUARD + int orig_fd_flags; +#endif +#if DISPATCH_USE_GUARDED_FD + unsigned int guard_flags; +#endif struct dispatch_stat_s stat; dispatch_stream_t streams[2]; dispatch_disk_t disk; @@ -149,12 +140,8 @@ typedef struct dispatch_io_param_s { unsigned long interval_flags; } dispatch_io_param_s; -struct dispatch_operation_vtable_s { - DISPATCH_VTABLE_HEADER(dispatch_operation_s); -}; - struct dispatch_operation_s { - DISPATCH_STRUCT_HEADER(dispatch_operation_s, dispatch_operation_vtable_s); + DISPATCH_OBJECT_HEADER(operation); dispatch_queue_t op_q; dispatch_op_direction_t direction; // READ OR WRITE dispatch_io_param_s params; @@ -166,7 +153,6 @@ struct dispatch_operation_s { dispatch_fd_entry_t fd_entry; dispatch_source_t timer; bool active; - int count; off_t advise_offset; void* buf; dispatch_op_flags_t flags; @@ -177,12 +163,9 @@ struct dispatch_operation_s { TAILQ_ENTRY(dispatch_operation_s) stream_list; }; -struct dispatch_io_vtable_s { - DISPATCH_VTABLE_HEADER(dispatch_io_s); -}; - +DISPATCH_CLASS_DECL(io); struct dispatch_io_s { - DISPATCH_STRUCT_HEADER(dispatch_io_s, dispatch_io_vtable_s); + DISPATCH_OBJECT_HEADER(io); dispatch_queue_t queue, barrier_queue; dispatch_group_t barrier_group; dispatch_io_param_s params; @@ -194,5 +177,12 @@ struct dispatch_io_s { }; void _dispatch_io_set_target_queue(dispatch_io_t channel, dispatch_queue_t dq); +size_t _dispatch_io_debug(dispatch_io_t channel, char* buf, size_t bufsiz); +void _dispatch_io_dispose(dispatch_io_t channel, bool *allow_free); +size_t _dispatch_operation_debug(dispatch_operation_t op, char* buf, + size_t bufsiz); +void _dispatch_operation_dispose(dispatch_operation_t operation, + bool *allow_free); +void _dispatch_disk_dispose(dispatch_disk_t disk, bool *allow_free); #endif // __DISPATCH_IO_INTERNAL__