当前位置: 首页 > news >正文

KiActivateWaiterQueue函数和Queue->Header.WaitListHead队列等待列表的关系

   
 

第一部分:
            if (Thread->ApcState.KernelApcPending &&
                (Thread->SpecialApcDisable == 0) &&
                (Thread->WaitIrql < APC_LEVEL)) {

            } else {


                //
                // Insert wait block in object wait list.
                //

                InsertTailList(&Queue->Header.WaitListHead, &WaitBlock->WaitListEntry);


VOID
FORCEINLINE
InsertTailList(
    IN PLIST_ENTRY ListHead,
    IN PLIST_ENTRY Entry
    )
{
    PLIST_ENTRY Blink;

    Blink = ListHead->Blink;
    Entry->Flink = ListHead;
    Entry->Blink = Blink;
    Blink->Flink = Entry;
    ListHead->Blink = Entry;
}

//LIFO队列


第二部分:


NTSTATUS
KeDelayExecutionThread (
    IN KPROCESSOR_MODE WaitMode,
    IN BOOLEAN Alertable,
    IN PLARGE_INTEGER Interval
    )
{


            //
            // If the current thread is processing a queue entry, then attempt
            // to activate another thread that is blocked on the queue object.
            //

            Queue = Thread->Queue;
            if (Queue != NULL) {
                KiActivateWaiterQueue(Queue);
            }


NTSTATUS
KeWaitForMultipleObjects (
    IN ULONG Count,
    IN PVOID Object[],
    IN WAIT_TYPE WaitType,
    IN KWAIT_REASON WaitReason,
    IN KPROCESSOR_MODE WaitMode,
    IN BOOLEAN Alertable,
    IN PLARGE_INTEGER Timeout OPTIONAL,
    IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
    )
{
            //
            // If the current thread is processing a queue entry, then attempt
            // to activate another thread that is blocked on the queue object.
            //

            Queue = Thread->Queue;
            if (Queue != NULL) {
                KiActivateWaiterQueue(Queue);
            }

NTSTATUS
KeWaitForSingleObject (
    IN PVOID Object,
    IN KWAIT_REASON WaitReason,
    IN KPROCESSOR_MODE WaitMode,
    IN BOOLEAN Alertable,
    IN PLARGE_INTEGER Timeout OPTIONAL
    )
{
              //
            // If the current thread is processing a queue entry, then attempt
            // to activate another thread that is blocked on the queue object.
            //

            Queue = Thread->Queue;
            if (Queue != NULL) {
                KiActivateWaiterQueue(Queue);
            }

第三部分:

FORCEINLINE
VOID
KiActivateWaiterQueue (
    IN PRKQUEUE Queue
    )

/*++

Routine Description:

    This function is called when the current thread is about to enter a
    wait state and is currently processing a queue entry. The current
    number of threads processign entries for the queue is decrement and
    an attempt is made to activate another thread if the current count
    is less than the maximum count, there is a waiting thread, and the
    queue is not empty.

    N.B. It is possible that this function is called on one processor
         holding the dispatcher database lock while the state of the
         specified queue object is being modified on another processor
         while holding only the queue object lock. This does not cause
         a problem since holding the queue object lock ensures that
         there are no waiting threads.

Arguments:

    Queue - Supplies a pointer to a dispatcher object of type event.

Return Value:

    None.

--*/

{

    PRLIST_ENTRY Entry;
    PRKTHREAD Thread;
    PRKWAIT_BLOCK WaitBlock;
    PRLIST_ENTRY WaitEntry;

    //
    // Decrement the current count of active threads and check if another
    // thread can be activated. If the current number of active threads is
    // less than the target maximum number of threads, there is a entry in
    // in the queue, and a thread is waiting, then remove the entry from the
    // queue, decrement the number of entries in the queue, and unwait the
    // respectiive thread.
    //

    Queue->CurrentCount -= 1;
    if (Queue->CurrentCount < Queue->MaximumCount) {
        Entry = Queue->EntryListHead.Flink;
        WaitEntry = Queue->Header.WaitListHead.Blink;//LIFO队列
        if ((Entry != &Queue->EntryListHead) &&
            (WaitEntry != &Queue->Header.WaitListHead)) {

            RemoveEntryList(Entry);
            Entry->Flink = NULL;
            Queue->Header.SignalState -= 1;
            WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
            Thread = WaitBlock->Thread;
            KiUnwaitThread(Thread, (LONG_PTR)Entry, 0);
        }
    }

    return;
}

http://www.dtcms.com/a/128868.html

相关文章:

  • 【第三章】13-常用模块1-ngx_http_upstream_module
  • Introduction To Raymarching
  • AI结合VBA提升EXCEL办公效率尝试
  • SQL:Relationship(关系)
  • 类似东郊到家的上门按摩预约服务系统小程序APP源码全开源
  • 3.5 字典补充
  • Google 官方提示工程 (Prompt Engineering)白皮书 总结
  • ESP32与STM32哪种更适合初学者?
  • Qt触摸屏隐藏鼠标指针
  • Python数组(array)学习之旅:数据结构的奇妙冒险
  • DRM(Digital Rights Management)生态以及架构介绍
  • 自动驾驶技术-相机_IMU时空标定
  • NI的LABVIEW工具安装及卸载步骤说明
  • 博途 TIA Portal之1200做主站与有意思的板子做MODBUS_RTU通讯
  • 【多模态大模型实战】使用LoRA微调Qwen2.5-VL
  • ESP32+Arduino入门(三):连接WIFI获取当前时间
  • 埃隆·马斯克与开源:通过协作重塑创新
  • Python 中 `__init__` 方法的深入解析
  • Java工具类-assert断言
  • 嵌入式人工智能应用-第三章 opencv操作3 图像平滑操作 下
  • Linux 内存调优之系统内存全面监控
  • 教程:在Typora中显示拼音——附处理工具
  • 学术版 GPT 网页
  • 电商用户购物行为分析:基于K-Means聚类与分类验证的完整流程
  • Linux dmesg 命令详解
  • 深入理解 v-for 指令及其使用方法
  • AI绘制流程图
  • 【数据结构】之二叉树
  • 《嵌套调用与链式访问:C语言中的函数调用技巧》
  • 关于Genspark.ai的使用体验