Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | /* * Copyright (c) 2019-2019 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef _IOKIT_UIODISPATCHQUEUE_H #define _IOKIT_UIODISPATCHQUEUE_H #include <DriverKit/OSObject.iig> #include <DriverKit/OSAction.iig> #include <DriverKit/IODispatchSource.iig> typedef int (*IODispatchLogFunction)(const char *format, ...); typedef void (^IODispatchBlock)(void); typedef void (*IODispatchFunction)(void * context); typedef void (^IODispatchQueueCancelHandler)(void); /*! * @class IODispatchQueue * * @abstract * IODispatchQueue provides a queue for ordered execution of blocks. * * @discussion * All blocks submitted to dispatch queues are dequeued in FIFO order. * By default the queue is serial and will execute one block at a time. */ class NATIVE KERNEL IODispatchQueue : public OSObject { public: /*! * @brief Creates a new dispatch queue object. * @discussion Creates a new dispatch queue object. All queues are currently serial, executing one block at time * FIFO order. The new object has retain count 1 and should be released by the caller. * @param options No options are currently defined, pass zero. * @param priority No priorities are currently defined, pass zero. * @return kIOReturnSuccess on success. See IOReturn.h for error codes. */ static kern_return_t Create( const IODispatchQueueName name, uint64_t options, uint64_t priority, IODispatchQueue ** queue) LOCAL; virtual bool init() override; virtual void free() override; /*! * @brief Determines if the current thread is running on the queue. * @discussion Determines if the current thread is running on the queue, including if the queue invoked a * second queue (ie. OnQueue can return true for more than one queue in a given context.) * @return bool true if current thread is running on this queue. */ bool OnQueue() LOCALONLY; /*! * @brief Return the name the queue was created with. * @discussion Returns a pointer to the queues name. Only valid while the queue is retained. * @return C-string pointer in the queues internal storage. */ const char * GetName() LOCALONLY; /*! * @brief Stop the queue from executing futher work. * @discussion Stops the queue from dequeuing work, and on completion of any block currently being executed, * invokes a callback block. Canceling is asynchronous. * @param handler Block that will executed when the queue has completed any inflight work * and will not execute further work. * @return C-string pointer in the queues internal storage. */ kern_return_t Cancel(IODispatchQueueCancelHandler handler) LOCALONLY; /*! * @brief Schedule a block to be executed on the queue asynchronously. * @discussion Schedules work to be done on the queue without waiting for it to complete. The queue will be * retained until the block completes. * @param block Block that will executed on the queue, not in the context of the caller. */ void DispatchAsync(IODispatchBlock block) LOCALONLY; /*! * @brief C-function callback version of DispatchAsync. */ void DispatchAsync_f(void * context, IODispatchFunction function) LOCALONLY; void DispatchSync(IODispatchBlock block) LOCALONLY; /*! * @brief C-function callback version of DispatchSync. */ void DispatchSync_f(void * context, IODispatchFunction function) LOCALONLY; /*! * @brief Log the current execution context with respect to any queues the current thread holds. * @param output printf like output function. The address of IOLog is suitable to be used. */ static void Log(const char * message, IODispatchLogFunction output) LOCALONLY; }; #if DRIVERKIT_PRIVATE class EXTENDS (IODispatchQueue) IODispatchQueuePrivate { virtual kern_return_t SetPort( mach_port_t port PORTMAKESEND); }; #endif #endif /* ! _IOKIT_UIODISPATCH_H */ |