ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


IOSharedDataQueue

Inherits from:
Declared In:

Overview

A generic queue designed to pass data both from the kernel to a user process and from a user process to the kernel.

Discussion

The IOSharedDataQueue class is designed to also allow a user process to queue data to kernel code. IOSharedDataQueue objects are designed to be used in a single producer / single consumer situation. As such, there are no locks on the data itself. Because the kernel enqueue and user-space dequeue methods follow a strict set of guidelines, no locks are necessary to maintain the integrity of the data struct.


Each data entry can be variable sized, but the entire size of the queue data region (including overhead for each entry) must be specified up front.


In order for the IODataQueue instance to notify the user process that data is available, a notification mach port must be set. When the queue is empty and a new entry is added, a message is sent to the specified port.


In order to make the data queue memory available to a user process, the method getMemoryDescriptor() must be used to get an IOMemoryDescriptor instance that can be mapped into a user process. Typically, the clientMemoryForType() method on an IOUserClient instance will be used to request the IOMemoryDescriptor and then return it to be mapped into the user process.



Functions

dequeue

Dequeues the next available entry on the queue and copies it into the given data pointer.

getMemoryDescriptor

Returns a memory descriptor covering the IODataQueueMemory region.

initWithCapacity

Initializes an IOSharedDataQueue instance with the capacity specified in the size parameter.

peek

Used to peek at the next entry on the queue.

withCapacity

Static method that creates a new IOSharedDataQueue instance with the capacity specified in the size parameter.

withEntries

Static method that creates a new IOSharedDataQueue instance with the specified number of entries of the given size.


dequeue


Dequeues the next available entry on the queue and copies it into the given data pointer.

public

virtual Boolean dequeue( void *data, UInt32 *dataSize);
Parameters
data

A pointer to the data memory region in which to copy the next entry data on the queue. If this parameter is 0 (NULL), it will simply move to the next entry.

dataSize

A pointer to the size of the data parameter. On return, this contains the size of the actual entry data - even if the original size was not large enough.

Return Value

Returns true on success and false on failure. Typically failure means that the queue is empty.

Discussion

This function will dequeue the next available entry on the queue. If a data pointer is provided, it will copy the data into the memory region if there is enough space available as specified in the dataSize parameter. If no data pointer is provided, it will simply move the head value past the current entry.


getMemoryDescriptor


Returns a memory descriptor covering the IODataQueueMemory region.

public

virtual IOMemoryDescriptor *getMemoryDescriptor();
Return Value

Returns a newly allocated IOMemoryDescriptor for the IODataQueueMemory region. Returns zero on failure.

Discussion

The IOMemoryDescriptor instance returned by this method is intended to be mapped into a user process. This is the memory region that the IODataQueueClient code operates on.


initWithCapacity


Initializes an IOSharedDataQueue instance with the capacity specified in the size parameter.

public

virtual Boolean initWithCapacity( UInt32 size);
Parameters
size

The size of the data queue memory region.

Return Value

Returns true on success and false on failure.

Discussion

The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE and DATA_QUEUE_MEMORY_APPENDIX_SIZE macro in . The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in .


peek


Used to peek at the next entry on the queue.

public

virtual IODataQueueEntry * peek();
Return Value

Returns a pointer to the next IODataQueueEntry if one is available. 0 (NULL) is returned if the queue is empty.

Discussion

This function can be used to look at the next entry which allows the entry to be received without having to copy it with dequeue. In order to do this, call peek to get the entry. Then call dequeue with a NULL data pointer. That will cause the head to be moved to the next entry, but no memory to be copied.


withCapacity


Static method that creates a new IOSharedDataQueue instance with the capacity specified in the size parameter.

public

static IOSharedDataQueue *withCapacity( UInt32 size);
Parameters
size

The size of the data queue memory region.

Return Value

Returns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.

Discussion

The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE macro in . The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in .
This method allocates a new IODataQueue instance and then calls initWithCapacity() with the given size parameter. If the initWithCapacity() fails, the new instance is released and zero is returned.


withEntries


Static method that creates a new IOSharedDataQueue instance with the specified number of entries of the given size.

public

static IOSharedDataQueue *withEntries( UInt32 numEntries, UInt32 entrySize);
Parameters
numEntries

Number of entries to allocate space for.

entrySize

Size of each entry.

Return Value

Reeturns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.

Discussion

This method will create a new IOSharedDataQueue instance with enough capacity for numEntries of entrySize. It does account for the IODataQueueEntry overhead for each entry. Note that the numEntries and entrySize are simply used to determine the data region size. They do not actually restrict the size of number of entries that can be added to the queue.
This method allocates a new IODataQueue instance and then calls initWithEntries() with the given numEntries and entrySize parameters. If the initWithEntries() fails, the new instance is released and zero is returned.

Member Data


_reserved


See Also:

reserved

protected

ExpansionData * _reserved;
Discussion

Reserved for future use. (Internal use only)


reserved


See Also:

_reserved

protected

ExpansionData * _reserved;
Discussion

Reserved for future use. (Internal use only)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19