Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright 2018 Gaƫtan Rivet 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <string.h> 7 : : #include <sys/queue.h> 8 : : 9 : : #include <rte_class.h> 10 : : #include <rte_debug.h> 11 : : 12 : : #include <eal_export.h> 13 : : #include "eal_private.h" 14 : : 15 : : static struct rte_class_list rte_class_list = 16 : : TAILQ_HEAD_INITIALIZER(rte_class_list); 17 : : 18 : : RTE_EXPORT_SYMBOL(rte_class_register) 19 : : void 20 : 504 : rte_class_register(struct rte_class *class) 21 : : { 22 [ - + ]: 504 : RTE_VERIFY(class); 23 [ + - - + ]: 504 : RTE_VERIFY(class->name && strlen(class->name)); 24 : : 25 : 504 : TAILQ_INSERT_TAIL(&rte_class_list, class, next); 26 : 504 : EAL_LOG(DEBUG, "Registered [%s] device class.", class->name); 27 : 504 : } 28 : : 29 : : RTE_EXPORT_SYMBOL(rte_class_unregister) 30 : : void 31 : 0 : rte_class_unregister(struct rte_class *class) 32 : : { 33 [ # # ]: 0 : TAILQ_REMOVE(&rte_class_list, class, next); 34 : 0 : EAL_LOG(DEBUG, "Unregistered [%s] device class.", class->name); 35 : 0 : } 36 : : 37 : : RTE_EXPORT_SYMBOL(rte_class_find) 38 : : struct rte_class * 39 : 8 : rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, 40 : : const void *data) 41 : : { 42 : : struct rte_class *cls; 43 : : 44 [ - + ]: 8 : if (start != NULL) 45 : 0 : cls = TAILQ_NEXT(start, next); 46 : : else 47 : 8 : cls = TAILQ_FIRST(&rte_class_list); 48 [ + + ]: 17 : while (cls != NULL) { 49 [ + + ]: 16 : if (cmp(cls, data) == 0) 50 : : break; 51 : 9 : cls = TAILQ_NEXT(cls, next); 52 : : } 53 : 8 : return cls; 54 : : } 55 : : 56 : : static int 57 : 16 : cmp_class_name(const struct rte_class *class, const void *_name) 58 : : { 59 : : const char *name = _name; 60 : : 61 : 16 : return strcmp(class->name, name); 62 : : } 63 : : 64 : : RTE_EXPORT_SYMBOL(rte_class_find_by_name) 65 : : struct rte_class * 66 : 8 : rte_class_find_by_name(const char *name) 67 : : { 68 : 8 : return rte_class_find(NULL, cmp_class_name, (const void *)name); 69 : : }