VirtualBox

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

Last change on this file since 86669 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: req.h 82968 2020-02-04 10:35:17Z 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 is completed, the requester is begin notified. */
52 RTREQSTATE_COMPLETED,
53 /** The request packet is in the free chain. (The requester */
54 RTREQSTATE_FREE
55} RTREQSTATE;
56
57
58/**
59 * RT Request packet.
60 *
61 * This is used to request an action in the queue handler thread.
62 */
63struct RTREQ
64{
65 /** Magic number (RTREQ_MAGIC). */
66 uint32_t u32Magic;
67 /** Set if the event semaphore is clear. */
68 volatile bool fEventSemClear;
69 /** Set if the push back semaphore should be signaled when the request
70 * is picked up from the queue. */
71 volatile bool fSignalPushBack;
72 /** Set if pool, clear if queue. */
73 volatile bool fPoolOrQueue;
74 /** IPRT status code for the completed request. */
75 volatile int32_t iStatusX;
76 /** Request state. */
77 volatile RTREQSTATE enmState;
78 /** The reference count. */
79 volatile uint32_t cRefs;
80
81 /** Pointer to the next request in the chain. */
82 struct RTREQ * volatile pNext;
83
84 union
85 {
86 /** Pointer to the pool this packet belongs to. */
87 RTREQPOOL hPool;
88 /** Pointer to the queue this packet belongs to. */
89 RTREQQUEUE hQueue;
90 /** Opaque owner access. */
91 void *pv;
92 } uOwner;
93
94 /** Timestamp take when the request was submitted to a pool. Not used
95 * for queued request. */
96 uint64_t uSubmitNanoTs;
97 /** Requester completion event sem. */
98 RTSEMEVENT EventSem;
99 /** Request pushback event sem. Allocated lazily. */
100 RTSEMEVENTMULTI hPushBackEvt;
101 /** Flags, RTREQ_FLAGS_*. */
102 uint32_t fFlags;
103 /** Request type. */
104 RTREQTYPE enmType;
105 /** Request specific data. */
106 union RTREQ_U
107 {
108 /** RTREQTYPE_INTERNAL. */
109 struct
110 {
111 /** Pointer to the function to be called. */
112 PFNRT pfn;
113 /** Number of arguments. */
114 uint32_t cArgs;
115 /** Array of arguments. */
116 uintptr_t aArgs[64];
117 } Internal;
118 } u;
119};
120
121/** Internal request representation. */
122typedef RTREQ RTREQINT;
123/** Pointer to an internal request representation. */
124typedef RTREQINT *PRTREQINT;
125
126/**
127 * Internal queue instance.
128 */
129typedef struct RTREQQUEUEINT
130{
131 /** Magic value (RTREQQUEUE_MAGIC). */
132 uint32_t u32Magic;
133 /** Set if busy (pending or processing requests). */
134 bool volatile fBusy;
135 /** Head of the request queue (LIFO). Atomic. */
136 volatile PRTREQ pReqs;
137 /** List of requests pending after a non-VINF_SUCCESS status code forced
138 * RTReqQueueProcess to stop processing requestins. This is in FIFO order. */
139 volatile PRTREQ pAlreadyPendingReqs;
140 /** The last index used during alloc/free. */
141 volatile uint32_t iReqFree;
142 /** Number of free request packets. */
143 volatile uint32_t cReqFree;
144 /** Array of pointers to lists of free request packets. Atomic. */
145 volatile PRTREQ apReqFree[9];
146 /** Requester event sem.
147 * The request can use this event semaphore to wait/poll for new requests.
148 */
149 RTSEMEVENT EventSem;
150} RTREQQUEUEINT;
151
152/** Pointer to an internal queue instance. */
153typedef struct RTREQQUEUEINT *PRTREQQUEUEINT;
154/** Pointer to a request thread pool instance. */
155typedef struct RTREQPOOLINT *PRTREQPOOLINT;
156
157
158/* req.cpp */
159DECLHIDDEN(int) rtReqAlloc(RTREQTYPE enmType, bool fPoolOrQueue, void *pvOwner, PRTREQ *phReq);
160DECLHIDDEN(int) rtReqReInit(PRTREQINT pReq, RTREQTYPE enmType);
161DECLHIDDEN(void) rtReqFreeIt(PRTREQINT pReq);
162DECLHIDDEN(int) rtReqProcessOne(PRTREQ pReq);
163
164/* reqpool.cpp / reqqueue.cpp. */
165DECLHIDDEN(void) rtReqQueueSubmit(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
166DECLHIDDEN(void) rtReqPoolSubmit(PRTREQPOOLINT pPool, PRTREQINT pReq);
167DECLHIDDEN(bool) rtReqQueueRecycle(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
168DECLHIDDEN(bool) rtReqPoolRecycle(PRTREQPOOLINT pPool, PRTREQINT pReq);
169
170RT_C_DECLS_END
171
172#endif /* !IPRT_INCLUDED_INTERNAL_req_h */
173
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