VirtualBox

source: vbox/trunk/include/iprt/circbuf.h@ 48418

Last change on this file since 48418 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/** @file
2 * IPRT - Lock Free Circular Buffer
3 */
4
5/*
6 * Copyright (C) 2010-2011 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_circbuf_h
27#define ___iprt_circbuf_h
28
29#include <iprt/types.h>
30
31/** @defgroup grp_rt_circbuf RTCircBuf - Lock Free Circular Buffer
32 * @ingroup grp_rt
33 *
34 * Implementation of a lock free circular buffer which could be used in a multi
35 * threaded environment. Note that only the acquire, release and getter
36 * functions are threading aware. So don't use reset if the circular buffer is
37 * still in use.
38 *
39 * @{
40 */
41
42RT_C_DECLS_BEGIN
43
44/** Pointer to a circular buffer (abstract). */
45typedef struct RTCIRCBUF *PRTCIRCBUF;
46
47/**
48 * Create a circular buffer.
49 *
50 * @returns IPRT status code.
51 *
52 * @param ppBuf Where to store the buffer.
53 * @param cbSize The size of the new buffer.
54 */
55RTDECL(int) RTCircBufCreate(PRTCIRCBUF *ppBuf, size_t cbSize);
56
57/**
58 * Destroy the circular buffer.
59 *
60 * @param pBuf The buffer to destroy. NULL is ignored.
61 */
62RTDECL(void) RTCircBufDestroy(PRTCIRCBUF pBuf);
63
64/**
65 * Reset all position information in the circular buffer.
66 *
67 * @note This function is not multi threading aware.
68 *
69 * @param pBuf The buffer to reset.
70 */
71RTDECL(void) RTCircBufReset(PRTCIRCBUF pBuf);
72
73/**
74 * Returns the current free space of the buffer.
75 *
76 * @param pBuf The buffer to query.
77 */
78RTDECL(size_t) RTCircBufFree(PRTCIRCBUF pBuf);
79
80/**
81 * Returns the current used space of the buffer.
82 *
83 * @param pBuf The buffer to query.
84 */
85RTDECL(size_t) RTCircBufUsed(PRTCIRCBUF pBuf);
86
87/**
88 * Returns the size of the buffer.
89 *
90 * @param pBuf The buffer to query.
91 */
92RTDECL(size_t) RTCircBufSize(PRTCIRCBUF pBuf);
93
94RTDECL(bool) RTCircBufIsReading(PRTCIRCBUF pBuf);
95RTDECL(bool) RTCircBufIsWriting(PRTCIRCBUF pBuf);
96
97/**
98 * Acquire a block of the circular buffer for reading.
99 *
100 * @param pBuf The buffer to acquire from.
101 * @param cbReqSize The requested size of the block.
102 * @param ppvStart The resulting memory pointer.
103 * @param pcbSize The resulting size of the memory pointer.
104 */
105RTDECL(void) RTCircBufAcquireReadBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize);
106
107/**
108 * Release a block which was acquired by RTCircBufAcquireReadBlock.
109 *
110 * @param pBuf The buffer to acquire from.
111 * @param cbSize The size of the block.
112 */
113RTDECL(void) RTCircBufReleaseReadBlock(PRTCIRCBUF pBuf, size_t cbSize);
114
115/**
116 * Acquire a block of the circular buffer for writing.
117 *
118 * @param pBuf The buffer to acquire from.
119 * @param cbReqSize The requested size of the block.
120 * @param ppvStart The resulting memory pointer.
121 * @param pcbSize The resulting size of the memory pointer.
122 */
123RTDECL(void) RTCircBufAcquireWriteBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize);
124
125/**
126 * Release a block which was acquired by RTCircBufAcquireWriteBlock.
127 *
128 * @param pBuf The buffer to acquire from.
129 * @param cbSize The size of the block.
130 */
131RTDECL(void) RTCircBufReleaseWriteBlock(PRTCIRCBUF pBuf, size_t cbSize);
132
133RT_C_DECLS_END
134
135/** @} */
136
137#endif /* !___iprt_circbuf_h */
138
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