示例#1
0
int JtEventServer::TestCmd()
{
	AsyncEvent Event(std::bind(&JtEventServer::TestCmdInner,this,std::placeholders::_1,std::placeholders::_2)
		, JTEVENTSERVER_TEST_CMD, GenSeq(), this);

	int res = DoInSync(Event);

	return 0;
}
示例#2
0
int JtEventServer::AddPeer(JtEventPeer* Peer)
{
	//lock.... to do.....
	//assert(Peer);

	AsyncEvent Event(std::bind(&JtEventServer::AddPeerInner,this,std::placeholders::_1,std::placeholders::_2)
		, JTEVENTSERVER_NOTIFY_ADD_PEER, GenSeq(), Peer);

	{
		JtMutexAutoLock L(m_PeerLock);
		m_PeerWait2AddS[Event.m_Seq]=(Peer);
	}
	
	jtprintf("[%s]m_Seq %d, AddPeer %p\n", __FUNCTION__, Event.m_Seq, Peer);
	
	int res = DoInSync(Event);

	return res;
}
示例#3
0
int JtEventServer::Stop()
{
	AsyncEvent Event(std::bind(&JtEventServer::AddPeerInner,this,std::placeholders::_1,std::placeholders::_2)
		, JTEVENTSERVER_NOTIFY_STOP_LOOP, GenSeq(), this);

	int res = DoInSync(Event);

#if (defined(WIN32) || defined(WIN64))

	if(tid!=(HANDLE)-1)
	{
		WaitForSingleObject(tid, INFINITE);
		//CloseHandle(tid);
		tid = (HANDLE)-1;
	}
#else
	if(tid!=(pthread_t)-1)
	{
		pthread_join(tid, NULL);
		tid = -1;
	}
#endif
	
	return 0;

/*
	ExCommand Head;
	Head.nSrcType				= 0;
	Head.nCmdType				= JTEVENTSERVER_NOTIFY_STOP_LOOP;
	Head.nCmdSeq				= GenSeq();
	Head.nContentSize			= 0;

	pEventPairPipe->SendCmd((const char*)&Head, sizeof(Head));

#if (defined(WIN32) || defined(WIN64))
	Sleep(2000);
#else
	sleep(2);
#endif
*/

	return 0;
}
示例#4
0
void RandomModeEval()
{
	int size = 7;
	int seq[] = {100,500,1000,2000,3000,4000,5000};

	cout<<"Leftist Tree and Binomial Heap performance after 5000(m) Delete min or Random insert operations \n\n";
	cout<<"After Pre-Insert (n)\t Min Leftist Tree (ms)\t Min Binomial Heap (ms)\n\n";

	long double ltree = 0;
	long double bheap = 0;
	clock_t start, end;
	for(int a = 0; a < size; a++)
	{
		long double TimeLeftist = 0;
		long double TimeBinoHeap = 0;

		for(int j = 0; j < 5; j++)
		{
			int *order = GenSeq(seq[a]);
			MinLeftistT *TreeLeftist = new MinLeftistT();
			TreeLeftist->start(order, seq[a]);
			MinBinomialHeap *heapBinomial = new MinBinomialHeap();
			heapBinomial->start(order, seq[a]);

			for(int i = 0; i < RandomNumber; i++)
			{
				if( rand()%2 == 0 )
				{
					int v = rand() % seq[a];
					start = clock();
					TreeLeftist->InsertNode(v);
					end = clock();
					TimeLeftist += (end - start);
					start = clock();
					heapBinomial->InsertIntoBHeap(v);
					end = clock();
					TimeBinoHeap += (end - start);
				}
				else
				{

					start = clock();
					TreeLeftist->MinDelete();
					end = clock();
					TimeLeftist += (end - start);

					start = clock();
					heapBinomial->MinDeleteBHeap();
					end = clock();
					TimeBinoHeap += (end - start);
				}
			}
			delete heapBinomial;
			delete TreeLeftist;
			delete[] order;
		}

		cout<<"\t"<<seq[a]<<"\t\t\t";
		cout<<(TimeLeftist / (5 * RandomNumber))<<"\t\t\t";
		cout<<(TimeBinoHeap / (5 * RandomNumber))<<"\n";
		ltree += TimeLeftist;
		bheap += TimeBinoHeap;
	}

	cout<<"\nThe running time per operation for Min Leftist Tree is ";
	cout<<(ltree / (5 * size *RandomNumber))<<" ms.\n";
	cout<<"\nThe running time per operation for Min Binomial Heap is ";
	cout<<(bheap / (5 * size * RandomNumber))<<" ms.\n";
}