int cavan_alarm_thread_init(struct cavan_alarm_thread *alarm_thread) { int ret; struct cavan_thread *thread; ret = pthread_mutex_init(&alarm_thread->lock, NULL); if (ret < 0) { pr_error_info("pthread_mutex_init"); return ret; } ret = double_link_init(&alarm_thread->link, MOFS(struct cavan_alarm_node, node)); if (ret < 0) { pr_red_info("double_link_init"); goto out_pthread_mutex_destroy; } thread = &alarm_thread->thread; thread->name = "ALARM"; thread->wake_handker = NULL; thread->handler = cavan_alarm_thread_handler; ret = cavan_thread_init(thread, alarm_thread); if (ret < 0) { pr_red_info("cavan_thread_init"); goto out_double_link_deinit; } signal(SIGALRM, cavan_alarm_sighandler); return 0; out_double_link_deinit: double_link_deinit(&alarm_thread->link); out_pthread_mutex_destroy: pthread_mutex_destroy(&alarm_thread->lock); return ret; }
int cavan_data_pool_init(struct cavan_data_pool *pool, int offset, size_t node_size, int count) { int ret; size_t size; byte *buff, *buff_end; struct double_link *link = &pool->link; ret = cavan_data_pool_link_init(link, offset); if (ret < 0) { pr_red_info("cavan_data_link_init"); return ret; } size = node_size * count; buff = malloc(size); if (buff == NULL) { pr_error_info("malloc"); goto out_double_link_deinit; } pool->buff = buff; pool->offset = offset; pool->node_size = node_size; for (buff_end = buff + size; buff < buff_end; buff += node_size) { struct cavan_data_pool_node *data = cavan_data_pool_to_node(pool, buff); data->private_data = pool; data->destroy = cavan_data_pool_node_destroy; double_link_node_init(&data->node); double_link_append(link, &data->node); } return 0; out_double_link_deinit: double_link_deinit(link); return ret; }
void cavan_alarm_thread_deinit(struct cavan_alarm_thread *thread) { cavan_thread_deinit(&thread->thread); double_link_deinit(&thread->link); pthread_mutex_destroy(&thread->lock); }
void cavan_data_pool_deinit(struct cavan_data_pool *pool) { free(pool->buff); double_link_deinit(&pool->link); }