• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include <chcore/type.h>
14 #include <sys/types.h>
15 
16 #define RING_BUFFER_FULL     1
17 #define RING_BUFFER_NOT_FULL 0
18 #define MSG_OP_SUCCESS       1
19 #define MSG_OP_FAILURE       0
20 
21 /*
22  * Ring buffer struct layout
23  * buffer_size:                         size_t, size of whole struct including
24  * the meta data consumer_offset, producer_offset:    int msg_size: size_t, size
25  * of the msg that will be stored in the buffer There is also a data buffer to
26  * actually store data, closely after the meta data above.
27  */
28 
29 struct ring_buffer {
30     size_t buffer_size;
31     off_t consumer_offset;
32     off_t producer_offset;
33     size_t msg_size;
34 };
35 
36 int get_one_msg(struct ring_buffer *ring_buf, void *msg);
37 int set_one_msg(struct ring_buffer *ring_buf, void *msg);
38 int if_buffer_full(struct ring_buffer *ring_buf);
39 struct ring_buffer *new_ringbuffer(int msg_num, size_t msg_size);
40 void free_ringbuffer(struct ring_buffer *ring_buf);
41