numam-dpdk/lib/eal/include/rte_class.h
William Tu f1f6ebc0ea eal: remove sys/queue.h from public headers
Currently there are some public headers that include 'sys/queue.h', which
is not POSIX, but usually provided by the Linux/BSD system library.
(Not in POSIX.1, POSIX.1-2001, or POSIX.1-2008. Present on the BSDs.)
The file is missing on Windows. During the Windows build, DPDK uses a
bundled copy, so building a DPDK library works fine.  But when OVS or other
applications use DPDK as a library, because some DPDK public headers
include 'sys/queue.h', on Windows, it triggers an error due to no such
file.

One solution is to install the 'lib/eal/windows/include/sys/queue.h' into
Windows environment, such as [1]. However, this means DPDK exports the
functionalities of 'sys/queue.h' into the environment, which might cause
symbols, macros, headers clashing with other applications.

The patch fixes it by removing the "#include <sys/queue.h>" from
DPDK public headers, so programs including DPDK headers don't depend
on the system to provide 'sys/queue.h'. When these public headers use
macros such as TAILQ_xxx, we replace it by the ones with RTE_ prefix.
For Windows, we copy the definitions from <sys/queue.h> to rte_os.h
in Windows EAL. Note that these RTE_ macros are compatible with
<sys/queue.h>, both at the level of API (to use with <sys/queue.h>
macros in C files) and ABI (to avoid breaking it).

Additionally, the TAILQ_FOREACH_SAFE is not part of <sys/queue.h>,
the patch replaces it with RTE_TAILQ_FOREACH_SAFE.

[1] http://mails.dpdk.org/archives/dev/2021-August/216304.html

Suggested-by: Nick Connolly <nick.connolly@mayadata.io>
Suggested-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Narcisa Vasile <navasile@linux.microsoft.com>
2021-10-01 13:09:43 +02:00

133 lines
2.9 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018 Gaëtan Rivet
*/
#ifndef _RTE_CLASS_H_
#define _RTE_CLASS_H_
/**
* @file
*
* DPDK device class interface.
*
* This file describes the interface of the device class
* abstraction layer.
*
* A device class defines the type of function a device
* will be used for e.g.: Ethernet adapter (eth),
* cryptographic co-processor (crypto), etc.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <rte_dev.h>
/** Double linked list of classes */
RTE_TAILQ_HEAD(rte_class_list, rte_class);
/**
* A structure describing a generic device class.
*/
struct rte_class {
RTE_TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */
const char *name; /**< Name of the class */
rte_dev_iterate_t dev_iterate; /**< Device iterator. */
};
/**
* Class comparison function.
*
* @param cls
* Class under test.
*
* @param data
* Data to compare against.
*
* @return
* 0 if the class matches the data.
* !0 if the class does not match.
* <0 if ordering is possible and the class is lower than the data.
* >0 if ordering is possible and the class is greater than the data.
*/
typedef int (*rte_class_cmp_t)(const struct rte_class *cls, const void *data);
/**
* Class iterator to find a particular class.
*
* This function compares each registered class to find one that matches
* the data passed as parameter.
*
* If the comparison function returns zero this function will stop iterating
* over any more classes. To continue a search the class of a previous search
* can be passed via the start parameter.
*
* @param start
* Starting point for the iteration.
*
* @param cmp
* Comparison function.
*
* @param data
* Data to pass to comparison function.
*
* @return
* A pointer to a rte_class structure or NULL in case no class matches
*/
__rte_experimental
struct rte_class *
rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp,
const void *data);
/**
* Find the registered class for a given name.
*/
__rte_experimental
struct rte_class *
rte_class_find_by_name(const char *name);
/**
* Register a Class handle.
*
* @param cls
* A pointer to a rte_class structure describing the class
* to be registered.
*/
__rte_experimental
void rte_class_register(struct rte_class *cls);
/**
* Unregister a Class handle.
*
* @param cls
* A pointer to a rte_class structure describing the class
* to be unregistered.
*/
__rte_experimental
void rte_class_unregister(struct rte_class *cls);
/**
* Helper for Class registration.
* The constructor has lower priority than Bus constructors.
* The constructor has higher priority than PMD constructors.
*/
#define RTE_REGISTER_CLASS(nm, cls) \
RTE_INIT_PRIO(classinitfn_ ##nm, CLASS) \
{\
(cls).name = RTE_STR(nm); \
rte_class_register(&cls); \
}
#define RTE_UNREGISTER_CLASS(nm, cls) \
RTE_FINI_PRIO(classfinifn_ ##nm, CLASS) \
{ \
rte_class_unregister(&cls); \
}
#ifdef __cplusplus
}
#endif
#endif /* _RTE_CLASS_H_ */