Flowgrind
Advanced TCP traffic generator
fg_definitions.h File Reference

Common definitions used by the Flowgrind daemon, controller, and libs. More...

#include "config.h"

Go to the source code of this file.

Macros

#define likely(x)   __builtin_expect(!!(x), 1)
 These macros gain us a few percent of speed. More...
 
#define unlikely(x)   __builtin_expect(!!(x), 0) /** @} */
 These macros gain us a few percent of speed. More...
 
#define UNUSED_ARGUMENT(x)   (void)x
 Suppress warning for unused argument. More...
 
#define NARGS(...)   (sizeof((int[]){__VA_ARGS__})/sizeof(int))
 To determine the number of arguments in VA_ARGS. More...
 
#define foreach(iter, ...)
 foreach macro for iterating through enum values. More...
 
#define FN_APPLY(type, fn, ...)
 To vectorize an arbitrary function that takes any type of pointer. More...
 
#define free_all(...)   FN_APPLY(void, free, __VA_ARGS__);
 To free() an arbitrary number of variables. More...
 
#define ASSIGN_MIN(s, c)
 Assign value if it less than current one. More...
 
#define ASSIGN_MAX(s, c)
 Assign value if it's greater than current one. More...
 

Detailed Description

Common definitions used by the Flowgrind daemon, controller, and libs.

Definition in file fg_definitions.h.

Macro Definition Documentation

#define ASSIGN_MAX (   s,
 
)
Value:
({ typeof (s) _s = (s); \
typeof (c) _c = (c); \
if (_s < _c) s = c; })

Assign value if it's greater than current one.

Definition at line 68 of file fg_definitions.h.

#define ASSIGN_MIN (   s,
 
)
Value:
({ typeof (s) _s = (s); \
typeof (c) _c = (c); \
if (_s > _c) s = c; })

Assign value if it less than current one.

Definition at line 62 of file fg_definitions.h.

#define FN_APPLY (   type,
  fn,
  ... 
)
Value:
do { \
void *stopper = (int[]){0}; \
void **list = (type*[]){__VA_ARGS__, stopper}; \
for (int i=0; list[i] != stopper; i++) \
fn(list[i]); \
} while(0)

To vectorize an arbitrary function that takes any type of pointer.

Definition at line 51 of file fg_definitions.h.

#define foreach (   iter,
  ... 
)
Value:
for(int keep = 1, count = 0, size = NARGS(__VA_ARGS__); \
keep && count != size; keep = !keep, count++) \
for(iter = ((int[]){__VA_ARGS__}) + count; \
keep; keep = !keep)
#define NARGS(...)
To determine the number of arguments in VA_ARGS.

foreach macro for iterating through enum values.

Definition at line 44 of file fg_definitions.h.

#define free_all (   ...)    FN_APPLY(void, free, __VA_ARGS__);

To free() an arbitrary number of variables.

Definition at line 59 of file fg_definitions.h.

#define likely (   x)    __builtin_expect(!!(x), 1)

These macros gain us a few percent of speed.

Definition at line 34 of file fg_definitions.h.

#define NARGS (   ...)    (sizeof((int[]){__VA_ARGS__})/sizeof(int))

To determine the number of arguments in VA_ARGS.

Definition at line 41 of file fg_definitions.h.

#define unlikely (   x)    __builtin_expect(!!(x), 0) /** @} */

These macros gain us a few percent of speed.

Definition at line 35 of file fg_definitions.h.

#define UNUSED_ARGUMENT (   x)    (void)x

Suppress warning for unused argument.

Definition at line 38 of file fg_definitions.h.