⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferqueue.cpp

📁 完整的基于Conxant平台的USB电视棒的WIN驱动程序。
💻 CPP
字号:
/*+++ *******************************************************************\ 
* 
*  Copyright and Disclaimer: 
*  
*     --------------------------------------------------------------- 
*     This software is provided "AS IS" without warranty of any kind, 
*     either expressed or implied, including but not limited to the 
*     implied warranties of noninfringement, merchantability and/or 
*     fitness for a particular purpose.
*     --------------------------------------------------------------- 
*   
*     Copyright (c) 2008 Conexant Systems, Inc. 
*     All rights reserved. 
*
\******************************************************************* ---*/ 
#include "BufferQueue.h"

/////////////////////////////////////////////////////////////////////////////////////////
BufferQueue::BufferQueue()
{
    KeInitializeSpinLock (&_spin_lock);
    InitializeListHead (&_list_head);
    KeInitializeEvent(&_list_full_event, NotificationEvent, FALSE);
    _count = 0;
}


/////////////////////////////////////////////////////////////////////////////////////////
VOID BufferQueue::waitForBuffers(DWORD wait_time)
{
    LARGE_INTEGER timeout;
    timeout.QuadPart = (__int64)(10000*wait_time); 
    timeout.QuadPart = -timeout.QuadPart;


    KeWaitForSingleObject(
        &_list_full_event,
        Executive,
        KernelMode,
        TRUE,
        &timeout);
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID BufferQueue::cancelWaits()
{
    KeSetEvent(&_list_full_event, IO_NO_INCREMENT, FALSE);
}

/////////////////////////////////////////////////////////////////////////////////////////
PBUFFER_ENTRY BufferQueue::getBuffer()
{
    PBUFFER_ENTRY p_buffer = NULL;

    KIRQL old_irql = lock();

    if (!IsListEmpty (&_list_head))
    {
        p_buffer = (PBUFFER_ENTRY) RemoveHeadList(&_list_head);
        _count--;

        if(_count == 0)
        {
            KeClearEvent(&_list_full_event);
        }
    }

    if(p_buffer)
    {
        p_buffer->buffer_in_list = FALSE;
    }

    unlock(old_irql);

    return p_buffer;
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID BufferQueue::addBuffer(PBUFFER_ENTRY p_buffer)
{
    KIRQL old_irql = lock();
   
    //The buffer is already in a list.
    if(p_buffer->buffer_in_list)
    {
        unlock(old_irql);
        return;
    }

    InsertTailList(&_list_head, (PLIST_ENTRY)p_buffer);
    _count++;
    if(_count == 1)
    {
        KeSetEvent(&_list_full_event, IO_NO_INCREMENT, FALSE);
    }

    p_buffer->buffer_in_list = TRUE;

    unlock(old_irql);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -