static inline struct tc_device *tc_device_create(char *id) { struct tc_device *d = tc_device_index_find(id, 0); if(!d) { debug(D_TC_LOOP, "TC: Creating device '%s'", id); d = calloc(1, sizeof(struct tc_device)); if(!d) { fatal("Cannot allocate memory for tc_device %s", id); return NULL; } d->id = strdup(id); d->hash = simple_hash(d->id); avl_init(&d->classes_index, tc_class_compare); tc_device_index_add(d); if(!tc_device_root) { tc_device_root = d; } else { d->next = tc_device_root; tc_device_root->prev = d; tc_device_root = d; } } return(d); }
static inline struct tc_device *tc_device_create(char *id) { struct tc_device *d = tc_device_index_find(id, 0); if(!d) { debug(D_TC_LOOP, "TC: Creating device '%s'", id); d = callocz(1, sizeof(struct tc_device)); d->id = strdupz(id); d->hash = simple_hash(d->id); d->enabled = (char)-1; avl_init(&d->classes_index, tc_class_compare); if(unlikely(tc_device_index_add(d) != d)) error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", d->id); if(!tc_device_root) { tc_device_root = d; } else { d->next = tc_device_root; tc_device_root->prev = d; tc_device_root = d; } } return(d); }
static struct tc_device *tc_device_create(char *id) { struct tc_device *d = tc_device_index_find(id, 0); if(!d) { debug(D_TC_LOOP, "TC: Creating device '%s'", id); d = calloc(1, sizeof(struct tc_device)); if(!d) { fatal("Cannot allocate memory for tc_device %s", id); return NULL; } d->id = strdup(id); d->hash = simple_hash(d->id); d->classes_index.root = NULL; d->classes_index.compar = tc_class_compare; #ifdef AVL_LOCK_WITH_MUTEX pthread_mutex_init(&d->classes_index.mutex, NULL); #else pthread_rwlock_init(&d->classes_index.rwlock, NULL); #endif tc_device_index_add(d); if(!tc_device_root) { tc_device_root = d; } else { d->next = tc_device_root; tc_device_root->prev = d; tc_device_root = d; } } return(d); }