Esempio n. 1
0
void NetworkManager::Run()
{
	int threadId;
	struct epoll_event events[100];
	int numOfEvent, n;

	g_networkThreadCountLock.Lock();
	threadId = g_networkThreadCount++;
	g_networkThreadCountLock.Unlock();

	for(;;)
	{
		numOfEvent = epoll_wait(m_epollFdList[threadId], m_epollEvent2DList[threadId], 100, 2000);

		//printf("NW thread %d\n", threadId);
		if(numOfEvent < 0){	
			// critical error
			fprintf(stderr, "[ERROR] epoll_wait() ERROR : %s\n", strerror(errno));
			exit(1);
		}

		if(numOfEvent == 0)
		{
			continue;
		}

		//printf("NT %d activated\n", TC);
		OnEvent(numOfEvent, threadId);
	}
	close(m_serverFd);
	for(int i=0; i<NETWORK_THREAD_NUM; i++)
		close(m_epollFdList[i]);
}
Esempio n. 2
0
void SingletonReleaseTextVector()
{
	g_SpinLockTextVec.Lock();
	if (g_pTextVec)
	{
		delete g_pTextVec;
		g_pTextVec = 0;
	}
	g_SpinLockTextVec.Unlock();
}
Esempio n. 3
0
void SingletonReleaseHashTable()
{
	g_SpinLockHashTable.Lock();
	if (g_pObjHash)
	{
		delete g_pObjHash;
		g_pObjHash = 0;
	}
	g_SpinLockHashTable.Unlock();
}
Esempio n. 4
0
void duplicate_node::match(vector<duplicate_node*>& entrances,
                           search_duplicate_files_status* status,
                           SpinLock& lock)
{
    duplicate_node* iter = this;
    while (iter) {
        bool first_matched = true;
        duplicate_node* current_node = iter;
        duplicate_node* last_node = iter;
        euint current_symbol = iter->m_symbol;
        while (current_node) {
            {
                SpinLock::Instance inst = lock.Lock();
                if (status) {
                    status->m_current_status = search_duplicate_files_status::Matching;
                    status->m_processing_file = current_node->m_path.c_str();
                }
            }
            if (current_node->m_symbol == current_symbol && current_node != last_node) {
                last_node->m_next1 = current_node;
                if (first_matched) {
                    entrances.push_back(last_node);
                    first_matched = false;
                }
                last_node->m_is_matched = true;
                current_node->m_is_matched = true;
                last_node = current_node;
            }
            current_node = current_node->m_next0;
        }
        iter = iter->m_next0;
        while (iter && iter->m_is_matched) {
            iter = iter->m_next0;
        }
    }
    {
        SpinLock::Instance inst = lock.Lock();
        if (status) {
            status->m_current_status = search_duplicate_files_status::Idling;
            status->m_processing_file = nullptr;
        }
    }
}
Esempio n. 5
0
HashType * SingletonGetHashTable()
{
	if (!g_pObjHash)
	{
		g_SpinLockHashTable.Lock();
		if (!g_pObjHash)
			g_pObjHash = new HashType;
		g_SpinLockHashTable.Unlock();
	}
	return g_pObjHash;
}
Esempio n. 6
0
TextBufVecType * SingletonGetTextVector()
{
	if (!g_pTextVec)
	{
		g_SpinLockTextVec.Lock();
		if (!g_pTextVec)
			g_pTextVec = new TextBufVecType;
		g_SpinLockTextVec.Unlock();
	}
	return g_pTextVec;
}
Esempio n. 7
0
euint64 duplicate_node::prepare(duplicate_node_cache* cache,
                                search_duplicate_files_status* status,
                                SpinLock& lock)
{
    euint64 proced_size = 0;
    duplicate_node* iter = this;
    while (iter) {
        iter->m_next1 = nullptr;
        iter->m_symbol = 0;
        iter->m_is_matched = false;
        cache->open(iter);

        {
            SpinLock::Instance inst = lock.Lock();
            if (status) {
                status->m_current_status = search_duplicate_files_status::Reading;
                status->m_processing_file = iter->m_path.c_str();
            }
        }

        ///fseek(iter->m_file.get(), iter->m_offset, SEEK_SET);
        iter->m_file.Seek(iter->m_offset);
        ///fread(&iter->m_symbol, 1, sizeof(SYMBOL), iter->m_file.get());
        iter->m_file.Read(&iter->m_symbol, sizeof(SYMBOL));

        proced_size += sizeof(SYMBOL);
        m_remainder -= sizeof(SYMBOL);
        iter->m_offset += sizeof(SYMBOL);
        iter = iter->m_next0;
    }
    {
        {
            SpinLock::Instance inst = lock.Lock();
            if (status) {
                status->m_current_status = search_duplicate_files_status::Idling;
                status->m_processing_file = nullptr;
            }
        }
    }
    return proced_size;
}
Esempio n. 8
0
void xhn::thread::assign_to_local_thread(thread_ptr& local_thread, thread_ptr& global_thread, SpinLock& lock)
{
    {
        xhn::SpinLock::Instance inst = lock.Lock();
        local_thread = global_thread;
    }
    if (!local_thread) {

        local_thread = VNEW xhn::thread;
        while (!local_thread->is_running()) {}

        {
            xhn::SpinLock::Instance inst = lock.Lock();
            if (!global_thread) {
                global_thread = local_thread;
            }
            else {
                local_thread = global_thread;
            }
        }
    }
}