X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/4452a7af2eac33dbad800bcc91f2399d62c18f53..7ddcb079202367355dddccdfa4318e57d50318be:/iokit/IOKit/IOWorkLoop.h diff --git a/iokit/IOKit/IOWorkLoop.h b/iokit/IOKit/IOWorkLoop.h index d2d8222d3..e248a9b3b 100644 --- a/iokit/IOKit/IOWorkLoop.h +++ b/iokit/IOKit/IOWorkLoop.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1998-2009 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -25,14 +25,6 @@ * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ -/* -Copyright (c) 1998 Apple Computer, Inc. All rights reserved. -HISTORY - 1998-7-13 Godfrey van der Linden(gvdl) - Created. - 1998-10-30 Godfrey van der Linden(gvdl) - Converted to C++ -*/ #ifndef __IOKIT_IOWORKLOOP_H #define __IOKIT_IOWORKLOOP_H @@ -44,6 +36,10 @@ HISTORY #include +#if IOKITSTATS +#include +#endif + class IOEventSource; class IOTimerEventSource; class IOCommandGate; @@ -78,13 +74,23 @@ member function's parameter list. typedef IOReturn (*Action)(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3); + enum { + kPreciousStack = 0x00000001 + }; private: /*! @function threadMainContinuation @abstract Static function that calls the threadMain function. */ static void threadMainContinuation(IOWorkLoop *self); - + +/*! @function eventSourcePerformsWork + @abstract Checks if the event source passed in overrides checkForWork() to perform any work. +IOWorkLoop uses this to determine if the event source should be polled in runEventSources() or not. + @param inEventSource The event source to check. +*/ + bool eventSourcePerformsWork(IOEventSource *inEventSource); + protected: /*! @typedef maintCommandEnum @@ -96,6 +102,7 @@ protected: /*! @var gateLock Mutual exclusion lock that is used by close and open Gate functions. + This is a recursive lock, which allows multiple layers of code to share a single IOWorkLoop without deadlock. This is common in IOKit since threads of execution tend to follow the service plane in the IORegistry, and multiple objects along the call path may acquire the gate for the same (shared) workloop. */ IORecursiveLock *gateLock; @@ -109,7 +116,7 @@ protected: */ IOCommandGate *controlG; -/*! @var workSpinLock +/*! @var workToDoLock The spin lock that is used to guard the 'workToDo' variable. */ IOSimpleLock *workToDoLock; @@ -132,7 +139,18 @@ protected: /*! @struct ExpansionData @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future. */ - struct ExpansionData { }; + struct ExpansionData { + IOOptionBits options; + IOEventSource *passiveEventChain; +#if DEBUG + void * allocationBacktrace[16]; +#endif /* DEBUG */ +#if IOKITSTATS + struct IOWorkLoopCounter *counter; +#else + void *iokitstatsReserved; +#endif + }; /*! @var reserved Reserved for future use. (Internal use only) @@ -167,13 +185,20 @@ protected: public: /*! @function workLoop - @abstract Factory member function to constuct and intialize a work loop. + @abstract Factory member function to construct and intialize a work loop. @result Returns a workLoop instance if constructed successfully, 0 otherwise. */ static IOWorkLoop *workLoop(); +/*! @function workLoopWithOptions(IOOptionBits options) + @abstract Factory member function to constuct and intialize a work loop. + @param options Options - kPreciousStack to avoid stack deallocation on paging path. + @result Returns a workLoop instance if constructed successfully, 0 otherwise. +*/ + static IOWorkLoop *workLoopWithOptions(IOOptionBits options); + /*! @function init - @discussion Initializes an instance of the workloop. This method creates and initialses the signaling semaphore and forks the thread that will continue executing. + @discussion Initializes an instance of the workloop. This method creates and initializes the signaling semaphore, the controller gate lock, and spawns the thread that will continue executing. @result Returns true if initialized successfully, false otherwise. */ virtual bool init(); @@ -224,13 +249,13 @@ public: /*! @function enableAllInterrupts @abstract Calls enable() in all interrupt event sources. - @discussion For all event sources (ES) for which IODynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call enable() function. See IOEventSource::enable(). + @discussion For all event sources (ES) for which OSDynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call enable() function. See IOEventSource::enable(). */ virtual void enableAllInterrupts() const; /*! @function disableAllInterrupts @abstract Calls disable() in all interrupt event sources. - @discussion For all event sources (ES) for which IODynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call disable() function. See IOEventSource::disable(). + @discussion For all event sources (ES) for which OSDynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call disable() function. See IOEventSource::disable(). */ virtual void disableAllInterrupts() const; @@ -239,6 +264,9 @@ protected: // Internal APIs used by event sources to control the thread friend class IOEventSource; friend class IOTimerEventSource; +#if IOKITSTATS + friend class IOStatistics; +#endif virtual void signalWorkAvailable(); virtual void openGate(); virtual void closeGate(); @@ -259,12 +287,10 @@ public: @param arg3 Parameter for action parameter, defaults to 0. @result Returns the value of the Action callout. */ - OSMetaClassDeclareReservedUsed(IOWorkLoop, 0); virtual IOReturn runAction(Action action, OSObject *target, void *arg0 = 0, void *arg1 = 0, void *arg2 = 0, void *arg3 = 0); -#if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT)) /*! @function runEventSources @discussion Consists of the inner 2 loops of the threadMain function(qv). The outer loop terminates when there is no more work, and the inside loop @@ -284,16 +310,22 @@ public: @result Return false if the work loop is shutting down, true otherwise. */ - OSMetaClassDeclareReservedUsed(IOWorkLoop, 1); virtual bool runEventSources(); -#endif protected: + // Internal APIs used by event sources to control the thread + virtual int sleepGate(void *event, AbsoluteTime deadline, UInt32 interuptibleType); -#if (defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT)) +protected: +#if __LP64__ + OSMetaClassDeclareReservedUnused(IOWorkLoop, 0); OSMetaClassDeclareReservedUnused(IOWorkLoop, 1); -#endif OSMetaClassDeclareReservedUnused(IOWorkLoop, 2); +#else + OSMetaClassDeclareReservedUsed(IOWorkLoop, 0); + OSMetaClassDeclareReservedUsed(IOWorkLoop, 1); + OSMetaClassDeclareReservedUsed(IOWorkLoop, 2); +#endif OSMetaClassDeclareReservedUnused(IOWorkLoop, 3); OSMetaClassDeclareReservedUnused(IOWorkLoop, 4); OSMetaClassDeclareReservedUnused(IOWorkLoop, 5);