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

📄 sdworkitem.h

📁 2443 wince5.0 bsp, source code
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

// Copyright (c) 2002 BSQUARE Corporation.  All rights reserved.
// DO NOT REMOVE --- BEGIN EXTERNALLY DEVELOPED SOURCE CODE ID 40973--- DO NOT REMOVE

// Generic work item object

#include "SDCardDDK.h"
#include <SDHCD.h>
#include "SDCardApi.h"

#ifndef _SDCARD_WORKITEM_DEFINED
#define _SDCARD_WORKITEM_DEFINED

#define SD_BUS_DRIVER_WORKER_TAG  'SDWK'

class CSDWorkItem;

// typedef for work item function
typedef VOID (*PSD_WORK_ITEM_FUNC) (CSDWorkItem *, PVOID);

// work item message block
typedef struct WORK_ITEM_MESSAGE_BLOCK {
    LIST_ENTRY  ListEntry;      // list entry
    DWORD       Data;           // data block
} *PWORK_ITEM_MESSAGE_BLOCK;

// macro to extract the data field in the message block
#define GetMessageBlock(type, pBlock) (type)(&((pBlock)->Data))

// class to implement work item object
class CSDWorkItem 
{
public:
    // constructor
    CSDWorkItem(PVOID                  pContext, 
        PSD_WORK_ITEM_FUNC     pFunction, 
        int                    Priority,
        ULONG                  MessageListDepth,
        ULONG                  MessageBlockLength,
        BOOL                   MessageQueue = TRUE);

    // destructor
    ~CSDWorkItem();

    // start the work item
    SD_API_STATUS StartWorkItem();

    // work item thread function
    static DWORD WorkItemThreadEntry(CSDWorkItem *pWorkItem);

    // get work item context
    PVOID GetContext() {
        return m_pWorkItemContext;
    }

    // acquire the object lock
    inline VOID AcquireLock() {
        EnterCriticalSection(&m_CriticalSection);
    }

    // release the object lock
    inline VOID ReleaseLock() {
        LeaveCriticalSection(&m_CriticalSection);
    }

    // allocate a message block
    inline PWORK_ITEM_MESSAGE_BLOCK AllocateMessage() {
        if (UsingMessageQueue()) {
            return (PWORK_ITEM_MESSAGE_BLOCK)SDAllocateFromMemList(m_hWorkItemMessageList);
        } else {
            DEBUGCHK(FALSE);
            return NULL;    
        }
    }

    // free a message
    inline VOID FreeMessage(PWORK_ITEM_MESSAGE_BLOCK pMessage) {
        if (UsingMessageQueue()) {
            SDFreeToMemList(m_hWorkItemMessageList, pMessage);
        } else {
            DEBUGCHK(FALSE);
        }
    }

    // wait for a wakeup event
    SD_API_STATUS WaitWakeUp(DWORD TimeOut = INFINITE);

    inline BOOL UsingMessageQueue() { return m_UseMessageQueue; }

    // post a message to the message queue
    VOID PostMessage(PWORK_ITEM_MESSAGE_BLOCK pMessage);

    // get a message from the message queue
    SD_API_STATUS GetMessage(PWORK_ITEM_MESSAGE_BLOCK *ppMessage);

    // flush the message queue
    VOID FlushMessageQueue();

    // wake up the work item
    VOID WakeUpWorkItem() {
        SetEvent(m_hWorkerWakeUp);
    }

protected:
    CRITICAL_SECTION        m_CriticalSection;  // work item critical section
    HANDLE                  m_hWorkerThread;    // the work item thread
    HANDLE                  m_hWorkerWakeUp;    // worker wake up
    BOOL                    m_ShutDown;         // ShutDown
    PSD_WORK_ITEM_FUNC      m_pWorkFunction;    // the work function
    PVOID                   m_pWorkItemContext; // context for the work item
    int                     m_WorkItemPriority;      // work item priority
    BOOL                    m_UseMessageQueue;       // use a message queue
    LIST_ENTRY              m_WorkItemMessageQueue;  // work item message queue
    SD_MEMORY_LIST_HANDLE   m_hWorkItemMessageList;  // list for events occuring on 
    ULONG                   m_MessageListDepth;      // message list depth
    ULONG                   m_MessageBlockLength;    // message block length   
    BOOL                    m_Initialized;           // initialized
};


#endif

// DO NOT REMOVE --- END EXTERNALLY DEVELOPED SOURCE CODE ID --- DO NOT REMOVE

⌨️ 快捷键说明

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