VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/req.h@ 91483

Last change on this file since 91483 was 88813, checked in by vboxsync, 4 years ago

IPRT/RTReq: Added a RTReqCancel function. Changed the behavior of the RTREQFLAGS_NO_WAIT to optionally return the request handle rather than obstinately returning NIL even when the phReq parameter is not NULL. This makes the usage clearer and allows canceling NO_WAIT requests. (Needed in DrvAudio.) bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: req.h 88813 2021-05-01 18:15:13Z vboxsync $ */
2/** @file
3 * IPRT - Internal RTReq header.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef IPRT_INCLUDED_INTERNAL_req_h
28#define IPRT_INCLUDED_INTERNAL_req_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/types.h>
34
35
36RT_C_DECLS_BEGIN
37
38/**
39 * Request state.
40 */
41typedef enum RTREQSTATE
42{
43 /** The state is invalid. */
44 RTREQSTATE_INVALID = 0,
45 /** The request have been allocated and is in the process of being filed. */
46 RTREQSTATE_ALLOCATED,
47 /** The request is queued by the requester. */
48 RTREQSTATE_QUEUED,
49 /** The request is begin processed. */
50 RTREQSTATE_PROCESSING,
51 /** The request has been cancelled. */
52 RTREQSTATE_CANCELLED,
53 /** The request is completed, the requester is begin notified. */
54 RTREQSTATE_COMPLETED,
55 /** The request packet is in the free chain. */
56 RTREQSTATE_FREE
57} RTREQSTATE;
58AssertCompileSize(RTREQSTATE, sizeof(uint32_t));
59
60
61/**
62 * RT Request packet.
63 *
64 * This is used to request an action in the queue handler thread.
65 */
66struct RTREQ
67{
68 /** Magic number (RTREQ_MAGIC). */
69 uint32_t u32Magic;
70 /** Set if the event semaphore is clear. */
71 volatile bool fEventSemClear;
72 /** Set if the push back semaphore should be signaled when the request
73 * is picked up from the queue. */
74 volatile bool fSignalPushBack;
75 /** Set if pool, clear if queue. */
76 volatile bool fPoolOrQueue;
77 /** IPRT status code for the completed request. */
78 volatile int32_t iStatusX;
79 /** Request state. */
80 volatile RTREQSTATE enmState;
81 /** The reference count. */
82 volatile uint32_t cRefs;
83
84 /** Pointer to the next request in the chain. */
85 struct RTREQ * volatile pNext;
86
87 union
88 {
89 /** Pointer to the pool this packet belongs to. */
90 RTREQPOOL hPool;
91 /** Pointer to the queue this packet belongs to. */
92 RTREQQUEUE hQueue;
93 /** Opaque owner access. */
94 void *pv;
95 } uOwner;
96
97 /** Timestamp take when the request was submitted to a pool. Not used
98 * for queued request. */
99 uint64_t uSubmitNanoTs;
100 /** Requester completion event sem. */
101 RTSEMEVENT EventSem;
102 /** Request pushback event sem. Allocated lazily. */
103 RTSEMEVENTMULTI hPushBackEvt;
104 /** Flags, RTREQ_FLAGS_*. */
105 uint32_t fFlags;
106 /** Request type. */
107 RTREQTYPE enmType;
108 /** Request specific data. */
109 union RTREQ_U
110 {
111 /** RTREQTYPE_INTERNAL. */
112 struct
113 {
114 /** Pointer to the function to be called. */
115 PFNRT pfn;
116 /** Number of arguments. */
117 uint32_t cArgs;
118 /** Array of arguments. */
119 uintptr_t aArgs[12];
120 } Internal;
121 } u;
122};
123
124/** Internal request representation. */
125typedef RTREQ RTREQINT;
126/** Pointer to an internal request representation. */
127typedef RTREQINT *PRTREQINT;
128
129/**
130 * Internal queue instance.
131 */
132typedef struct RTREQQUEUEINT
133{
134 /** Magic value (RTREQQUEUE_MAGIC). */
135 uint32_t u32Magic;
136 /** Set if busy (pending or processing requests). */
137 bool volatile fBusy;
138 /** Head of the request queue (LIFO). Atomic. */
139 volatile PRTREQ pReqs;
140 /** List of requests pending after a non-VINF_SUCCESS status code forced
141 * RTReqQueueProcess to stop processing requestins. This is in FIFO order. */
142 volatile PRTREQ pAlreadyPendingReqs;
143 /** The last index used during alloc/free. */
144 volatile uint32_t iReqFree;
145 /** Number of free request packets. */
146 volatile uint32_t cReqFree;
147 /** Array of pointers to lists of free request packets. Atomic. */
148 volatile PRTREQ apReqFree[9];
149 /** Requester event sem.
150 * The request can use this event semaphore to wait/poll for new requests.
151 */
152 RTSEMEVENT EventSem;
153} RTREQQUEUEINT;
154
155/** Pointer to an internal queue instance. */
156typedef struct RTREQQUEUEINT *PRTREQQUEUEINT;
157/** Pointer to a request thread pool instance. */
158typedef struct RTREQPOOLINT *PRTREQPOOLINT;
159
160
161/* req.cpp */
162DECLHIDDEN(int) rtReqAlloc(RTREQTYPE enmType, bool fPoolOrQueue, void *pvOwner, PRTREQ *phReq);
163DECLHIDDEN(int) rtReqReInit(PRTREQINT pReq, RTREQTYPE enmType);
164DECLHIDDEN(void) rtReqFreeIt(PRTREQINT pReq);
165DECLHIDDEN(int) rtReqProcessOne(PRTREQ pReq);
166
167/* reqpool.cpp / reqqueue.cpp. */
168DECLHIDDEN(void) rtReqQueueSubmit(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
169DECLHIDDEN(void) rtReqPoolSubmit(PRTREQPOOLINT pPool, PRTREQINT pReq);
170DECLHIDDEN(void) rtReqPoolCancel(PRTREQPOOLINT pPool, PRTREQINT pReq);
171DECLHIDDEN(bool) rtReqQueueRecycle(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
172DECLHIDDEN(bool) rtReqPoolRecycle(PRTREQPOOLINT pPool, PRTREQINT pReq);
173
174RT_C_DECLS_END
175
176#endif /* !IPRT_INCLUDED_INTERNAL_req_h */
177
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette