<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: libmaple/ring_buffer.h</title>
		<link>http://forums.leaflabs.com/topic.php?id=689</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:20:01 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=689" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-4131</link>
			<pubDate>Mon, 04 Apr 2011 12:45:46 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4131@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;x893,&#60;/p&#62;
&#60;p&#62;Actually, the size of the buffer is 63, not 64.  One byte is always left free to distinguish empty from full.  This is what makes the logic correct.&#60;/p&#62;
&#60;p&#62;I was unable to reproduce your report, although it's possible that I misunderstood you.  Can you please submit some sample code along with your description of the problem?  For example, here is a commit I have just pushed into master which tests basic ring_buffer functionality:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/987fa5f433e0cd41b1621dad8b4e331cf82d49f3&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/987fa5f433e0cd41b1621dad8b4e331cf82d49f3&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The relevant new file is examples/test-ring-buffer-insertion.cpp:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/987fa5f433e0cd41b1621dad8b4e331cf82d49f3/examples/test-ring-buffer-insertion.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/987fa5f433e0cd41b1621dad8b4e331cf82d49f3/examples/test-ring-buffer-insertion.cpp&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Here is the output it gives on my Maple Rev 5; everything looks fine to me:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Beginning test.&#60;/p&#62;
&#60;p&#62;resetting ring buffer.&#60;br /&#62;
ring buffer contents:&#60;br /&#62;
rb_push_insert()-ing 63 bytes.&#60;br /&#62;
rb_full_count(rb) = 63&#60;br /&#62;
ring buffer contents: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63&#60;br /&#62;
------------------------------&#60;br /&#62;
resetting ring buffer.&#60;br /&#62;
ring buffer contents:&#60;br /&#62;
rb_push_insert()-ing 64 bytes.&#60;br /&#62;
rb_full_count(rb) = 63&#60;br /&#62;
ring buffer contents: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64&#60;br /&#62;
------------------------------&#60;br /&#62;
resetting ring buffer.&#60;br /&#62;
ring buffer contents:&#60;br /&#62;
rb_safe_insert()-ing 63 bytes.&#60;br /&#62;
rb_full_count(rb) = 63&#60;br /&#62;
ring buffer contents: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63&#60;br /&#62;
------------------------------&#60;br /&#62;
resetting ring buffer.&#60;br /&#62;
ring buffer contents:&#60;br /&#62;
rb_safe_insert()-ing 64 bytes.&#60;br /&#62;
rb_full_count(rb) = 63&#60;br /&#62;
ring buffer contents: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63&#60;br /&#62;
------------------------------&#60;/p&#62;
&#60;p&#62;Test finished.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;In the future, when discussing problems, can you please report the version of libmaple or the Maple IDE that you are using?  If you are using 0.0.9, the ring_buffer implementation had many bugs which have been fixed in subsequent snapshot releases.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>x893 on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-4082</link>
			<pubDate>Tue, 29 Mar 2011 07:44:28 +0000</pubDate>
			<dc:creator>x893</dc:creator>
			<guid isPermaLink="false">4082@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Logic for count build only on head/tail calculations not correct.&#60;br /&#62;
Simple check any logic with next situation&#60;br /&#62;
i send 64 bytes (64 = size of buffer)&#60;br /&#62;
and rb_full_count(..) return zero !&#60;br /&#62;
For correct calculation need add counter to calculate insert/remove elements.&#60;br /&#62;
Correctly name ring_buffer - queue with maximum capacity and count of queued elements.&#60;/p&#62;
&#60;p&#62;I implement this logic (counter/tail/head) in my CAN library and no lost elements in any case.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3933</link>
			<pubDate>Thu, 17 Mar 2011 08:11:44 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">3933@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;yes.  sorry for the hasty implementation.&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/12aca5b72d62081c50fafc41e448841a4328a500&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/12aca5b72d62081c50fafc41e448841a4328a500&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>geoffreymbrown on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3930</link>
			<pubDate>Thu, 17 Mar 2011 07:43:23 +0000</pubDate>
			<dc:creator>geoffreymbrown</dc:creator>
			<guid isPermaLink="false">3930@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Isn't it easier to check &#34;not empty&#34;   head != tail rather than full count != 0 ?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3927</link>
			<pubDate>Thu, 17 Mar 2011 07:22:40 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">3927@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'd rather not force everyone to pay for checking if the buffer is empty in rb_remove(), so I've added an rb_safe_remove() (in the refactor branch) instead:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/8097736f3be70ed3a5550334b31e8cfeddc0bfcf&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/8097736f3be70ed3a5550334b31e8cfeddc0bfcf&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>geoffreymbrown on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3925</link>
			<pubDate>Thu, 17 Mar 2011 07:01:39 +0000</pubDate>
			<dc:creator>geoffreymbrown</dc:creator>
			<guid isPermaLink="false">3925@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, I missed that.  You might still want to make remove do the right thing&#60;br /&#62;
when the buffer is empty.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3920</link>
			<pubDate>Thu, 17 Mar 2011 06:38:18 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">3920@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the report.  This has been fixed in master for over a month:&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/ring_buffer.h&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/libmaple/ring_buffer.h&#60;/a&#62;&#60;br /&#62;
&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/usart.c#L83&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/libmaple/usart.c#L83&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;A snapshot was released with the new code (choose the 2011-02-13 snapshot release for your platform):&#60;br /&#62;
&#60;a href=&#34;http://static.leaflabs.com/pub/leaflabs/maple-ide/snapshots/&#34; rel=&#34;nofollow&#34;&#62;http://static.leaflabs.com/pub/leaflabs/maple-ide/snapshots/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>geoffreymbrown on "libmaple/ring_buffer.h"</title>
			<link>http://forums.leaflabs.com/topic.php?id=689#post-3918</link>
			<pubDate>Wed, 16 Mar 2011 20:45:34 +0000</pubDate>
			<dc:creator>geoffreymbrown</dc:creator>
			<guid isPermaLink="false">3918@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;This looks pretty broken:&#60;/p&#62;
&#60;p&#62;static inline uint32 rb_full_count(ring_buffer *rb) {&#60;br /&#62;
    return rb-&#38;gt;tail - rb-&#38;gt;head;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Suppose with have a 4 place ring buffer where tail = 0, head = 1  (i.e. there are&#60;br /&#62;
three items in the buffer).   Type conversion isn't going to magically&#60;br /&#62;
return 3.   I think what you want is&#60;/p&#62;
&#60;p&#62;(rb-&#38;gt;size + rb-&#38;gt;tail - rb-&#38;gt;head) &#38;amp; (rb-&#38;gt;size - 1)&#60;/p&#62;
&#60;p&#62;Also, your insert and remove routines are definitely unsafe.  Notice that&#60;br /&#62;
in libmaple/uart.c, you don't check to see if the buffer is full. The right&#60;br /&#62;
thing to do here is probably throw the character in the trash since you don't&#60;br /&#62;
have flow control.  Overflowing your buffer seems pretty crass.  &#60;/p&#62;
&#60;p&#62;I noticed that you call rb_remove in your usart_getc routine but also don't&#60;br /&#62;
check if the buffer is empty.  At the least this should fail in benign way&#60;br /&#62;
rather than manufacturing a buffer full of trash.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
