コード例 #1
0
ファイル: wiki_socket.cpp プロジェクト: duliangang/fastwiki
int WikiSocket::ws_one_thread(int idx)
{
	int sock;

	for (;;) {
		sock = q_accept(m_bind_sock);
		if (sock == -1) {
			if (errno == EINTR) {
				q_sleep(1);
				continue;
			}
			break;
		}
		m_http->hp_init(sock);
		m_do_url(m_do_url_class, (void *)this, m_http, sock, idx);

#ifdef WIN32
		closesocket(sock);
#else
		close(sock);
#endif
	}

	return 0;
}
コード例 #2
0
int start_create_index(const char *index_file, fw_files_t data_file, int total,
		const char *tmp_dir, size_t mem_size, const char *z_flag)
{
	sort_idx_t idx;
	data_head_t data_head;

	pthread_mutex_init(&m_fidx_mutex, NULL);

	m_wiki_index = new WikiIndex();
	m_wiki_index->wi_init(index_file);

	m_href_total = m_wiki_index->wi_href_total();

	m_wiki_data = new WikiData();
	m_wiki_data->wd_init(data_file, total);
	m_wiki_data->wd_get_head(&data_head);

	int page_total = 0;

	for (int i = 0; i < m_href_total; i++) {
		if (m_wiki_index->wi_fetch(i, &idx)) {
			page_total++;
		}
	}
#ifdef DEBUG
	LOG("page total: %d\n", page_total);
#endif

	m_full_index  = new WikiFullIndex();

	int max_thread = m_ffi_arg.pthread_total;
	
	if (max_thread == 0)
		max_thread = 1;
	
	if (max_thread > wiki_pthread_total())
		max_thread = wiki_pthread_total();

	m_full_index->wfi_create_init(z_flag, page_total + 1, data_head.lang, tmp_dir, mem_size, m_word_hash, max_thread);

	pthread_t id[128];

	for (int i = 0; i < max_thread; i++) {
		int n = pthread_create(&id[i], NULL, wiki_full_index_thread, &i);
		if (n != 0){
			return -1;
		}
		q_sleep(1);
	}

	for (int i = 0; i < max_thread; i++) {
		pthread_join(id[i], NULL);
	}

	m_full_index->wfi_add_page_done();

	return 0;
}
コード例 #3
0
static void my_wait()
{
	printf("Init done: http://127.0.0.1:%d\n", m_wiki_socket->ws_get_bind_port());

#ifdef DEBUG
	printf("-- This is debug version --\n");
#endif

	for (;;) {
		q_sleep(1);
	}
}
コード例 #4
0
ファイル: fastwiki-image.cpp プロジェクト: OZv/fastwiki
int fi_start_fetch_thread(int max_thread)
{
	pthread_t id[128];

	for (int i = 0; i < max_thread; i++) {
		int idx = i;
		int n = pthread_create(&id[i], NULL, fetch_image_thread, &idx);
		if (n == -1) {
			printf("error pthread\n");
			exit(0);
		}

		q_sleep(1);
	}

	for (int i = 0; i < max_thread; i++) {
		pthread_join(id[i], NULL);
	}

	return 0;
}