System Worker Threads

来源:互联网 发布:网络查询名下有无公司 编辑:程序博客网 时间:2024/06/05 15:45

http://msdn.microsoft.com/zh-cn/library/ff564587.aspx

先翻译成自己能看懂的。。。

 

 

 

To use a work item, a driver performs the following steps:

  1. Allocate and initialize a new work item.

    The system uses an IO_WORKITEM structure to hold a work item. To allocate a new IO_WORKITEM structure and initialize it as a work item, the driver can call IoAllocateWorkItem. In Windows Vista and later versions of Windows, the driver can alternatively allocate its own IO_WORKITEM structure, and callIoInitializeWorkItem to initialize the structure as a work item. (The driver should call IoSizeofWorkItem to determine the number of bytes that are necessary to hold a work item.)

     

    分配和初始化一个新的工作.

    操作系统使用IO_WORKITEM结构来表示一个工作节点,驱动程序可以调用IoAllocateWorkItem来分配和初始化一个工作节点.

    在windows vista及其后续版本中,驱动程序可以选择先为自己分配IO_WORKITEM结构再调用IoInitializeWorkItem来初始化一个工作节点.(程序可以调用IoSizeofWorkItem来获取一个工作结构的大小.)

     

  2. Associate a callback routine with the work item, and queue the work item so that it will be processed by a system worker thread.

    To associate a WorkItem routine with the work item and queue the work item, the driver should call IoQueueWorkItem. To instead associate a WorkItemExroutine with the work item and queue the work item, the driver should call IoQueueWorkItemEx.

     

    然后要将一个回调函数与工作节点绑定起来并插入到系统工作队列中,程序可以调用IoQueueWorkItem来完成这个.但是如果程序是使用WorkItemEx来表示工作节点的话就要使用IoQueueWorkItemEx来绑定和插入到系统工作队列里.

     

  3. After the work item is no longer required, free it.

    A work item that was allocated by IoAllocateWorkItem should be freed by IoFreeWorkItem. A work item that was initialized by IoInitializeWorkItem must be uninitialized by IoUninitializeWorkItem before it can be freed.

    The work item can only be uninitialized or freed when the work item is not currently queued. The system dequeues the work item before it calls the work item's callback routine, so IoFreeWorkItem and IoUninitializeWorkItem can be called from within the callback.

     

    在工作节点不再需要后,要记得释放掉,被IoAllocateWorkItem分配的工作节点可以使用IoFreeWorkItem.被IoInitializeWorkItem初始化的工作节点要在其释放前调用IoUninitializeWorkItem.只有在工作节点没有被正确的插入到队列时才可以调用这些函数来释放它.如果成功插入队列以后,操作系统自己会在调用完该节点的回调函数后会将该节点移出队列.所以可以在回调函数里调用IoFreeWorkItem和IoUninitializedWorkItem来释放工作节点.

     

 

 

 

 

原创粉丝点击