}
/////////////////////////////////////////////////////////////////////////////////////
/// client treads realization ///////////////////////////////////////////////////////
DWORD WINAPI Client1Thread(HWND hWnd)
{
UINT uCount;
UINT uTime;
char cBuff[10];
UINT TurnLength;
for(uCount=1; uCount<=5000; uCount++)
{
//generate to next client uTime --- in miliseconds
//uTime = CLIENT1_COMETIME + Generator();
uTime = (unsigned)(CLIENT1_COMETIME * TIME_RATIO);
uTime += (unsigned)(Generator() * TIME_RATIO);
Sleep(uTime);
//is CMO working
if(bCMOWork==FALSE) return 0;
//add client1 to the first turn
WaitForSingleObject(hSemaphore, INFINITE);
Turn1[uCount].uNumber = uCount;
Turn1[uCount].uIn = GetTickCount();
Turn1[uCount].uOut = 0;
uAmount1++;
//update main window
uTurn1++;
IntToStr(cBuff, uTurn1);
SendDlgItemMessage(hWnd, IDC_TURN1, WM_SETTEXT, 0, (long)cBuff);
uTurn++;
IntToStr(cBuff, uTurn);
SendDlgItemMessage(hWnd, IDC_TURN, WM_SETTEXT, 0, (long)cBuff);
ReleaseSemaphore(hSemaphore, 1, NULL);
}
return 0;
}
DWORD WINAPI Client2Thread(HWND hWnd)
{
UINT uCount;
UINT uTime;
char cBuff[10];
UINT TurnLength;
for(uCount=1; uCount<=5000; uCount++)
{
//generate to next client uTime --- in miliseconds
//uTime = CLIENT2_COMETIME + Generator();
uTime = (unsigned)(CLIENT2_COMETIME * TIME_RATIO);
uTime += (unsigned)(Generator() * TIME_RATIO);
Sleep(uTime);
//is CMO working
if(bCMOWork==FALSE) return 0;
//add client2 to the first turn
WaitForSingleObject(hSemaphore, INFINITE);
Turn2[uCount].uNumber = uCount;
Turn2[uCount].uIn = GetTickCount();
uAmount2++;
//update main window
uTurn2++;
IntToStr(cBuff, uTurn2);
SendDlgItemMessage(hWnd, IDC_TURN2, WM_SETTEXT, 0, (long)cBuff);
uTurn++;
IntToStr(cBuff, uTurn);
SendDlgItemMessage(hWnd, IDC_TURN, WM_SETTEXT, 0, (long)cBuff);
ReleaseSemaphore(hSemaphore, 1, NULL);
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////
////////// timer procedure //////////////////////////////////////////////////////////
void Serving(CLIENT *lpClient, UINT uClientType, UINT uServingTime)
{
char cBuff[10];
UINT uQuitTime;
UINT uStart;
//calculate quit time
uStart = GetTickCount();
uQuitTime = GetTickCount() + uServingTime;
//update main window
IntToStr(cBuff, uClientType);
SendDlgItemMessage(hMainWindow, IDC_CLIENTTYPE, WM_SETTEXT, 0, (long)cBuff);
do
{
IntToStr(cBuff, GetTickCount() - uStart);
SendDlgItemMessage(hMainWindow, IDC_PASSED, WM_SETTEXT, 0, (long)cBuff);
}while(uQuitTime >= GetTickCount());
lpClient->uOut = GetTickCount();
return;
}
/////////////////////////////////////////////////////////////////////////////////////
////////// timer procedure //////////////////////////////////////////////////////////
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
char cBuff[10];
uWorkingTime++;
IntToStr(cBuff, uWorkingTime);
SendDlgItemMessage(hMainWindow, IDC_WORKINGTIME, WM_SETTEXT, 0, (long)cBuff);
return;
}