IOWorkLoop



Member Functions

_maintRequest

Abstract: Synchrounous implementation of $link addEventSource & $link removeEventSource functions.
protected:

virtual IOReturn _maintRequest(void *command, void *data, void *, void *);


addEventSource

public:

virtual IOReturn addEventSource(IOEventSource *newEvent);

Add an event source to be monitored by the work loop. This function does not return until the work loop has acknowledged the arrival of the new event source. When a new event has been added the threadMain will always restart it's loop and check all outstanding events. The event source is retained by the work loop

Parameters

NameDescription
newEventPointer to $link IOEventSource subclass to add.
Result: Always returns kIOReturnSuccess.

closeGate

Abstract: Close the single-threading gate
public:

virtual void closeGate();


disableAllEventSources

Abstract: Call disable() in all event sources
public:

virtual void disableAllEventSources() const;

For all event sources in $link eventChain call disable() function. See $link IOEventSource::disable()


disableAllInterrupts

Abstract: Call disable() in all interrupt event sources
public:

virtual void disableAllInterrupts() const;

For all event sources, ES, for which IODynamicCast(IOInterruptEventSource, ES) is valid, in $link eventChain call disable() function. See $link IOEventSource::disable()


enableAllEventSources

Abstract: Call enable() in all event sources
public:

virtual void enableAllEventSources() const;

For all event sources in $link eventChain call enable() function. See $link IOEventSource::enable()


enableAllInterrupts

Abstract: Call enable() in all interrupt event sources
public:

virtual void enableAllInterrupts() const;

For all event sources, ES, for which IODynamicCast(IOInterruptEventSource, ES) is valid, in $link eventChain call enable() function. See $link IOEventSource::enable()


free

protected:

virtual void free();

Mandatory free of the object independent of the current retain count. If the work loop is running this method will not return until the thread has succefully terminated. Each event source in the chain will be released and the working semaphore will be destroyed.

If the client has some outstanding requests on an event they will never be informed of completion. If an external thread is blocked on any of the event sources they will be awoken with a KERN_INTERUPTED status.


free

Abstract: Sub-class implementation of free method, frees calloutEntry
public:

virtual void signalWorkAvailable();


getThread

Abstract: Get'ter for $link workThread.
public:

virtual IOThread getThread() const;

Result: Returns workThread

inGate

Abstract: Is the current execution context holding the work-loop's gate?
public:

virtual bool inGate() const;

Result: Returns true if IOThreadSelf() is gate holder.

init

public:

virtual bool init();

Result: true if initialised successfully, false otherwise.

launchThreadMain

Abstract: Static function that just calls the $link threadMain function.
private:

static void launchThreadMain(void *self);


onThread

Abstract: Is the current execution context on the work thread?
public:

virtual bool onThread() const;

Result: Returns true if IOThreadSelf() == workThread.

openGate

Abstract: Open the single-threading gate
public:

virtual void openGate();


removeEventSource

public:

virtual IOReturn removeEventSource(IOEventSource *toRemove);

Remove an event source from the work loop. This function does not return until the work loop has acknowledged the removal of the event source. When an event has been removed the threadMain will always restart it's loop and check all outstanding events. The event source will be released before return.

Parameters

NameDescription
toRemovePointer to $link IOEventSource subclass to remove.
Result: kIOReturnSuccess if successful, kIOReturnBadArgument if toRemove couldn't be found.

threadMain

protected:

virtual void threadMain();

Work loop threads main function. This function consists of 3 loops: the outermost loop is the semaphore clear and wait loop, the middle loop terminates when there is no more work and the inside loop walks the event list calling the $link checkForWork method in each event source. If an event source has more work to do then it can set the more flag and the middle loop will repeat. When no more work is outstanding the outermost will sleep until and event is signaled or the least wakeupTime whichever occurs first. If the event source does not require the semaphore wait to time out it must set the provided wakeupTime parameter to zero.


workLoop

Abstract: Factory member function to constuct and intialise a work loop.
public:

static IOWorkLoop *workLoop();

Result: workLoop instance if constructed successfully, 0 otherwise.

Member Data

controlG

protected:
 IOCommandGate *controlG;

Internal control gate to maintain event system.


eventChain

protected:
 IOEventSource *eventChain;

Pointer to first Event Source in linked list.


gateLock

protected:
 IORecursiveLock *gateLock;

Mutual exlusion lock that used by close and open Gate functions.


loopRestart

protected:
 bool loopRestart;

If event chain has been changed and the system has to be rechecked from start this flag is set. (Internal use only)


maintCommandEnum

protected:
  typedef  enum  {  mAddEvent,  mRemoveEvent  }  maintCommandEnum;

Enumeration of commands that $link _maintCommand can deal with.


workSemaphore

protected:
 semaphore_port_t workSemaphore;

The semaphore that is used to signal the work loop when some event has been 'produced'.


workThread

protected:
 IOThread workThread;

Work loop thread.


© 2000 Apple Computer, Inc. — (Last Updated 2/23/2000)