Пример #1
0
static int lha_lh_new_init(void *data, LHADecoderCallback callback,
                           void *callback_data)
{
	LHANewDecoder *decoder = data;

	// Initialize input stream reader.

	bit_stream_reader_init(&decoder->bit_stream_reader,
	                       callback, callback_data);

	// Initialize data structures.

	init_ring_buffer(decoder);

	// First read starts the first block.

	decoder->block_remaining = 0;

	// Initialize tree tables to a known state.

	init_tree(decoder->code_tree, NUM_CODES * 2);
	init_tree(decoder->offset_tree, MAX_TEMP_CODES * 2);

	return 1;
}
Пример #2
0
	Ribbon(unsigned int length, int mux_address)
	{
		this->enabled = true;
		this->mux_address = mux_address;
		this->length = length;
		this->buffer = (struct RingBuffer *)malloc(sizeof(struct RingBuffer));
		init_ring_buffer(this->buffer, this->length * 3 * 300);
	}
Пример #3
0
static int lha_lh1_init(void *data, LHADecoderCallback callback,
                        void *callback_data)
{
    LHALH1Decoder *decoder = data;

    // Initialize input stream reader.

    bit_stream_reader_init(&decoder->bit_stream_reader,
                           callback, callback_data);

    // Initialize data structures.

    init_groups(decoder);
    init_tree(decoder);
    init_offset_table(decoder);
    init_ring_buffer(decoder);

    return 1;
}
Пример #4
0
int init_server (server_t *server) {
	assert (server != NULL);

	server->shutdown = false;

    zlog_category_t *category = zlog_get_category("server");
	zlog_info (category, "Initializing server.");

	// init thread cluster
	thread_pool_cluster_config_t config_cluster = {
		.pool_size = 10,
		.extend_threshold = 5,
		.cycle_of_seconds = 1
	};
	init_thread_pool_cluster (&server->cluster, &config_cluster);

	// init file loader 
	// filenames are defined in movies.h
	init_file_loader (&server->loader, 100, "../images/", filenames);

	// init ring buffer
	buffer_config_t config_buffer = {
		.buffer_size = 50,
		.consume_threshold = 1,
		.produce_threshold = 0
	};
	init_ring_buffer (&server->buffer, &config_buffer);

	// malloc here, free at destroy_server
	server->socket = (socket_manager_t *)malloc (sizeof (socket_manager_t));
	assert (server->socket != NULL);

	// init socket
	init_socket_server (server->socket, SERVER_PORT);

	// hook
	server->socket->handle = _server_handle;
	server->socket->server = server;
	server->run = _server_run;

	// submit consumer
	server->cluster.submit (&server->cluster, _server_consumer, (void *)server);

	return 0;
}

int destroy_server (server_t *server) {
	assert (server != NULL);

	server->shutdown = true;

    zlog_category_t *category = zlog_get_category("server");
	zlog_info (category, "Destroying server.");

	// destroy loop thread
	zlog_debug (category, "Destroying server loop.");
	int status = pthread_cancel (server->loop);
	status = pthread_join (server->loop, NULL);
	assert (status == 0);

	zlog_debug (category, "Destroying file loader.");
	destroy_file_loader (&server->loader);


	zlog_debug (category, "Destroying server socket manager.");
	destroy_socket_manager (server->socket);
	free (server->socket);

	zlog_debug (category, "Destroying thread cluster.");
	destroy_thread_pool_cluster (&server->cluster);


	zlog_debug (category, "Destroying ring buffer.");
	destroy_ring_buffer (&server->buffer);

	return 0;
}
size_t create_ring_buffer(struct ring_buff *rb, size_t size)
{
        char *buff = (char *) portMalloc(size);
        return NULL == buff ? 0 : init_ring_buffer(rb, buff, size);
}