You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/11/18 03:18:45 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #2315: Add common circular buffer management

patacongo commented on a change in pull request #2315:
URL: https://github.com/apache/incubator-nuttx/pull/2315#discussion_r525720509



##########
File path: include/nuttx/mm/circ_buf.h
##########
@@ -0,0 +1,308 @@
+/****************************************************************************
+ * include/nuttx/mm/circ_buf.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_MM_CIRC_BUF_H
+#define __INCLUDE_NUTTX_MM_CIRC_BUF_H
+
+/* Note about locking: There is no locking required until only one reader
+ * and one writer is using the circular buffer.
+ * For multiple writer and one reader there is only a need to lock the
+ * writer. And vice versa for only one writer and multiple reader there is
+ * only a need to lock the reader.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This structure describes circular buffer */
+
+struct circ_buf_s
+{
+  FAR void *base;
+  size_t    size;
+  size_t    head;
+  size_t    tail;
+  bool      external;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: circ_buf_init
+ *
+ * Description:
+ *   Initialize a circular buffer.
+ *
+ * Input Parameters:
+ *   circ  - Address of the circular buffer to be used.
+ *   base  - A pointer to circular buffer's internal buffer. It can provide
+ *           by called context because sometimes the creation of buffer
+ *           is speical or preallocated, eg: DMA buffer.
+ *           It also can alloc by this api if base is NULL.
+ *   bytes - The size of the internal buffer.
+ *
+ * Returned Value:
+ *   Zero on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int circ_buf_init(FAR struct circ_buf_s *circ,
+                  FAR void *base, size_t bytes);
+
+/****************************************************************************
+ * Name: circ_buf_resize
+ *
+ * Description:
+ *   Resize a circular buffer (change buffer size).
+ *
+ * Input Parameters:
+ *   circ  - Address of the circular buffer to be used.
+ *   bytes - The size of the internal buffer.
+ *
+ * Returned Value:
+ *   Zero on success; A negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int circ_buf_resize(FAR struct circ_buf_s *circ, size_t bytes);
+
+/****************************************************************************
+ * Name: circ_buf_uninit
+ *
+ * Description:
+ *   Free the circular buffer.
+ *
+ * Input Parameters:
+ *   circ  - Address of the circular buffer to be used.
+ ****************************************************************************/
+
+void circ_buf_uninit(FAR struct circ_buf_s *circ);

Review comment:
       No, you should follow the NuttX naming conventions as specified in the Coding Standard:  https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#funcname
   
   Personal preference is irrelevant.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org