Beispiel #1
0
int cavan_mux_init(struct cavan_mux *mux, void *data)
{
	int i;
	int ret;
	struct cavan_thread *thread;

	if (mux->send == NULL || mux->recv == NULL) {
		pr_red_info("mux->send = %p, mux->recv = %p", mux->send, mux->recv);
		return -EINVAL;
	}

	cavan_lock_init(&mux->lock, false);

	ret = cavan_mem_queue_init(&mux->recv_queue, CAVAN_MUX_MTU);
	if (ret < 0) {
		pr_red_info("cavan_mem_queue_init: %d", ret);
		goto out_cavan_lock_deinit;
	}

	mux->private_data = data;
	mux->packages = NULL;

	mux->package_head = NULL;
	mux->package_tail = &mux->package_head;

	for (i = 0; i < NELEM(mux->links); i++) {
		mux->links[i] = NULL;
	}

	thread = &mux->recv_thread;
	thread->name = "MUX RECEIVE";
	thread->handler = cavan_mux_recv_thread_handler;
	thread->wake_handker = NULL;
	ret = cavan_thread_run(thread, mux, 0);
	if (ret < 0) {
		pr_red_info("cavan_thread_run");
		goto out_cavan_mem_queue_deinit;
	}

	thread = &mux->send_thread;
	thread->name = "MUX SEND";
	thread->handler = cavan_mux_send_thread_handler;
	thread->wake_handker = NULL;
	ret = cavan_thread_run(thread, mux, 0);
	if (ret < 0) {
		pr_red_info("cavan_thread_run");
		goto out_cavan_thread_stop_recv;
	}

	return 0;

out_cavan_thread_stop_recv:
	cavan_thread_stop(&mux->recv_thread);
out_cavan_mem_queue_deinit:
	cavan_mem_queue_deinit(&mux->recv_queue);
out_cavan_lock_deinit:
	cavan_lock_deinit(&mux->lock);
	return ret;
}
Beispiel #2
0
void cavan_mux_link_init(struct cavan_mux_link *link, struct cavan_mux *mux)
{
	cavan_lock_init(&link->lock, false);

	link->mux = mux;
	link->hole_size = 0;
	link->package_head = NULL;
	link->package_tail = &link->package_head;
}