コード例 #1
0
bool
as_event_send_close_loop(as_event_loop* event_loop)
{
	// Send stop command through queue so it can be executed in event loop thread.
	pthread_mutex_lock(&event_loop->lock);
	as_uv_command qcmd = {.type = AS_UV_EXIT_LOOP, .ptr = 0};
	bool queued = as_queue_push(&event_loop->queue, &qcmd);
	pthread_mutex_unlock(&event_loop->lock);
	
	if (queued) {
		uv_async_send(event_loop->wakeup);
	}
	return queued;
}

void
as_event_close_loop(as_event_loop* event_loop)
{
	uv_close((uv_handle_t*)event_loop->wakeup, as_uv_wakeup_closed);
	
	// Only stop event loop if client created event loop.
	if (as_event_threads_created) {
		uv_stop(event_loop->loop);
	}
	
	// Cleanup event loop resources.
	as_queue_destroy(&event_loop->queue);
	as_queue_destroy(&event_loop->pipe_cb_queue);
	pthread_mutex_unlock(&event_loop->lock);
	pthread_mutex_destroy(&event_loop->lock);
}
コード例 #2
0
static void
as_ev_close_loop(as_event_loop* event_loop)
{
	ev_async_stop(event_loop->loop, &event_loop->wakeup);
	
	// Only stop event loop if client created event loop.
	if (as_event_threads_created) {
		ev_unloop(event_loop->loop, EVUNLOOP_ALL);
	}
	
	// Cleanup event loop resources.
	as_queue_destroy(&event_loop->queue);
	as_queue_destroy(&event_loop->pipe_cb_queue);
}
コード例 #3
0
static void
as_ev_close_connections(as_node* node, as_queue* conn_queue)
{
	as_event_connection* conn;
	
	// Queue connection commands to event loops.
	while (as_queue_pop(conn_queue, &conn)) {
		close(conn->fd);
		cf_free(conn);
		as_event_decr_connection(node->cluster, conn_queue);
		ck_pr_dec_32(&node->cluster->async_conn_pool);
	}
	as_queue_destroy(conn_queue);
}
コード例 #4
0
void
as_event_node_destroy(as_node* node)
{
	// Send close connection commands to event loops.
	for (uint32_t i = 0; i < as_event_loop_size; i++) {
		as_event_loop* event_loop = &as_event_loops[i];
		
		pthread_mutex_lock(&event_loop->lock);
		as_uv_queue_close_connections(node, &node->async_conn_qs[i], &event_loop->queue);
		as_uv_queue_close_connections(node, &node->pipe_conn_qs[i], &event_loop->queue);
		pthread_mutex_unlock(&event_loop->lock);
		
		uv_async_send(event_loop->wakeup);
	}
		
	// Destroy all queues.
	for (uint32_t i = 0; i < as_event_loop_capacity; i++) {
		as_queue_destroy(&node->async_conn_qs[i]);
		as_queue_destroy(&node->pipe_conn_qs[i]);
	}
	cf_free(node->async_conn_qs);
	cf_free(node->pipe_conn_qs);
}