📄 requestcount.h
字号:
//
// File: requestcount.h
// Description: The definition and implementation of class RequestCount
//
// Created: Wed. Jan 15, 2003
//
//
// 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 MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL CONEXANT BE LIABLE TO ANY PARTY FOR DIRECT,
// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
// AND ITS DOCUMENTATION, EVEN IF CONEXANT HAS BEEN ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2000-2001 Conexant Systems, Inc.
//
// All Rights Reserved.
// ---------------------------------------------------------------
//
// Module Revision Id:
//
//
#ifndef _REQUEST_COUNT_H_
#define _REQUEST_COUNT_H_
/////////////////////////////////////////////////////////////////////////////////////////
//class RequestCount is a very simple class which keeps track of the number of IRPs
// currently being processed in the driver.
//
// The class provides members increment() and decrement() to change the request count
// as IRPs are received and completed.
//
// Member wait() waits for the request count to go to 0, necessary if the device is
// being removed.
//
// The class is very simple, and all functions are inline.
//
class RequestCount
{
public:
RequestCount();
//Wait for all requests to complete
VOID wait();
//increment and decrement the request count.
VOID increment();
VOID decrement();
private:
LONG _request_count;
KEVENT _all_requests_complete;
};
inline RequestCount::RequestCount():
_request_count(0)
{
KeInitializeEvent( &_all_requests_complete,
NotificationEvent,
TRUE );
}
inline VOID RequestCount::wait()
{
KeWaitForSingleObject(
&_all_requests_complete,
Executive,
KernelMode,
TRUE,
NULL);
}
inline VOID RequestCount::increment()
{
LONG count = InterlockedIncrement(&_request_count);
if(count == 1)
{
KeClearEvent(&_all_requests_complete);
}
dbgLogInfo(("Request Count incremented to %d\n", count));
}
inline VOID RequestCount::decrement()
{
LONG count = InterlockedDecrement(&_request_count);
ASSERT(count >= 0 );
dbgLogInfo(("Request Count decremented to %d\n", count));
if (count == 0 )
{
//Signal the event whenever there are no pending requests.
dbgLogTrace(("last request completed, signalling event\n"));
KeSetEvent(
&_all_requests_complete,
0,
FALSE );
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -