GuestHost/installation/VBoxWinDrvInst.cpp: Try harder if DiInstallDriverW() returns...
[vbox.git] / include / iprt / circbuf.h
blobc0a10a1f2b11e4290351c268a57fffffd3aaf76c
1 /** @file
2 * IPRT - Lock Free Circular Buffer
3 */
5 /*
6 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_circbuf_h
37 #define IPRT_INCLUDED_circbuf_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
39 # pragma once
40 #endif
42 #include <iprt/types.h>
44 /** @defgroup grp_rt_circbuf RTCircBuf - Lock Free Circular Buffer
45 * @ingroup grp_rt
47 * Implementation of a lock free circular buffer which could be used in a multi
48 * threaded environment. Note that only the acquire, release and getter
49 * functions are threading aware. So don't use reset if the circular buffer is
50 * still in use.
52 * @{
55 RT_C_DECLS_BEGIN
57 /** Pointer to a circular buffer (abstract). */
58 typedef struct RTCIRCBUF *PRTCIRCBUF;
60 /**
61 * Create a circular buffer.
63 * @returns IPRT status code.
65 * @param ppBuf Where to store the buffer.
66 * @param cbSize The size of the new buffer.
68 RTDECL(int) RTCircBufCreate(PRTCIRCBUF *ppBuf, size_t cbSize);
70 /**
71 * Destroy the circular buffer.
73 * @param pBuf The buffer to destroy. NULL is ignored.
75 RTDECL(void) RTCircBufDestroy(PRTCIRCBUF pBuf);
77 /**
78 * Reset all position information in the circular buffer.
80 * @note This function is not multi threading aware.
82 * @param pBuf The buffer to reset.
84 RTDECL(void) RTCircBufReset(PRTCIRCBUF pBuf);
86 /**
87 * Returns the current free space of the buffer.
89 * @param pBuf The buffer to query.
91 RTDECL(size_t) RTCircBufFree(PRTCIRCBUF pBuf);
93 /**
94 * Returns the current used space of the buffer.
96 * @param pBuf The buffer to query.
98 RTDECL(size_t) RTCircBufUsed(PRTCIRCBUF pBuf);
101 * Returns the size of the buffer.
103 * @param pBuf The buffer to query.
105 RTDECL(size_t) RTCircBufSize(PRTCIRCBUF pBuf);
107 RTDECL(bool) RTCircBufIsReading(PRTCIRCBUF pBuf);
108 RTDECL(bool) RTCircBufIsWriting(PRTCIRCBUF pBuf);
111 * Returns the current read offset (in bytes) within the buffer.
113 * @param pBuf The buffer to query.
115 RTDECL(size_t) RTCircBufOffsetRead(PRTCIRCBUF pBuf);
118 * Returns the current write offset (in bytes) within the buffer.
120 * @param pBuf The buffer to query.
122 RTDECL(size_t) RTCircBufOffsetWrite(PRTCIRCBUF pBuf);
125 * Acquire a block of the circular buffer for reading.
127 * @param pBuf The buffer to acquire from.
128 * @param cbReqSize The requested size of the block.
129 * @param ppvStart The resulting memory pointer.
130 * @param pcbSize The resulting size of the memory pointer.
132 RTDECL(void) RTCircBufAcquireReadBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize);
135 * Release a block which was acquired by RTCircBufAcquireReadBlock.
137 * @param pBuf The buffer to acquire from.
138 * @param cbSize The size of the block.
140 RTDECL(void) RTCircBufReleaseReadBlock(PRTCIRCBUF pBuf, size_t cbSize);
143 * Acquire a block of the circular buffer for writing.
145 * @param pBuf The buffer to acquire from.
146 * @param cbReqSize The requested size of the block.
147 * @param ppvStart The resulting memory pointer.
148 * @param pcbSize The resulting size of the memory pointer.
150 RTDECL(void) RTCircBufAcquireWriteBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize);
153 * Release a block which was acquired by RTCircBufAcquireWriteBlock.
155 * @param pBuf The buffer to acquire from.
156 * @param cbSize The size of the block.
158 RTDECL(void) RTCircBufReleaseWriteBlock(PRTCIRCBUF pBuf, size_t cbSize);
160 RT_C_DECLS_END
162 /** @} */
164 #endif /* !IPRT_INCLUDED_circbuf_h */