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 #include "lf_ring.h"
17 #include "queue.h"
18 #include "log.h"
19 #include "fillp.h"
20 #include "dympool.h"
21 #include "fillp_buf_item.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
FillpCreateDympCreateCb(DympItemType * item)27 static inline FILLP_INT FillpCreateDympCreateCb(DympItemType *item)
28 {
29     struct FillpPcbItem *pcbItem = (struct FillpPcbItem *)DYMP_ITEM_DATA(item);
30     pcbItem->buf.p = (char *)pcbItem + sizeof(struct FillpPcbItem);
31     pcbItem->fpcb = FILLP_NULL_PTR;
32     return FILLP_OK;
33 }
34 
FillpCreateBufItemPool(int poolSize,int initSize,int pktSize)35 void *FillpCreateBufItemPool(int poolSize, int initSize, int pktSize)
36 {
37     int initialSize = UTILS_MIN(poolSize, initSize);
38     DympoolItemOperaCbSt itemOperaCb = {FillpCreateDympCreateCb, FILLP_NULL_PTR};
39     return (void *)DympCreatePool(initialSize, poolSize,
40                                   ((int)sizeof(struct FillpPcbItem) + (int)(pktSize + FILLP_HLEN)),
41                                   FILLP_FALSE, &itemOperaCb);
42 }
43 
FillbufItemPoolSetConflictSafe(void * pool,FILLP_BOOL consSafe,FILLP_BOOL prodSafe)44 void FillbufItemPoolSetConflictSafe(void *pool, FILLP_BOOL consSafe, FILLP_BOOL prodSafe)
45 {
46     DympSetConsSafe((DympoolType *)pool, consSafe);
47     DympSetProdSafe((DympoolType *)pool, prodSafe);
48 }
49 
FillpMallocBufItem(void * pool,void ** data,int throttleGrow)50 int FillpMallocBufItem(void *pool, void **data, int throttleGrow)
51 {
52     return DympAlloc((DympoolType *)pool, data, throttleGrow);
53 }
54 
FillpAskMoreBufItem(void * pool,int stepSize,int throttleGrow)55 int FillpAskMoreBufItem(void *pool, int stepSize, int throttleGrow)
56 {
57     return DympAskMoreMemory((DympoolType *)pool, stepSize, throttleGrow);
58 }
59 
FillpFreeBufItem(void * data)60 void FillpFreeBufItem(void *data)
61 {
62     struct FillpPcb *fpcb = FILLP_NULL_PTR;
63     if (data == FILLP_NULL_PTR) {
64         return;
65     }
66     fpcb = (struct FillpPcb *)(((struct FillpPcbItem *)data)->fpcb);
67     if ((fpcb != FILLP_NULL_PTR) && (fpcb->send.preItem == data)) {
68         fpcb->send.preItem = FILLP_NULL_PTR;
69     }
70     FillpFrameFreeItem((struct FillpPcbItem *)data);
71     DympFree(data);
72 }
73 
74 
FillpDestroyBufItemPool(void * pool)75 void FillpDestroyBufItemPool(void *pool)
76 {
77     if (pool == FILLP_NULL_PTR) {
78         return;
79     }
80 
81     DympDestroyPool((DympoolType *)pool);
82 }
83 
84 #ifdef __cplusplus
85 }
86 #endif
87