Пример #1
0
void Game::initialize(){
	init();
	game::network::Socket::socket_init();
	config.load(folder_path+"config.txt");
	window=create_window();

	//window->render_on();
	draw = new Display::Draw();
	draw->register_cur();
	UIObj_Creator=new UI::UIObjectCreator();
	UIObj_Creator->register_cur();

	renderer = new Display::Renderer(draw, window);
	//render_task = new RenderTask(renderer);


	input = new Input::Input(window->get_window());
	input->register_cur();
	game_receiver=new Input::Receiver("Game");
	input->push_receiver(game_receiver);

	controller_system=new ControllerSystem();
	controller_system->push(new Input::SelectableControl());
	controller_system->push(new Audio::AudioController());


	thread_pool = create_thread_pool();

	s_loading = new LoadingScene();
	s_loading->initialize(draw,input,thread_pool);

	initialize_game();
}
Пример #2
0
bool CContext::create()
{
    try
    {
        // 忽略PIPE信号
        if (!IgnorePipeSignal())
        {
            return false;
        }
        if (!create_listen_manager())
        {
            return false;
        }
        if (!create_thread_pool(&_listen_manager))
        {
            return false;
        }
    }
    catch (sys::CSyscallException& ex)
    {
        SERVER_LOG_FATAL("Created context failed for %s at %s:%d.\n"
                         , strerror(ex.get_errcode())
                         , ex.get_filename()
                         , ex.get_linenumber());
        return false;
    }

    return true;
}
Пример #3
0
void
helo_init(pool_limits_t *limits)
{
    thread_pool_t *pool;

    /* initialize the thread pool */
    logstr(GLOG_INFO, "initializing helo thread pool");
    pool = create_thread_pool("helo", &helo, limits, NULL);
    if (pool == NULL)
        daemon_fatal("create_thread_pool");

    register_check(pool, false);
}
Пример #4
0
void
reverse_init(pool_limits_t *limits)
{
	thread_pool_t *pool;

	/* initialize the thread pool */
	logstr(GLOG_INFO, "initializing reverse thread pool");
	pool = create_thread_pool("reverse", &reverse, limits, NULL);
	if (pool == NULL)
		daemon_fatal("create_thread_pool");

	register_check(pool, false);
}
Пример #5
0
void
spf_init(pool_limits_t *limits)
{
	thread_pool_t *pool;

	/* initialize the thread pool */
	logstr(GLOG_INFO, "initializing spf checker thread pool");
	pool = create_thread_pool("spf", &spfc, limits, NULL);
	if (pool == NULL)
		daemon_fatal("create_thread_pool");

	/* This is a definitive check */
	register_check(pool, true);
}
Пример #6
0
void test_mm(void) {
  int max_threads = 8;
  thread_pool_t *thread_pool = create_thread_pool(max_threads);

  int m = 8192;
  int n = 1024;
  int k = 1024;
  double *a = make_array(m, k);
  double *b = make_array(k, n);
  double *o = make_array(m, n);
  int tile_sizes[5] = {1024, 64, 64, 8, 8};

  int num_threads = 8;
  job_t *job = make_job(0, m, 1024, num_threads, 1);

  vm_args_t vm_args;
  vm_args.a = a;
  vm_args.b = b;
  vm_args.out = o;
  vm_args.m = m;
  vm_args.n = n;
  vm_args.k = k;

  struct timeval start, end, result;
  gettimeofday(&start, NULL);
  launch_job(thread_pool, &vm2, &vm_args, job, tile_sizes, 1);
  wait_for_job(thread_pool);
  gettimeofday(&end, NULL);

  double t;
  timersub(&end, &start, &result);
  t = result.tv_sec + result.tv_usec / 1000000.0;
  printf("Parallel runtime: %f\n", t);

  int pass = 1;
//  int i, j, l;
//  double sum;
//  gettimeofday(&start, NULL);
//  for (i = 0; i < m; ++i) {
//    for (j = 0; j < n; ++j) {
//      sum = 0.0;
//      for (l = 0; l < k; ++l) {
//        sum += a[i*k + l] * b[j*k + l];
//      }
//      pass = pass && (abs(sum - o[i*n + j]) < 1e-4);
//    }
//  }
//  gettimeofday(&end, NULL);
  CU_ASSERT(pass);

//  double naive_time;
//  timersub(&end, &start, &result);
//  naive_time = result.tv_sec + result.tv_usec / 1000000.0;
//  printf("Naive time: %f\n", naive_time);

  destroy_thread_pool(thread_pool);
  free_job(job);
  free_array(a);
  free_array(b);
  free_array(o);
}
Пример #7
0
int main(int argc, char* argv[])
{
	if (argc <= 2)
	{
		printf("Usage: %s ip_address port_number\n", argv[0]);
		return 0;
	}

	log_globals_init(&g_log);
	log_init(&g_log, "jhttpserver.log", NULL);
	log_set_loglevel(&g_log, LOG_DEBUG);

	const char* ip = argv[1];
	int port = atoi(argv[2]);

	INFO(&g_log, "jhttpserver", "%s : %d", ip, port);

	add_signal(SIGPIPE, SIG_IGN, TRUE);

	thread_pool* pool = create_thread_pool(8 ,10000);
	if (pool == NULL)
	{
		printf("create thread pool is failed.");
		ERROR(&g_log, "jhttpserver", "create thread pool is failed.");
		return 1;
	}

	http_conn* users = (http_conn*)malloc(sizeof(http_conn) * MAX_FD);
	assert(users);

	int listen_fd = socket(PF_INET, SOCK_STREAM, 0);
	struct linger tmp = {1, 0};
	setsockopt(listen_fd, SOL_SOCKET, SO_LINGER, &tmp, sizeof(tmp));

	int ret = 0;
	struct sockaddr_in address;
	bzero(&address, sizeof(address));
	address.sin_family = AF_INET;
	address.sin_port = htons(port);
	inet_pton(AF_INET, ip, &address.sin_addr);

	ret = bind(listen_fd, (struct sockaddr *)&address, sizeof(address));
	assert(ret >= 0);
	ret = listen(listen_fd, 5);
	assert(ret >= 0);

	struct epoll_event events[MAX_EVENT_NUMBER];
	epollfd = epoll_create(5);
	assert(epollfd != -1);
	add_fd(epollfd, listen_fd, false);

	while (true)
	{
		int number = epoll_wait(epollfd, events, MAX_EVENT_NUMBER, -1);
		if ((number < 0) && (errno != EINTR))
		{
			printf("epoll failure\n");
			break;
		}

		int i=0;
		for (; i<number; i++)
		{
			int sockfd = events[i].data.fd;
			if (sockfd == listen_fd)
			{
				struct sockaddr_in client_address;
				socklen_t client_addr_len = sizeof(client_address);
				int conn_fd = accept(listen_fd, (struct sockaddr*)&client_address,
						&client_addr_len);
				if (conn_fd < 0)
				{
					printf("errno is : %d\n", errno);
					continue;
				}
				if (user_count > MAX_FD)
				{
					show_error(conn_fd, "Internal server busy");
					continue;
				}
				init_new_connect(&users[conn_fd], conn_fd, &client_address);

			}
			else if (events[i].events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR))
			{
				close_connect(&users[sockfd]);
			}
			else if (events[i].events & EPOLLIN)
			{
				if (http_conn_read(&users[sockfd]))
				{
					add_conn(pool, users + sockfd);
				}
				else
				{
					close_connect(&users[sockfd]);
				}
			}
			else if (events[i].events & EPOLLOUT)
			{
				if (!http_conn_write(&users[sockfd]))
				{
					close_connect(&users[sockfd]);
				}
			}
		}
	}

	close(epollfd);
	close(listen_fd);
	free(users);
	destroy_thread_pool(pool);
	return 0;
}
Пример #8
0
bool CDispatcherContext::create()
{           
    return create_thread_pool();    
}