@@ -10,20 +10,29 @@ const ptrdiff_t CsArc_ListOffsets_[] = {
10
10
[CslDirectDel ] = offsetof(CsArc , Del ),
11
11
};
12
12
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
-
18
13
#define CsArc_Move (arc , entry , src , dst ) \
19
14
do { \
20
15
NDNDPDK_ASSERT((entry)->arcList == CslDirect##src); \
21
16
CsList_Remove(&(arc)->src, (entry)); \
22
17
(entry)->arcList = CslDirect##dst; \
23
18
CsList_Append(&(arc)->dst, (entry)); \
24
19
N_LOGV("^ move=%p from=" #src " to=" #dst, (entry)); \
20
+ (arc)->moveCb((arc)->moveCbArg, (entry), CslDirect##src, CslDirect##dst); \
25
21
} while (false)
26
22
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
+
27
36
__attribute__((nonnull )) static inline void
28
37
CsArc_SetP (CsArc * arc , double p )
29
38
{
@@ -45,20 +54,21 @@ CsArc_Init(CsArc* arc, uint32_t capacity)
45
54
CsArc_c (arc ) = capacity ;
46
55
CsArc_2c (arc ) = 2 * capacity ;
47
56
CsArc_SetP (arc , 0.0 );
57
+
58
+ arc -> moveCb = CsArc_MoveHandler ;
59
+ arc -> moveCbArg = NULL ;
48
60
}
49
61
50
62
__attribute__((nonnull )) static void
51
63
CsArc_Replace (CsArc * arc , bool isB2 )
52
64
{
53
- CsEntry * moving = NULL ;
54
65
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 );
56
67
CsArc_Move (arc , moving , T1 , B1 );
57
68
} else {
58
- moving = CsList_GetFront (& arc -> T2 );
69
+ CsEntry * moving = CsList_GetFront (& arc -> T2 );
59
70
CsArc_Move (arc , moving , T2 , B2 );
60
71
}
61
- CsEntry_Clear (moving );
62
72
}
63
73
64
74
__attribute__((nonnull )) static void
@@ -102,7 +112,6 @@ CsArc_AddNew(CsArc* arc, CsEntry* entry)
102
112
NDNDPDK_ASSERT (arc -> B1 .count == 0 );
103
113
N_LOGV ("^ evict-from=T1" );
104
114
CsEntry * deleting = CsList_GetFront (& arc -> T1 );
105
- CsEntry_Clear (deleting );
106
115
CsArc_Move (arc , deleting , T1 , Del );
107
116
}
108
117
} else {
0 commit comments