|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifndef MPL_BASE_H_INCLUDED
|
|
Packit Service |
c5cf8c |
#define MPL_BASE_H_INCLUDED
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* this file splits off the base functionality in MPL, which does not
|
|
Packit Service |
c5cf8c |
* depend on any of the exposed features. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mplconfig.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
#include <stdarg.h>
|
|
Packit Service |
c5cf8c |
#include <stdint.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined _mpl_restrict
|
|
Packit Service |
c5cf8c |
#define mpl_restrict _mpl_restrict
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define mpl_restrict restrict
|
|
Packit Service |
c5cf8c |
#endif /* _mpl_restrict */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined _mpl_const
|
|
Packit Service |
c5cf8c |
#define mpl_const _mpl_const
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define mpl_const const
|
|
Packit Service |
c5cf8c |
#endif /* _mpl_const */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined _mpl_inline
|
|
Packit Service |
c5cf8c |
#define mpl_inline _mpl_inline
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define mpl_inline inline
|
|
Packit Service |
c5cf8c |
#endif /* _mpl_inline */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined MPL_HAVE_CTYPE_H
|
|
Packit Service |
c5cf8c |
#include <ctype.h>
|
|
Packit Service |
c5cf8c |
#endif /* MPL_HAVE_CTYPE_H */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined(MPL_HAVE_INTTYPES_H)
|
|
Packit Service |
c5cf8c |
#include <inttypes.h>
|
|
Packit Service |
c5cf8c |
#endif /* MPL_HAVE_INTTYPES_H */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined MPL_HAVE_IFADDRS_H
|
|
Packit Service |
c5cf8c |
#include <ifaddrs.h>
|
|
Packit Service |
c5cf8c |
#endif /* MPL_HAVE_IFADDRS_H */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if defined MPL_HAVE_ARPA_INET_H
|
|
Packit Service |
c5cf8c |
#include <arpa/inet.h>
|
|
Packit Service |
c5cf8c |
#endif /* MPL_HAVE_ARPA_INET_H */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if !defined ATTRIBUTE
|
|
Packit Service |
c5cf8c |
#if defined MPL_HAVE_GCC_ATTRIBUTE
|
|
Packit Service |
c5cf8c |
#define ATTRIBUTE(a_) __attribute__(a_)
|
|
Packit Service |
c5cf8c |
#else /* MPL_HAVE_GCC_ATTRIBUTE */
|
|
Packit Service |
c5cf8c |
#define ATTRIBUTE(a_)
|
|
Packit Service |
c5cf8c |
#endif /* MPL_HAVE_GCC_ATTRIBUTE */
|
|
Packit Service |
c5cf8c |
#endif /* ATTRIBUTE */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPL_UNUSED ATTRIBUTE((unused))
|
|
Packit Service |
c5cf8c |
#define MPL_STATIC_INLINE_PREFIX ATTRIBUTE((always_inline)) static inline
|
|
Packit Service |
c5cf8c |
#define MPL_STATIC_INLINE_SUFFIX ATTRIBUTE((always_inline))
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_FUNC_ATTRIBUTE_FALLTHROUGH
|
|
Packit Service |
c5cf8c |
#define MPL_FALLTHROUGH ATTRIBUTE((fallthrough))
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define MPL_FALLTHROUGH
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_VAR_ATTRIBUTE_ALIGNED
|
|
Packit Service |
c5cf8c |
#define MPL_ATTR_ALIGNED(x) ATTRIBUTE((aligned(x)))
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define MPL_ATTR_ALIGNED(x)
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_VAR_ATTRIBUTE_USED
|
|
Packit Service |
c5cf8c |
#define MPL_USED ATTRIBUTE((used))
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define MPL_USED
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* These likely/unlikely macros provide static branch prediction hints to the
|
|
Packit Service |
c5cf8c |
* compiler, if such hints are available. Simply wrap the relevant expression in
|
|
Packit Service |
c5cf8c |
* the macro, like this:
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* if (unlikely(ptr == NULL)) {
|
|
Packit Service |
c5cf8c |
* // ... some unlikely code path ...
|
|
Packit Service |
c5cf8c |
* }
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* They should be used sparingly, especially in upper-level code. It's easy to
|
|
Packit Service |
c5cf8c |
* incorrectly estimate branching likelihood, while the compiler can often do a
|
|
Packit Service |
c5cf8c |
* decent job if left to its own devices.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* These macros are not namespaced because the namespacing is cumbersome.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_BUILTIN_EXPECT
|
|
Packit Service |
c5cf8c |
#define unlikely(x_) __builtin_expect(!!(x_),0)
|
|
Packit Service |
c5cf8c |
#define likely(x_) __builtin_expect(!!(x_),1)
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define unlikely(x_) (x_)
|
|
Packit Service |
c5cf8c |
#define likely(x_) (x_)
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPL_QUOTE(A) MPL_QUOTE2(A)
|
|
Packit Service |
c5cf8c |
#define MPL_QUOTE2(A) #A
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPL_MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
Packit Service |
c5cf8c |
#define MPL_MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Use this macro for each parameter to a function that is not referenced in
|
|
Packit Service |
c5cf8c |
the body of the function */
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_WINDOWS_H
|
|
Packit Service |
c5cf8c |
#define MPL_UNREFERENCED_ARG(a) a
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define MPL_UNREFERENCED_ARG(a)
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* macro for finding the enclosing structure of an element */
|
|
Packit Service |
c5cf8c |
#define MPL_container_of(ptr, type, member) (type *)((char *)(ptr) - offsetof(type,member))
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* This macro is used to silence warnings from the Mac OS X linker when
|
|
Packit Service |
c5cf8c |
* an object file "has no symbols". The unused attribute prevents a
|
|
Packit Service |
c5cf8c |
* warning about the unused dummy variable while the used attribute
|
|
Packit Service |
c5cf8c |
* prevents the compiler from discarding the symbol altogether. This
|
|
Packit Service |
c5cf8c |
* macro should be used at the top of any file that might not define any
|
|
Packit Service |
c5cf8c |
* other variables or functions (perhaps due to conditional compilation
|
|
Packit Service |
c5cf8c |
* via the preprocessor). A semicolon is expected after each invocation
|
|
Packit Service |
c5cf8c |
* of this macro. */
|
|
Packit Service |
c5cf8c |
#define MPL_SUPPRESS_OSX_HAS_NO_SYMBOLS_WARNING \
|
|
Packit Service |
c5cf8c |
static int MPL_UNIQUE_SYMBOL_NAME(dummy) ATTRIBUTE((unused)) MPL_USED = 0
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* we jump through a couple of extra macro hoops to append the line
|
|
Packit Service |
c5cf8c |
* number to the variable name in order to reduce the chance of a name
|
|
Packit Service |
c5cf8c |
* collision with headers that might be included in the translation
|
|
Packit Service |
c5cf8c |
* unit */
|
|
Packit Service |
c5cf8c |
#define MPL_UNIQUE_SYMBOL_NAME(prefix_) MPL_UNIQUE_IMPL1_(prefix_##_unique_L,__LINE__)
|
|
Packit Service |
c5cf8c |
#define MPL_UNIQUE_IMPL1_(prefix_,line_) MPL_UNIQUE_IMPL2_(prefix_,line_)
|
|
Packit Service |
c5cf8c |
#define MPL_UNIQUE_IMPL2_(prefix_,line_) MPL_UNIQUE_IMPL3_(prefix_,line_)
|
|
Packit Service |
c5cf8c |
#define MPL_UNIQUE_IMPL3_(prefix_,line_) prefix_##line_
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPL_HAVE_STDBOOL_H
|
|
Packit Service |
c5cf8c |
#include <stdbool.h>
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#ifndef MPL_HAVE__BOOL
|
|
Packit Service |
c5cf8c |
#ifdef __cplusplus
|
|
Packit Service |
c5cf8c |
typedef bool _Bool;
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#define _Bool signed char
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#define bool _Bool
|
|
Packit Service |
c5cf8c |
#define false 0
|
|
Packit Service |
c5cf8c |
#define true 1
|
|
Packit Service |
c5cf8c |
#define __bool_true_false_are_defined 1
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* MPL_BASE_H_INCLUDED */
|