1 | /* $Id: req.h 60121 2016-03-21 14:28:23Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Internal RTReq header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2015 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 ___internal_req_h
|
---|
28 | #define ___internal_req_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Request state.
|
---|
37 | */
|
---|
38 | typedef enum RTREQSTATE
|
---|
39 | {
|
---|
40 | /** The state is invalid. */
|
---|
41 | RTREQSTATE_INVALID = 0,
|
---|
42 | /** The request have been allocated and is in the process of being filed. */
|
---|
43 | RTREQSTATE_ALLOCATED,
|
---|
44 | /** The request is queued by the requester. */
|
---|
45 | RTREQSTATE_QUEUED,
|
---|
46 | /** The request is begin processed. */
|
---|
47 | RTREQSTATE_PROCESSING,
|
---|
48 | /** The request is completed, the requester is begin notified. */
|
---|
49 | RTREQSTATE_COMPLETED,
|
---|
50 | /** The request packet is in the free chain. (The requester */
|
---|
51 | RTREQSTATE_FREE
|
---|
52 | } RTREQSTATE;
|
---|
53 |
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * RT Request packet.
|
---|
57 | *
|
---|
58 | * This is used to request an action in the queue handler thread.
|
---|
59 | */
|
---|
60 | struct RTREQ
|
---|
61 | {
|
---|
62 | /** Magic number (RTREQ_MAGIC). */
|
---|
63 | uint32_t u32Magic;
|
---|
64 | /** Set if the event semaphore is clear. */
|
---|
65 | volatile bool fEventSemClear;
|
---|
66 | /** Set if the push back semaphore should be signaled when the request
|
---|
67 | * is picked up from the queue. */
|
---|
68 | volatile bool fSignalPushBack;
|
---|
69 | /** Set if pool, clear if queue. */
|
---|
70 | volatile bool fPoolOrQueue;
|
---|
71 | /** IPRT status code for the completed request. */
|
---|
72 | volatile int32_t iStatusX;
|
---|
73 | /** Request state. */
|
---|
74 | volatile RTREQSTATE enmState;
|
---|
75 | /** The reference count. */
|
---|
76 | volatile uint32_t cRefs;
|
---|
77 |
|
---|
78 | /** Pointer to the next request in the chain. */
|
---|
79 | struct RTREQ * volatile pNext;
|
---|
80 |
|
---|
81 | union
|
---|
82 | {
|
---|
83 | /** Pointer to the pool this packet belongs to. */
|
---|
84 | RTREQPOOL hPool;
|
---|
85 | /** Pointer to the queue this packet belongs to. */
|
---|
86 | RTREQQUEUE hQueue;
|
---|
87 | /** Opaque owner access. */
|
---|
88 | void *pv;
|
---|
89 | } uOwner;
|
---|
90 |
|
---|
91 | /** Timestamp take when the request was submitted to a pool. Not used
|
---|
92 | * for queued request. */
|
---|
93 | uint64_t uSubmitNanoTs;
|
---|
94 | /** Requester completion event sem. */
|
---|
95 | RTSEMEVENT EventSem;
|
---|
96 | /** Request pushback event sem. Allocated lazily. */
|
---|
97 | RTSEMEVENTMULTI hPushBackEvt;
|
---|
98 | /** Flags, RTREQ_FLAGS_*. */
|
---|
99 | uint32_t fFlags;
|
---|
100 | /** Request type. */
|
---|
101 | RTREQTYPE enmType;
|
---|
102 | /** Request specific data. */
|
---|
103 | union RTREQ_U
|
---|
104 | {
|
---|
105 | /** RTREQTYPE_INTERNAL. */
|
---|
106 | struct
|
---|
107 | {
|
---|
108 | /** Pointer to the function to be called. */
|
---|
109 | PFNRT pfn;
|
---|
110 | /** Number of arguments. */
|
---|
111 | uint32_t cArgs;
|
---|
112 | /** Array of arguments. */
|
---|
113 | uintptr_t aArgs[64];
|
---|
114 | } Internal;
|
---|
115 | } u;
|
---|
116 | };
|
---|
117 |
|
---|
118 | /** Internal request representation. */
|
---|
119 | typedef RTREQ RTREQINT;
|
---|
120 | /** Pointer to an internal request representation. */
|
---|
121 | typedef RTREQINT *PRTREQINT;
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Internal queue instance.
|
---|
125 | */
|
---|
126 | typedef struct RTREQQUEUEINT
|
---|
127 | {
|
---|
128 | /** Magic value (RTREQQUEUE_MAGIC). */
|
---|
129 | uint32_t u32Magic;
|
---|
130 | /** Set if busy (pending or processing requests). */
|
---|
131 | bool volatile fBusy;
|
---|
132 | /** Head of the request queue (LIFO). Atomic. */
|
---|
133 | volatile PRTREQ pReqs;
|
---|
134 | /** List of requests pending after a non-VINF_SUCCESS status code forced
|
---|
135 | * RTReqQueueProcess to stop processing requestins. This is in FIFO order. */
|
---|
136 | volatile PRTREQ pAlreadyPendingReqs;
|
---|
137 | /** The last index used during alloc/free. */
|
---|
138 | volatile uint32_t iReqFree;
|
---|
139 | /** Number of free request packets. */
|
---|
140 | volatile uint32_t cReqFree;
|
---|
141 | /** Array of pointers to lists of free request packets. Atomic. */
|
---|
142 | volatile PRTREQ apReqFree[9];
|
---|
143 | /** Requester event sem.
|
---|
144 | * The request can use this event semaphore to wait/poll for new requests.
|
---|
145 | */
|
---|
146 | RTSEMEVENT EventSem;
|
---|
147 | } RTREQQUEUEINT;
|
---|
148 |
|
---|
149 | /** Pointer to an internal queue instance. */
|
---|
150 | typedef struct RTREQQUEUEINT *PRTREQQUEUEINT;
|
---|
151 | /** Pointer to a request thread pool instance. */
|
---|
152 | typedef struct RTREQPOOLINT *PRTREQPOOLINT;
|
---|
153 |
|
---|
154 |
|
---|
155 | /* req.cpp */
|
---|
156 | DECLHIDDEN(int) rtReqAlloc(RTREQTYPE enmType, bool fPoolOrQueue, void *pvOwner, PRTREQ *phReq);
|
---|
157 | DECLHIDDEN(int) rtReqReInit(PRTREQINT pReq, RTREQTYPE enmType);
|
---|
158 | DECLHIDDEN(void) rtReqFreeIt(PRTREQINT pReq);
|
---|
159 | DECLHIDDEN(int) rtReqProcessOne(PRTREQ pReq);
|
---|
160 |
|
---|
161 | /* reqpool.cpp / reqqueue.cpp. */
|
---|
162 | DECLHIDDEN(void) rtReqQueueSubmit(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
|
---|
163 | DECLHIDDEN(void) rtReqPoolSubmit(PRTREQPOOLINT pPool, PRTREQINT pReq);
|
---|
164 | DECLHIDDEN(bool) rtReqQueueRecycle(PRTREQQUEUEINT pQueue, PRTREQINT pReq);
|
---|
165 | DECLHIDDEN(bool) rtReqPoolRecycle(PRTREQPOOLINT pPool, PRTREQINT pReq);
|
---|
166 |
|
---|
167 | RT_C_DECLS_END
|
---|
168 |
|
---|
169 | #endif
|
---|
170 |
|
---|