FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
callback_data.h File Reference

Callback multiplex scheme. More...

+ Include dependency graph for callback_data.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define clib_callback_data_typedef(set_t_, cb_t_)
 Declare and define a callback set type. More...
 
#define clib_callback_data_init(set_, lock_)
 Initialize a callback set. More...
 
#define clib_callback_data_add(set_, value_)
 Add a callback to the specified callback set. More...
 
#define clib_callback_data_remove(set_, fp_)
 Remove a callback from the specified callback set. More...
 
#define clib_callback_data_swap(set_, fp_, value_)
 Swap a callback in the specified callback set. More...
 
#define clib_callback_data_ensure(set_, value_)
 Ensure a callback is in the specified callback set. More...
 
#define clib_callback_data_enable_disable(set_, fp_, ena_)
 Enable/Disable the specified callback. More...
 
#define clib_callback_data_get_value(set_, fp_, v_)
 Get the value of a callback, if set. More...
 
#define clib_callback_data_is_set(set_, fp_)
 Check if callback is set. More...
 
#define clib_callback_data_check_and_get(set_)
 Check for and get current callback set. More...
 
#define clib_callback_data_call_vec(vec_, ...)
 Iterate and call a callback vector. More...
 
#define clib_callback_data_call(set_, ...)
 Call the specified callback set. More...
 
#define clib_callback_data_prefetch(set_)
 prefetch the callback set More...
 

Detailed Description

Callback multiplex scheme.

Definition in file callback_data.h.

Macro Definition Documentation

◆ clib_callback_data_add

#define clib_callback_data_add (   set_,
  value_ 
)
Value:
do { \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) next_ = (set_)->next; \
if (PREDICT_TRUE (next_ == 0)) \
{ \
next_ = (set_)->spare; \
(set_)->spare = 0; \
vec_append (next_, (set_)->curr); \
} \
u32 sz_ = vec_len (next_); \
vec_validate (next_, sz_); \
next_[sz_] = (value_); \
(set_)->next = next_; \
clib_spinlock_unlock_if_init ((set_)->lock); \
} while (0)

Add a callback to the specified callback set.

Parameters
set_The callback set
value_The value_ to assign the callback

Add a callback from the indicated callback set. If the set is currently being iterated, then the change will be applied after the current full iteration, and prior to the next full iteration.

Definition at line 57 of file callback_data.h.

◆ clib_callback_data_call

#define clib_callback_data_call (   set_,
  ... 
)
Value:
do { \
typeof ((set_)->curr) v_ = clib_callback_data_check_and_get(set_); \
clib_callback_data_iterate (v_, __VA_ARGS__); \
} while (0)

Call the specified callback set.

Parameters
set_the callback set
varargsadditional callback parameters

Definition at line 293 of file callback_data.h.

◆ clib_callback_data_call_vec

#define clib_callback_data_call_vec (   vec_,
  ... 
)
Value:
do \
{ \
u32 sz_ = vec_len (vec_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
{ \
clib_prefetch_store (&vec_[i_ + 1]); \
(vec_[i_].fp) (&vec_[i_], __VA_ARGS__); \
} \
} \
while (0)

Iterate and call a callback vector.

Parameters
vec_the callback vector
varargsadditional callback parameters

Definition at line 276 of file callback_data.h.

◆ clib_callback_data_check_and_get

#define clib_callback_data_check_and_get (   set_)
Value:
({ \
typeof ((set_)->curr) curr_ = (set_)->curr; \
if (PREDICT_FALSE ((set_)->next != 0)) \
{ \
clib_spinlock_lock_if_init ((set_)->lock); \
vec_reset_length (curr_); \
(set_)->spare = curr_; \
curr_ = (set_)->next; \
(set_)->next = 0; \
if (PREDICT_FALSE (0 == vec_len (curr_))) \
vec_free (curr_); \
(set_)->curr = curr_; \
clib_spinlock_unlock_if_init ((set_)->lock); \
} \
curr_; \
})

Check for and get current callback set.

Parameters
set_the callback set
varargsadditional callback parameters

Definition at line 254 of file callback_data.h.

◆ clib_callback_data_enable_disable

#define clib_callback_data_enable_disable (   set_,
  fp_,
  ena_ 
)
Value:
do { \
if (ena_) \
{ \
typeof ((set_)->next[0]) data_ = { .fp = (fp_) }; \
clib_callback_data_add ((set_), data_); \
} \
clib_callback_data_remove ((set_), (fp_)); \
} while (0)

Enable/Disable the specified callback.

Parameters
set_The callback set
fp_The callback function
ena_1 to enable, 0 to disable

Enable or disable a callback function, with no data.

Definition at line 189 of file callback_data.h.

◆ clib_callback_data_ensure

#define clib_callback_data_ensure (   set_,
  value_ 
)
Value:
do { \
int found_ = 0; \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) next_ = (set_)->next; \
if (PREDICT_TRUE (next_ == 0)) \
{ \
next_ = (set_)->spare; \
(set_)->spare = 0; \
vec_append (next_, (set_)->curr); \
} \
u32 sz_ = vec_len (next_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
if (next_[i_].fp == (value_).fp) \
{ \
found_ = 1; \
break; \
} \
if (!found_) \
vec_validate (next_, i_); \
next_[i_] = (value_); \
(set_)->next = next_; \
clib_spinlock_unlock_if_init ((set_)->lock); \
} while(0)

Ensure a callback is in the specified callback set.

Parameters
set_The callback set
value_The value_ to assign the callback
Returns
1 if the function was swapped, 0 if not

Add or swap a callback in the indicated callback set. If the callback is already in the set, it is replaced. If the callback is not found, then it is added. If the set is currently being iterated, then the change will be applied after the current full iteration, and prior to the next full iteration.

Definition at line 156 of file callback_data.h.

◆ clib_callback_data_get_value

#define clib_callback_data_get_value (   set_,
  fp_,
  v_ 
)
Value:
({ \
int found_ = 0; \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) search_ = (set_)->next; \
if (PREDICT_TRUE (search_ == 0)) \
search_ = (set_)->curr; \
u32 sz_ = vec_len (search_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
if (search_[i_].fp == (fp_)) \
{ \
(v_) = search_[i]; \
found_ = 1; \
break; \
} \
clib_spinlock_unlock_if_init ((set_)->lock); \
found_; \
})

Get the value of a callback, if set.

Parameters
set_The callback set
fp_The callback function
v_Set to the callback's current value
Returns
1 if the function is in the set, 0 if not

Definition at line 206 of file callback_data.h.

◆ clib_callback_data_init

#define clib_callback_data_init (   set_,
  lock_ 
)
Value:
do { \
(set_)->lock = (lock_); \
(set_)->curr = 0; \
(set_)->next = 0; \
(set_)->spare = 0; \
} while (0)

Initialize a callback set.

Parameters
set_The callback set to initialize
lock_The lock to use, if any

Definition at line 41 of file callback_data.h.

◆ clib_callback_data_is_set

#define clib_callback_data_is_set (   set_,
  fp_ 
)
Value:
({ \
int found_ = 0; \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) search_ = (set_)->next; \
if (PREDICT_TRUE (search_ == 0)) \
search_ = (set_)->curr; \
u32 sz_ = vec_len (search_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
if (search_[i_].fp == (fp_)) \
{ \
found_ = 1; \
break; \
} \
clib_spinlock_unlock_if_init ((set_)->lock); \
found_; \
})

Check if callback is set.

Parameters
set_The callback set
fp_The callback function
Returns
1 if the function is in the set, 0 if not

Definition at line 231 of file callback_data.h.

◆ clib_callback_data_prefetch

#define clib_callback_data_prefetch (   set_)
Value:
do \
{ \
if (PREDICT_FALSE ((set_)->curr)) \
clib_prefetch_store ((set_)->curr); \
} \
while (0)

prefetch the callback set

Parameters
set_The callback set

Definition at line 302 of file callback_data.h.

◆ clib_callback_data_remove

#define clib_callback_data_remove (   set_,
  fp_ 
)
Value:
({ \
int found_ = 0; \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) next_ = (set_)->next; \
if (PREDICT_TRUE (next_ == 0)) \
{ \
next_ = (set_)->spare; \
(set_)->spare = 0; \
vec_append (next_, (set_)->curr); \
} \
u32 sz_ = vec_len (next_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
if (next_[i_].fp == (fp_)) \
{ \
vec_delete (next_, 1, i_); \
found_ = 1; \
break; \
} \
(set_)->next = next_; \
clib_spinlock_unlock_if_init ((set_)->lock); \
found_; \
})

Remove a callback from the specified callback set.

Parameters
set_The callback set
fp_The current callback function
Returns
1 if the function was removed, 0 if not

Remove a callback from the indicated callback set. Idempotent. If the set is currently being iterated, then the change will be applied after the current full iteration, and prior to the next full iteration.

Definition at line 84 of file callback_data.h.

◆ clib_callback_data_swap

#define clib_callback_data_swap (   set_,
  fp_,
  value_ 
)
Value:
({ \
int found_ = 0; \
clib_spinlock_lock_if_init ((set_)->lock); \
typeof ((set_)->next) next_ = (set_)->next; \
if (PREDICT_TRUE (next_ == 0)) \
{ \
next_ = (set_)->spare; \
(set_)->spare = 0; \
vec_append (next_, (set_)->curr); \
} \
u32 sz_ = vec_len (next_); \
u32 i_; \
for (i_ = 0; i_ < sz_; i_++) \
if (next_[i_].fp == (fp_)) \
{ \
next_[i_] = (value_); \
found_ = 1; \
break; \
} \
(set_)->next = next_; \
clib_spinlock_unlock_if_init ((set_)->lock); \
found_; \
})

Swap a callback in the specified callback set.

Parameters
set_The callback set
fp_The current callback function
value_The value_ to assign the callback
Returns
1 if the function was swapped, 0 if not

Swap a callback in the indicated callback set. If the callback is not found, then nothing is done. If the set is currently being iterated, then the change will be applied after the current full iteration, and prior to the next full iteration.

Definition at line 120 of file callback_data.h.

◆ clib_callback_data_typedef

#define clib_callback_data_typedef (   set_t_,
  cb_t_ 
)
Value:
typedef struct set_t_ \
{ \
cb_t_* curr; \
cb_t_* volatile next; \
cb_t_* spare; \
clib_spinlock_t* lock; \
} set_t_

Declare and define a callback set type.

Parameters
set_t_The set type to define
cb_t_The callback type to use

Definition at line 28 of file callback_data.h.

next
u16 * next
Definition: nat44_ei_out2in.c:718
clib_callback_data_remove
#define clib_callback_data_remove(set_, fp_)
Remove a callback from the specified callback set.
Definition: callback_data.h:84
clib_callback_data_check_and_get
#define clib_callback_data_check_and_get(set_)
Check for and get current callback set.
Definition: callback_data.h:254
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
i
int i
Definition: flowhash_template.h:376
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125