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_private.h" 13 : : 14 : : static struct rte_class_list rte_class_list = 15 : : TAILQ_HEAD_INITIALIZER(rte_class_list); 16 : : 17 : : void 18 : 502 : rte_class_register(struct rte_class *class) 19 : : { 20 [ - + ]: 502 : RTE_VERIFY(class); 21 [ + - - + ]: 502 : RTE_VERIFY(class->name && strlen(class->name)); 22 : : 23 : 502 : TAILQ_INSERT_TAIL(&rte_class_list, class, next); 24 : 502 : EAL_LOG(DEBUG, "Registered [%s] device class.", class->name); 25 : 502 : } 26 : : 27 : : void 28 : 0 : rte_class_unregister(struct rte_class *class) 29 : : { 30 [ # # ]: 0 : TAILQ_REMOVE(&rte_class_list, class, next); 31 : 0 : EAL_LOG(DEBUG, "Unregistered [%s] device class.", class->name); 32 : 0 : } 33 : : 34 : : struct rte_class * 35 : 8 : rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, 36 : : const void *data) 37 : : { 38 : : struct rte_class *cls; 39 : : 40 [ - + ]: 8 : if (start != NULL) 41 : 0 : cls = TAILQ_NEXT(start, next); 42 : : else 43 : 8 : cls = TAILQ_FIRST(&rte_class_list); 44 [ + + ]: 17 : while (cls != NULL) { 45 [ + + ]: 16 : if (cmp(cls, data) == 0) 46 : : break; 47 : 9 : cls = TAILQ_NEXT(cls, next); 48 : : } 49 : 8 : return cls; 50 : : } 51 : : 52 : : static int 53 : 16 : cmp_class_name(const struct rte_class *class, const void *_name) 54 : : { 55 : : const char *name = _name; 56 : : 57 : 16 : return strcmp(class->name, name); 58 : : } 59 : : 60 : : struct rte_class * 61 : 8 : rte_class_find_by_name(const char *name) 62 : : { 63 : 8 : return rte_class_find(NULL, cmp_class_name, (const void *)name); 64 : : }