@@ -10,20 +10,29 @@ const ptrdiff_t CsArc_ListOffsets_[] = {
1010 [CslDirectDel ] = offsetof(CsArc , Del ),
1111};
1212
13- #define CsArc_c (arc ) ((arc)->B1.capacity)
14- #define CsArc_2c (arc ) ((arc)->B2.capacity)
15- #define CsArc_p (arc ) ((arc)->T1.capacity)
16- #define CsArc_p1 (arc ) ((arc)->T2.capacity)
17-
1813#define CsArc_Move (arc , entry , src , dst ) \
1914 do { \
2015 NDNDPDK_ASSERT((entry)->arcList == CslDirect##src); \
2116 CsList_Remove(&(arc)->src, (entry)); \
2217 (entry)->arcList = CslDirect##dst; \
2318 CsList_Append(&(arc)->dst, (entry)); \
2419 N_LOGV("^ move=%p from=" #src " to=" #dst, (entry)); \
20+ (arc)->moveCb((arc)->moveCbArg, (entry), CslDirect##src, CslDirect##dst); \
2521 } while (false)
2622
23+ /**
24+ * @brief Default handler when entry is moved between lists.
25+ *
26+ * If an entry is moved from T1/T2 to a non-T1/T2 list, its Data packet is released.
27+ */
28+ __attribute__((nonnull )) static inline void
29+ CsArc_MoveHandler (__rte_unused void * arg , CsEntry * entry , CsListID src , CsListID dst )
30+ {
31+ if ((src == CslDirectT1 || src == CslDirectT2 ) && !(dst == CslDirectT1 || dst == CslDirectT2 )) {
32+ CsEntry_Clear (entry );
33+ }
34+ }
35+
2736__attribute__((nonnull )) static inline void
2837CsArc_SetP (CsArc * arc , double p )
2938{
@@ -45,20 +54,21 @@ CsArc_Init(CsArc* arc, uint32_t capacity)
4554 CsArc_c (arc ) = capacity ;
4655 CsArc_2c (arc ) = 2 * capacity ;
4756 CsArc_SetP (arc , 0.0 );
57+
58+ arc -> moveCb = CsArc_MoveHandler ;
59+ arc -> moveCbArg = NULL ;
4860}
4961
5062__attribute__((nonnull )) static void
5163CsArc_Replace (CsArc * arc , bool isB2 )
5264{
53- CsEntry * moving = NULL ;
5465 if (isB2 ? arc -> T1 .count >= CsArc_p1 (arc ) : arc -> T1 .count > CsArc_p (arc )) {
55- moving = CsList_GetFront (& arc -> T1 );
66+ CsEntry * moving = CsList_GetFront (& arc -> T1 );
5667 CsArc_Move (arc , moving , T1 , B1 );
5768 } else {
58- moving = CsList_GetFront (& arc -> T2 );
69+ CsEntry * moving = CsList_GetFront (& arc -> T2 );
5970 CsArc_Move (arc , moving , T2 , B2 );
6071 }
61- CsEntry_Clear (moving );
6272}
6373
6474__attribute__((nonnull )) static void
@@ -102,7 +112,6 @@ CsArc_AddNew(CsArc* arc, CsEntry* entry)
102112 NDNDPDK_ASSERT (arc -> B1 .count == 0 );
103113 N_LOGV ("^ evict-from=T1" );
104114 CsEntry * deleting = CsList_GetFront (& arc -> T1 );
105- CsEntry_Clear (deleting );
106115 CsArc_Move (arc , deleting , T1 , Del );
107116 }
108117 } else {
0 commit comments