macros (C Macros)

Header: udo/macros.h

Table of contents (click to go)

Macros

  1. UDO_API

  2. UDO_UNUSED

  3. UDO_INLINE

  4. UDO_STATIC_INLINE

  5. UDO_DIR_NAME_MAX

  6. UDO_FILE_NAME_MAX

  7. UDO_FILE_PATH_MAX

  8. UDO_MAX

  9. UDO_MIN

  10. UDO_BYTE_ALIGN

  11. UDO_PAGE_SIZE

  12. UDO_PAGE_GET

  13. UDO_STRTOU

  14. UDO_ATOMIC_DEF

Enums

Unions

Structs

Functions

API Documentation

UDO_API

UDO_API
Used to prevent C++ name mangling when
using library in a C++ software package.
/* Prevent c++ name mangling */
#ifdef __cplusplus
#define UDO_API extern "C"
#else
#define UDO_API
#endif

UDO_UNUSED

UDO_UNUSED
Informs the compiler that you expect a variable
to be unused and instructs compiler to not issue
a warning on the variable.
#define UDO_UNUSED __attribute__((unused))

UDO_INLINE

UDO_INLINE
β€œalways_inline” instructs GCC to
  1. Ignore flag -fno-inline
  2. Don’t produce external definition of a
    function with external linkage.
  3. Ignore inlining limits. Use alloca(3) to inline.
    #define UDO_INLINE inline __attribute__((always_inline))
    

UDO_STATIC_INLINE

UDO_STATIC_INLINE
β€œalways_inline” instructs GCC to
  1. Ignore flag -fno-inline
  2. Don’t produce external definition of a
    function with external linkage.
  3. Ignore inlining limits. Use alloca(3) to inline.
Any function declared with static keyword will
be visible only to the source file it’s declared in.
#define UDO_STATIC_INLINE static inline __attribute__((always_inline))

UDO_DIR_NAME_MAX

UDO_DIR_NAME_MAX
Amount of character ext file system
support for directory paths.
#define UDO_DIR_NAME_MAX (1<<12)

UDO_FILE_NAME_MAX

UDO_FILE_NAME_MAX
Amount of character ext file system
support for a given file name.
#define UDO_FILE_NAME_MAX (1<<8)

UDO_FILE_PATH_MAX

UDO_FILE_PATH_MAX
Amount of character ext filesystem
supports when specifying a path and
file.
#define UDO_FILE_PATH_MAX (UDO_DIR_NAME_MAX + UDO_FILE_NAME_MAX)

UDO_MAX

UDO_MAX
Returns the maximum value between a and b.

Param

Decription

a

Must pass an integer value.

b

Must pass an integer value.
#define UDO_MAX(a,b) \
        ({ typeof (a) _a = (a); \
           typeof (b) _b = (b); \
           _a > _b ? _a : _b; })

UDO_MIN

UDO_MIN
Returns the minimum value between a and b.

Param

Decription

a

Must pass an integer value.

b

Must pass an integer value.
#define UDO_MIN(a,b) \
        ({ typeof (a) _a = (a); \
           typeof (b) _b = (b); \
           _a < _b ? _a : _b; })
Returns:
Minimum value between 2 numbers

UDO_BYTE_ALIGN

UDO_BYTE_ALIGN
Returns the upper bound byte alignment value.
Alignment value must be a power of 2 number.

Param

Decription

bytes

Integer value to align.

power_two_align

Power of 2 number to align bytes to.
#define UDO_BYTE_ALIGN(bytes, power_two_align) \
        ((bytes+(power_two_align-1))&~(power_two_align-1))
Returns
Upper bound memory alignment

UDO_PAGE_SIZE

UDO_PAGE_SIZE
Defines typical page size.
#define UDO_PAGE_SIZE (1<<12)

UDO_PAGE_GET

UDO_PAGE_GET
Retrieves the starting address of
the page ptr resides in.

Param

Decription

ptr

Address caller wants to find page of.
#define UDO_PAGE_GET(ptr) \
        ((void*)((uintptr_t)ptr & ~(UDO_PAGE_SIZE-1)))
Returns:
Starting address of the page

UDO_STRTOU

UDO_STRTOU
Converts string to an unsigned integer.
Simple one way hash function.

Param

Decription

str

Pointer to string to hash.
#define UDO_STRTOU(str) \
        __extension__ \
        ({ \
                __label__ __out; \
                uint32_t hash=0; \
                if (!str) goto __out; \
                const char *s = str; \
                while (*s) hash += *s++; \
                __out: hash; \
        })
Returns:
unsigned integer representing string

UDO_ATOMIC_DEF

UDO_ATOMIC_DEF
Create atomic variable type of a
caller defined data type.

Param

Decription

name

Name of atomic type.

type

Data type of the atomic type.
#define UDO_ATOMIC_DEF(name, type) \
        typedef _Atomic __typeof__(type) name;

/* Atomic Types */
UDO_ATOMIC_DEF(udo_atomic_int, int)
UDO_ATOMIC_DEF(udo_atomic_bool, unsigned char)
UDO_ATOMIC_DEF(udo_atomic_u32, unsigned int)
UDO_ATOMIC_DEF(udo_atomic_addr, unsigned char *)
Returns:
The atomic type