FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
callback.h File Reference

Callback multiplex scheme For a fully worked-out example, see .../src/vlib/main. More...

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

Go to the source code of this file.

Macros

#define clib_callback_enable_disable(h, tmp, l, f, enable)
 Add or remove a callback to the specified callback set. More...
 
#define clib_call_callbacks(h, ...)
 call the specified callback set More...
 
#define clib_callback_is_set(h, l, f)
 predicate function says whether the specified function is enabled More...
 

Detailed Description

Callback multiplex scheme For a fully worked-out example, see .../src/vlib/main.

[ch] and .../src/plugins/perfmon.c

Definition in file callback.h.

Macro Definition Documentation

◆ clib_call_callbacks

#define clib_call_callbacks (   h,
  ... 
)
Value:
do { \
/* \
* Note: fp exists to shut up gcc-6, which \
* produces a warning not seen with gcc-7 or 8 \
*/ \
void (*fp)(void *a1, ...); \
int i; \
for (i = 0; i < vec_len (h); i++) \
{ \
fp = (void *)(h[i]); \
(*fp) (__VA_ARGS__); \
} \
} while (0);
int i
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)

call the specified callback set

Parameters
hthe callback set
varargsadditional callback parameters

Definition at line 67 of file callback.h.

◆ clib_callback_enable_disable

#define clib_callback_enable_disable (   h,
  tmp,
  l,
  f,
  enable 
)
Value:
do { \
void *tmp2; \
clib_spinlock_lock_if_init(&l); \
vec_reset_length(tmp); \
vec_append(tmp, h); \
if (enable) \
vec_add1 (tmp,(void *)f); \
else \
{ \
int i; \
for (i = 0; i < vec_len (tmp); i++) \
if (((void *)tmp[i]) == (void *)f) \
{ \
vec_delete (tmp, 1, i); \
break; \
} \
} \
tmp2 = h; \
CLIB_MEMORY_STORE_BARRIER(); \
h = tmp; \
tmp = tmp2; \
clib_spinlock_unlock_if_init(&l); \
} while(0);
int i
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)

Add or remove a callback to the specified callback set.

Parameters
hhead of the callback vector
tmpvector to build result
lclib_spinlock_t lock to protect the vector, may be 0
ffunction to add or remove
enable1 adds f to the vector, 0 removes f from the vector

Add or remove a callback from the indicated callback vector. Caller must provide locking to prevent > 1 concurrent writer Swaps the head of the callback vector and a tmp vector in one motion, after a write barrier to ensure that the write is atomic.

Definition at line 38 of file callback.h.

◆ clib_callback_is_set

#define clib_callback_is_set (   h,
  l,
 
)
Value:
({ \
int _i; \
int _found = 0; \
clib_spinlock_lock_if_init(&l); \
for (_i = 0; _i < vec_len (h); _i++) \
if (((void *)h[_i]) == (void *) f) \
{ \
_found=1; \
break; \
} \
clib_spinlock_unlock_if_init(&l); \
_found; \
})
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)

predicate function says whether the specified function is enabled

Parameters
hthe callback set
lclib_spinlock_t lock to protect the vector, may be 0
fthe function to search for
Returns
1 if the function is enabled, 0 if not

Definition at line 88 of file callback.h.