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