req.h revision 4f3f6eb7aecf332523a1b44ff1e0cda506408273
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync/* $Id$ */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync/** @file
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * IPRT - Internal RTReq header.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync/*
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * Copyright (C) 2006-2011 Oracle Corporation
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync *
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * available from http://www.virtualbox.org. This file is free software;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * General Public License (GPL) as published by the Free Software
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync *
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * The contents of this file may alternatively be used under the terms
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * of the Common Development and Distribution License Version 1.0
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * VirtualBox OSE distribution, in which case the provisions of the
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * CDDL are applicable instead of those of the GPL.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync *
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * You may elect to license modified versions of this file under the
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * terms and conditions of either the GPL or the CDDL or both.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync#ifndef ___internal_req_h
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync#define ___internal_req_h
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync#include <iprt/types.h>
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsyncRT_C_DECLS_BEGIN
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync/**
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync * Request state.
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsynctypedef enum RTREQSTATE
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync{
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The state is invalid. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_INVALID = 0,
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The request have been allocated and is in the process of being filed. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_ALLOCATED,
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The request is queued by the requester. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_QUEUED,
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The request is begin processed. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_PROCESSING,
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The request is completed, the requester is begin notified. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_COMPLETED,
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** The request packet is in the free chain. (The requester */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQSTATE_FREE
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync} RTREQSTATE;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync/**
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync * RT Request packet.
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync *
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync * This is used to request an action in the queue handler thread.
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsyncstruct RTREQ
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync{
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Magic number (RTREQ_MAGIC). */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync uint32_t u32Magic;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Set if the event semaphore is clear. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync volatile bool fEventSemClear;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Set if pool, clear if queue. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync volatile bool fPoolOrQueue;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** IPRT status code for the completed request. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync volatile int32_t iStatusX;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Request state. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync volatile RTREQSTATE enmState;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Pointer to the next request in the chain. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync struct RTREQ * volatile pNext;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync union
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync {
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Pointer to the pool this packet belongs to. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQPOOL hPool;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Pointer to the queue this packet belongs to. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQQUEUE hQueue;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync } uOwner;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Requester event sem.
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync * The request can use this event semaphore to wait/poll for completion
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync * of the request.
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTSEMEVENT EventSem;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Flags, RTREQ_FLAGS_*. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync uint32_t fFlags;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Request type. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync RTREQTYPE enmType;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Request specific data. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync union RTREQ_U
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync {
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** RTREQTYPE_INTERNAL. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync struct
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync {
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Pointer to the function to be called. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync PFNRT pfn;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Number of arguments. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync uint32_t cArgs;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync /** Array of arguments. */
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync uintptr_t aArgs[64];
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync } Internal;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync } u;
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync};
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
4f3f6eb7aecf332523a1b44ff1e0cda506408273vboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync/**
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * Internal queue instance.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsynctypedef struct RTREQQUEUEINT
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync{
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync /** Magic value (RTREQQUEUE_MAGIC). */
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync uint32_t u32Magic;
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync /** Set if busy (pending or processing requests). */
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync bool volatile fBusy;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync /** Head of the request queue. Atomic. */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync volatile PRTREQ pReqs;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync /** The last index used during alloc/free. */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync volatile uint32_t iReqFree;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync /** Number of free request packets. */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync volatile uint32_t cReqFree;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync /** Array of pointers to lists of free request packets. Atomic. */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync volatile PRTREQ apReqFree[9];
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync /** Requester event sem.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync * The request can use this event semaphore to wait/poll for new requests.
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync RTSEMEVENT EventSem;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync} RTREQQUEUEINT;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync/** Pointer to an internal queue instance. */
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsynctypedef RTREQQUEUEINT *PRTREQQUEUEINT;
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsyncDECLHIDDEN(int) rtReqProcessOne(PRTREQ pReq);
17ef1920962b3df57bf6d2704ced1586396d96f0vboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsyncRT_C_DECLS_END
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync#endif
b6b07507d11e2bea02bbba193ba367ea479a2fcfvboxsync