• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FILLP_LF_RING_H
17 #define FILLP_LF_RING_H
18 #include "utils.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define LF_RING_NAMESIZE 32
25 
26 #ifndef LF_RING_PAUSE_REP_COUNT
27 /** Yield after pause num of times, no yield if FTDP_RING_PAUSE_REP not defined. */
28 #define LF_RING_PAUSE_REP_COUNT 0
29 #endif
30 struct FillpLfRing {
31     char name[LF_RING_NAMESIZE];
32 
33     /* Ring producer status */
34     struct _prod {
35         volatile FILLP_ULONG head;
36         volatile FILLP_ULONG tail;
37     } prod;
38 
39     struct _cons {
40         volatile FILLP_ULONG head;
41         volatile FILLP_ULONG tail;
42     } cons;
43 
44     FILLP_ULONG size;
45     FILLP_BOOL prodSafe;
46     FILLP_BOOL consSafe;
47     FILLP_UINT8 padd[6];
48     /* Should be last element of the structure. DO NOT reorder or change */
49     void *ringCache[1]; /* Data */
50 };
51 
52 /*******************************************************************************
53     Function    : FillpLfRingInit
54 
55     Description : This function will be invoked to init the lock-free queue.
56 
57     Input       : ring - lock-free queue to be initialized
58                   name - name to be added to the lock-free queue
59                   size - size of lock-free queue
60 
61     Output      : ring - initialized lock-free queue
62 
63     Return      : None
64 *******************************************************************************/
65 void FillpLfRingInit(struct FillpLfRing *ring, char *name, size_t size);
66 
67 /*******************************************************************************
68     Function    : FillpLfRingCalMemSize
69 
70     Description : This function will be invoked to calculate the memory size
71                   required for lock-free queue, based on size.
72 
73     Input       : size - no of items of lock-free queue
74 
75     Output      : None
76 
77     Return      : Memory size of lock-free queue
78 *******************************************************************************/
79 size_t FillpLfRingCalMemSize(size_t size);
80 
81 /* multi-consumers safe */
82 /*******************************************************************************
83     Function    : FillpLfRingMpEnqueue
84 
85     Description : This function will be invoked to add data to lock-free queue.
86 
87     Input       : ring - lock-free queue to be initialized
88                   dataTable - data table to be added to lock-free queue
89                   count -
90 
91     Output      : None
92 
93     Return      : Memory size of lock-free queue
94 *******************************************************************************/
95 FillpErrorType FillpLfRingMpEnqueue(struct FillpLfRing *ring, void **dataTable, FILLP_UINT count);
96 
97 /* multi-consumers safe */
98 /*******************************************************************************
99     Function    : FillpLfRingMcDequeue
100 
101     Description : This function will be invoked to remove a data to lock-free
102                   queue.
103 
104     Input       : ring - lock-free queue to be initialized
105                   dataTable - data table to be added to lock-free queue
106                   count -
107 
108     Output      : None
109 
110     Return      : ERR_OK if success, or Error codes on failures
111 *******************************************************************************/
112 FILLP_INT FillpLfRingMcDequeue(struct FillpLfRing *ring, void **dataTable, FILLP_UINT count);
113 
114 FILLP_INT FillpRingEmpty(const struct FillpLfRing *r);
115 
116 
117 void FillpLfRingSetConsSafe(struct FillpLfRing *ring, FILLP_BOOL safe);
118 
119 void FillpLfRingSetProdSafe(struct FillpLfRing *ring, FILLP_BOOL safe);
120 
121 FILLP_INT FillpRingFreeEntries(const struct FillpLfRing *r);
122 
123 FILLP_ULONG FillpRingValidOnes(struct FillpLfRing *r);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 #endif /* FILLP_LF_RING_H */
129