@@ -19,6 +19,11 @@ public sealed class MpscBoundedBuffer<T> where T : class
1919 private readonly int mask ;
2020 private PaddedHeadAndTail headAndTail ; // mutable struct, don't mark readonly
2121
22+ /// <summary>
23+ /// Initializes a new instance of the MpscBoundedBuffer class with the specified bounded capacity.
24+ /// </summary>
25+ /// <param name="boundedLength">The bounded length.</param>
26+ /// <exception cref="ArgumentOutOfRangeException"></exception>
2227 public MpscBoundedBuffer ( int boundedLength )
2328 {
2429 if ( boundedLength < 0 )
@@ -33,8 +38,14 @@ public MpscBoundedBuffer(int boundedLength)
3338 mask = boundedLength - 1 ;
3439 }
3540
41+ /// <summary>
42+ /// The bounded capacity.
43+ /// </summary>
3644 public int Capacity => buffer . Length ;
3745
46+ /// <summary>
47+ /// Gets the number of items contained in the buffer.
48+ /// </summary>
3849 public int Count
3950 {
4051 get
@@ -68,7 +79,14 @@ private int GetCount(int head, int tail)
6879 return 0 ;
6980 }
7081
71- // thread safe
82+ /// <summary>
83+ /// Tries to add the specified item.
84+ /// </summary>
85+ /// <param name="item">The item to be added.</param>
86+ /// <returns>A BufferStatus value indicating whether the operation succeeded.</returns>
87+ /// <remarks>
88+ /// Thread safe.
89+ /// </remarks>
7290 public BufferStatus TryAdd ( T item )
7391 {
7492 int head = Volatile . Read ( ref headAndTail . Head ) ;
@@ -91,7 +109,15 @@ public BufferStatus TryAdd(T item)
91109 return BufferStatus . Contended ;
92110 }
93111
94- // thread safe for single try take/drain + multiple try add
112+
113+ /// <summary>
114+ /// Tries to remove an item.
115+ /// </summary>
116+ /// <param name="item">The item to be removed.</param>
117+ /// <returns>A BufferStatus value indicating whether the operation succeeded.</returns>
118+ /// <remarks>
119+ /// Thread safe for single try take/drain + multiple try add.
120+ /// </remarks>
95121 public BufferStatus TryTake ( out T item )
96122 {
97123 int head = Volatile . Read ( ref headAndTail . Head ) ;
@@ -119,7 +145,14 @@ public BufferStatus TryTake(out T item)
119145 return BufferStatus . Success ;
120146 }
121147
122- // thread safe for single try take/drain + multiple try add
148+ /// <summary>
149+ /// Drains the buffer into the specified array segment.
150+ /// </summary>
151+ /// <param name="output">The output buffer</param>
152+ /// <returns>The number of items written to the output buffer.</returns>
153+ /// <remarks>
154+ /// Thread safe for single try take/drain + multiple try add.
155+ /// </remarks>
123156 public int DrainTo ( ArraySegment < T > output )
124157 {
125158 int head = Volatile . Read ( ref headAndTail . Head ) ;
@@ -156,7 +189,12 @@ public int DrainTo(ArraySegment<T> output)
156189 return outCount ;
157190 }
158191
159- // Not thread safe
192+ /// <summary>
193+ /// Removes all values from the buffer.
194+ /// </summary>
195+ /// <remarks>
196+ /// Not thread safe.
197+ /// </remarks>
160198 public void Clear ( )
161199 {
162200 buffer = new T [ buffer . Length ] ;
0 commit comments