The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Revision:
170:e95d10626187
Parent:
169:a7c7b631e539
Child:
171:3a7713b1edbc
--- a/platform/CircularBuffer.h	Fri Jun 22 15:38:59 2018 +0100
+++ b/platform/CircularBuffer.h	Thu Sep 06 13:39:34 2018 +0100
@@ -24,17 +24,29 @@
 namespace internal {
 /* Detect if CounterType of the Circular buffer is of unsigned type. */
 template<typename T>
-struct is_unsigned { static const bool value = false; };
+struct is_unsigned {
+    static const bool value = false;
+};
 template<>
-struct is_unsigned<unsigned char> { static const bool value = true; };
+struct is_unsigned<unsigned char> {
+    static const bool value = true;
+};
 template<>
-struct is_unsigned<unsigned short> { static const bool value = true; };
+struct is_unsigned<unsigned short> {
+    static const bool value = true;
+};
 template<>
-struct is_unsigned<unsigned int> { static const bool value = true; };
+struct is_unsigned<unsigned int> {
+    static const bool value = true;
+};
 template<>
-struct is_unsigned<unsigned long> { static const bool value = true; };
+struct is_unsigned<unsigned long> {
+    static const bool value = true;
+};
 template<>
-struct is_unsigned<unsigned long long> { static const bool value = true; };
+struct is_unsigned<unsigned long long> {
+    static const bool value = true;
+};
 };
 
 /** \addtogroup platform */
@@ -52,7 +64,8 @@
 template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
 class CircularBuffer {
 public:
-    CircularBuffer() : _head(0), _tail(0), _full(false) {
+    CircularBuffer() : _head(0), _tail(0), _full(false)
+    {
         MBED_STATIC_ASSERT(
             internal::is_unsigned<CounterType>::value,
             "CounterType must be unsigned"
@@ -65,7 +78,8 @@
         );
     }
 
-    ~CircularBuffer() {
+    ~CircularBuffer()
+    {
     }
 
     /** Push the transaction to the buffer. This overwrites the buffer if it's
@@ -73,7 +87,8 @@
      *
      * @param data Data to be pushed to the buffer
      */
-    void push(const T& data) {
+    void push(const T &data)
+    {
         core_util_critical_section_enter();
         if (full()) {
             _tail++;
@@ -92,7 +107,8 @@
      * @param data Data to be popped from the buffer
      * @return True if the buffer is not empty and data contains a transaction, false otherwise
      */
-    bool pop(T& data) {
+    bool pop(T &data)
+    {
         bool data_popped = false;
         core_util_critical_section_enter();
         if (!empty()) {
@@ -109,7 +125,8 @@
      *
      * @return True if the buffer is empty, false if not
      */
-    bool empty() const {
+    bool empty() const
+    {
         core_util_critical_section_enter();
         bool is_empty = (_head == _tail) && !_full;
         core_util_critical_section_exit();
@@ -120,7 +137,8 @@
      *
      * @return True if the buffer is full, false if not
      */
-    bool full() const {
+    bool full() const
+    {
         core_util_critical_section_enter();
         bool full = _full;
         core_util_critical_section_exit();
@@ -130,7 +148,8 @@
     /** Reset the buffer
      *
      */
-    void reset() {
+    void reset()
+    {
         core_util_critical_section_enter();
         _head = 0;
         _tail = 0;
@@ -139,7 +158,8 @@
     }
 
     /** Get the number of elements currently stored in the circular_buffer */
-    CounterType size() const {
+    CounterType size() const
+    {
         core_util_critical_section_enter();
         CounterType elements;
         if (!_full) {
@@ -160,7 +180,8 @@
      * @param data Data to be peeked from the buffer
      * @return True if the buffer is not empty and data contains a transaction, false otherwise
      */
-    bool peek(T& data) const {
+    bool peek(T &data) const
+    {
         bool data_updated = false;
         core_util_critical_section_enter();
         if (!empty()) {
@@ -170,7 +191,7 @@
         core_util_critical_section_exit();
         return data_updated;
     }
-    
+
 private:
     T _pool[BufferSize];
     volatile CounterType _head;