• 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 #ifndef LIB_RING_BUFFER_H
13 #define LIB_RING_BUFFER_H
14 
15 #include <common/types.h>
16 
17 #define RING_BUFFER_FULL     1
18 #define RING_BUFFER_NOT_FULL 0
19 #define MSG_OP_SUCCESS       1
20 #define MSG_OP_FAILURE       0
21 
22 /*
23  * Ring buffer struct layout
24  * buffer_size: size_t, size of whole struct including the meta data
25  * consumer_offset: int
26  * producer_offset: int
27  * msg_size: size_t, size of the msg that will be stored in the buffer
28  * There is also a data buffer to actually store data, closely after the meta data above.
29  */
30 
31 struct ring_buffer {
32     size_t buffer_size;
33     off_t consumer_offset;
34     off_t producer_offset;
35     size_t msg_size;
36 };
37 
38 int get_one_msg(struct ring_buffer *ring_buf, void *msg);
39 int set_one_msg(struct ring_buffer *ring_buf, void *msg);
40 int if_buffer_full(struct ring_buffer *ring_buf);
41 
42 #endif /* LIB_RING_BUFFER_H */