]> git.saurik.com Git - apple/libdispatch.git/blobdiff - src/io_internal.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / src / io_internal.h
index dbbb6bf6c8a1a97f2400546b60578daeeb095daa..672727fae6f574f0343f428b28a518804712f56e 100644 (file)
@@ -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@
  *
 
 #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_INTERNAL(dispatch_operation);
-DISPATCH_DECL_INTERNAL(dispatch_disk);
+DISPATCH_INTERNAL_CLASS_DECL(operation);
+DISPATCH_INTERNAL_CLASS_DECL(disk);
 
 struct dispatch_stream_s {
        dispatch_queue_t dq;
@@ -104,10 +94,8 @@ struct dispatch_stat_s {
        mode_t mode;
 };
 
-DISPATCH_CLASS_DECL(disk);
 struct dispatch_disk_s {
-       DISPATCH_STRUCT_HEADER(disk);
-       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;
@@ -115,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[];
@@ -126,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;
@@ -146,9 +140,8 @@ typedef struct dispatch_io_param_s {
        unsigned long interval_flags;
 } dispatch_io_param_s;
 
-DISPATCH_CLASS_DECL(operation);
 struct dispatch_operation_s {
-       DISPATCH_STRUCT_HEADER(operation);
+       DISPATCH_OBJECT_HEADER(operation);
        dispatch_queue_t op_q;
        dispatch_op_direction_t direction; // READ OR WRITE
        dispatch_io_param_s params;
@@ -160,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;
@@ -173,7 +165,7 @@ struct dispatch_operation_s {
 
 DISPATCH_CLASS_DECL(io);
 struct dispatch_io_s {
-       DISPATCH_STRUCT_HEADER(io);
+       DISPATCH_OBJECT_HEADER(io);
        dispatch_queue_t queue, barrier_queue;
        dispatch_group_t barrier_group;
        dispatch_io_param_s params;
@@ -185,8 +177,12 @@ struct dispatch_io_s {
 };
 
 void _dispatch_io_set_target_queue(dispatch_io_t channel, dispatch_queue_t dq);
-void _dispatch_io_dispose(dispatch_io_t channel);
-void _dispatch_operation_dispose(dispatch_operation_t operation);
-void _dispatch_disk_dispose(dispatch_disk_t disk);
+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__