예제 #1
0
void Manager() {
    int totalLineCount, i, waitTime, senatorLineNum, clrkLineCnt, clrkBribeLineCnt;
    SetMonitor(allCustomersAreDone, 0, 0);
    do {
        Acquire(outsideLock);
        totalLineCount = 0;
        for(i = 0; i < clerkCount; ++i) {
            clrkLineCnt = GetMonitor(clerkLineCount, i);
            clrkBribeLineCnt = GetMonitor(clerkBribeLineCount, i);
            totalLineCount = totalLineCount + clrkLineCnt + clrkBribeLineCnt;
            senatorLineNum = GetMonitor(senatorLineCount, 0);
            if(totalLineCount > 0 || senatorLineNum > 0 ) {
                wakeUpClerks();
                break;
            }
        }
        printMoney();
        Release(outsideLock);
        waitTime = 100;
        for(i = 0; i < waitTime; ++i) {
            Yield();
        }
    } while(!customersAreAllDone());
    SetMonitor(allCustomersAreDone, 0, 1);

    printMoney();
    wakeUpClerks();

}
예제 #2
0
파일: senator.c 프로젝트: bryan/nachos
void waitApplicationLine(int* isAppCleared, int* cash, int socialNumber) {
  Acquire(applicationLineLock);
    SetMonitor(normalApplicationQLength, GetMonitor(normalApplicationQLength) + 1);
    Wait(normalApplicationQCV, applicationLineLock);
  Release(applicationLineLock);

  Acquire(applicationClerkWLock);
    SetMonitor(applicationClerkW, GetMonitor(applicationClerkW) - 1);
  Release(applicationClerkWLock);

  meetApplicationClerk(isAppCleared, socialNumber);
}
예제 #3
0
파일: senator.c 프로젝트: bryan/nachos
/* im passing by reference therefore any changes to these var will be reflected! */
void waitPassportLine(int* isPassCleared, int* cash, int socialNumber){
    Acquire(passportLineLock);
      /* same thing you lose no money */
      SetMonitor(normalPassportQLength, GetMonitor(normalPassportQLength) + 1);
      Wait(normalPassportQCV, passportLineLock);
    Release(passportLineLock);

    Acquire(passportLineClerkWLock);
      SetMonitor(passportClerkW, GetMonitor(passportClerkW) - 1);
    Release(passportLineClerkWLock);

    meetPassportClerk(isPassCleared, socialNumber);
}
예제 #4
0
파일: senator.c 프로젝트: bryan/nachos
/* im passing by reference therefore any changes to these var will be reflected! */
void waitCashierLine(int* isCashCleared, int* cash, int socialNumber) {
  Acquire(cashierLineLock);
    SetMonitor(normalCashierQLength, GetMonitor(normalCashierQLength) + 1);
    Wait(normalCashierQCV, cashierLineLock);
  /* after awoken */
  Release(cashierLineLock);

  Acquire(cashierLineClerkWLock);
    SetMonitor(cashierW, GetMonitor(cashierW) - 1);
  Release(cashierLineClerkWLock);
  
  meetCashier(isCashCleared, cash, socialNumber);
}
예제 #5
0
파일: senator.c 프로젝트: bryan/nachos
void meetPictureClerk(int* isPicCleared, int socialNumber) {
	int i, currentClerkIndex, likingPicture;

	currentClerkIndex = -1;
	while (currentClerkIndex == -1) {
		for (i = 0; i < pictureClerkAmount; i++){
			Acquire(pictureLocks[i]);
			if (GetMonitor(pictureClerkState[i]) == AVAILABLE){
				currentClerkIndex = i;
				SetMonitor(pictureClerkState[i], BUSY);
				break;
			} else {
				Release(pictureLocks[i]);
			}
		}
		if (currentClerkIndex == -1) {
			punish(10, 100); /* wait a little bit, someone will be available soon */
		}
	}

		/* has pictureLocks[i] stil acquired at this point */

		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has gotten in regular line for PictureClerk ", sizeof(" has gotten in regular line for PictureClerk "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write("\n", 1, ConsoleOutput);

		SetMonitor(pictureClerkDB[currentClerkIndex], socialNumber);

	  Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has given SSN ", sizeof(" has given SSN "), ConsoleOutput);
		WriteInt(socialNumber);
		Write(" to PictureClerk ", sizeof(" to PictureClerk "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write("\n", 1, ConsoleOutput);

		Signal(pictureCV[currentClerkIndex], pictureLocks[currentClerkIndex]);
		Wait(pictureCV[currentClerkIndex], pictureLocks[currentClerkIndex]);

		/*awoken */

		SetMonitor(pictureClerkDBCleared[currentClerkIndex], TRUE);
		Signal(pictureCV[currentClerkIndex], pictureLocks[currentClerkIndex]);
		Wait(pictureCV[currentClerkIndex], pictureLocks[currentClerkIndex]);

	Release(pictureLocks[currentClerkIndex]);
	*isPicCleared = TRUE;
}
예제 #6
0
// Todo: need to be saving these BIOs somewhere, and freeing them at
// the end of the run of the application.
//
void SetMonitor(FILE *f)
    {
    BIO *out=BIO_new(BIO_s_file());
    assert(out);
    BIO_set_fp(out,f,BIO_NOCLOSE);
    SetMonitor(out);
    }
예제 #7
0
void ApplicationClerk() {
  int myLine = -1;
  int i, numYields;
  char personName[50];
  int isCustomer = 1, custNumber;
  Acquire(serverClerkLock);
  for(i = 0; i < clerkArray[0]; ++i) {
      if (GetMonitor(clerkOwner, i) == 1 ){ /*ApplicationClerk index*/
          myLine = i;
          SetMonitor(clerkOwner, i, 0);
          break;
      }
  }
  Release(serverClerkLock);


    while(GetMonitor(allCustomersAreDone, 0) == 0) {
        custNumber = chooseCustomerFromLine(myLine, "ApplicationClerk_", 17);
        if(custNumber >= customerCount) {
            isCustomer = 0;
        } else {
            isCustomer = 1;
        }

        SetMonitor(clerkStates, myLine, BUSY);
        hasSignaledString(isCustomer, "ApplicationClerk_", 17, myLine, custNumber);
        Yield();
        givenSSNString(isCustomer, custNumber, "ApplicationClerk_", 17, myLine);
        Yield();
        recievedSSNString(isCustomer, "ApplicationClerk_", 17, myLine, custNumber);

/* CL: random time for applicationclerk to process data */
        numYields = Rand(80, 20);
        for(i = 0; i < numYields; ++i) {
            Yield();
        }
        SetMonitor(applicationIsFiled, custNumber, 1);
        PrintString("ApplicationClerk_", 17); PrintNum(myLine);
        PrintString(" has recorded a completed application for ", 42);
        PrintCust(isCustomer); PrintNum(custNumber); PrintNl();
        /*TODO: delete next line*/
        PrintNum(GetMonitor(applicationIsFiled, custNumber)); PrintString("test11", 6); PrintNl();

        clerkSignalsNextCustomer(myLine);
    }
}
예제 #8
0
파일: senator.c 프로젝트: bryan/nachos
void meetApplicationClerk(int* isAppCleared, int socialNumber) {
	int i, currentClerkIndex;

	/* Find an AVAILABLE applicationClerk or wait */
	currentClerkIndex = -1;
	while (currentClerkIndex == -1) {
		for (i = 0; i < applicationClerkAmount; i++){
			Acquire(applicationLocks[i]);
			if (GetMonitor(applicationClerkState[i]) == AVAILABLE){
				currentClerkIndex = i;
				SetMonitor(applicationClerkState[i], BUSY);
				break;
			} else {
				Release(applicationLocks[i]);
			}
		}
		if (currentClerkIndex == -1) {
			punish(10,100); /* wait a little bit, someone will be available soon */
		}
	}

  Write("Senator ", 8, ConsoleOutput);
  WriteInt(socialNumber);
  Write(" has gotten in regular line for ApplicationClerk ", sizeof(" has gotten in regular line for ApplicationClerk "), ConsoleOutput);
  WriteInt(currentClerkIndex);
  Write("\n", 1, ConsoleOutput);

	/* Give the application clerk your social in global variable */ 
	SetMonitor(applicationClerkDB[currentClerkIndex], socialNumber);

	Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has given SSN ", sizeof(" has given SSN "), ConsoleOutput);
	WriteInt(socialNumber);
	Write(" to ApplicationClerk ", sizeof(" to ApplicationClerk "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	Signal(applicationCV[currentClerkIndex], applicationLocks[currentClerkIndex]);
	Wait(applicationCV[currentClerkIndex], applicationLocks[currentClerkIndex]);
	Release(applicationLocks[currentClerkIndex]);
	*isAppCleared = TRUE;
}
예제 #9
0
int main() {
  int entityId;
  SetupPassportOffice();
  Acquire(application_clerk_init_lock_);
  entityId = GetMonitor(clerk_index_[kApplication], 0);
  SetMonitor(clerk_index_[kApplication], 0, entityId + 1);
  Release(application_clerk_init_lock_);
  RunEntity(APPLICATION_CLERK, entityId);
  Exit(0);
}
예제 #10
0
파일: netclient.c 프로젝트: ianlater/CS350
int main()
{


  Print("Create lock, create cv, create monitor, start monitor val at 1", 100,"","");
  
  CreateLock("Al",2);
  CreateCondition("Acv", 3);
  monitor = CreateMonitor(0, "test", 4);
  SetMonitor(monitor,0, 1);

}
예제 #11
0
bool CWinSystemWin32DX::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
  // When going DX fullscreen -> windowed, we must switch DXGI device to windowed mode first to
  // get it out of fullscreen mode because it restores a former resolution.
  // We then change to the mode we want.
  // In other cases, set the window/mode then swith DXGI mode.
  bool FS2Windowed = !m_useWindowedDX && UseWindowedDX(fullScreen);

  const MONITOR_DETAILS* monitor = GetMonitor(res.iScreen);
  if (!monitor)
    return false;

  SetMonitor(monitor->hMonitor);
  CRenderSystemDX::m_interlaced = ((res.dwFlags & D3DPRESENTFLAG_INTERLACED) != 0);
  CRenderSystemDX::m_useWindowedDX = UseWindowedDX(fullScreen);

  // this needed to prevent resize/move events from DXGI during changing mode
  CWinSystemWin32::m_IsAlteringWindow = true;
  if (FS2Windowed)
    CRenderSystemDX::SetFullScreenInternal();

  if (!m_useWindowedDX)
    SetForegroundWindowInternal(m_hWnd);

  // most 3D content has 23.976fps, so switch for this mode
  if (g_graphicsContext.GetStereoMode() == RENDER_STEREO_MODE_HARDWAREBASED)
    res = CDisplaySettings::GetInstance().GetResolutionInfo(CResolutionUtils::ChooseBestResolution(24.f / 1.001f, res.iWidth, true));

  // so this flags delays call SetFullScreen _after_ resetting render system
  bool delaySetFS = CRenderSystemDX::m_bHWStereoEnabled;
  if (!delaySetFS)
    CWinSystemWin32::SetFullScreen(fullScreen, res, blankOtherDisplays);

  // this needed to prevent resize/move events from DXGI during changing mode
  CWinSystemWin32::m_IsAlteringWindow = true;
  CRenderSystemDX::ResetRenderSystem(res.iWidth, res.iHeight, fullScreen, res.fRefreshRate);

  if (delaySetFS)
  {
    // now resize window and force changing resolution if stereo mode disabled
    if (UseWindowedDX(fullScreen))
      CWinSystemWin32::SetFullScreenEx(fullScreen, res, blankOtherDisplays, !CRenderSystemDX::m_bHWStereoEnabled);
    else
    {
      CRenderSystemDX::SetFullScreenInternal();
      CRenderSystemDX::CreateWindowSizeDependentResources();
    }
  }
  CWinSystemWin32::m_IsAlteringWindow = false;

  return true;
}
예제 #12
0
bool CWinSystemWin32DX::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
  // When going DX fullscreen -> windowed, we must switch DXGI device to windowed mode first to
  // get it out of fullscreen mode because it restores a former resolution.
  // We then change to the mode we want.
  // In other cases, set the window/mode then swith DXGI mode.
  bool FS2Windowed = !m_useWindowedDX && UseWindowedDX(fullScreen);

  const MONITOR_DETAILS* monitor = GetMonitor(res.iScreen);
  if (!monitor)
    return false;

  SetMonitor(monitor->hMonitor);
  CRenderSystemDX::m_interlaced = ((res.dwFlags & D3DPRESENTFLAG_INTERLACED) != 0);
  CRenderSystemDX::m_useWindowedDX = UseWindowedDX(fullScreen);

  // this needed to prevent resize/move events from DXGI during changing mode
  CWinSystemWin32::m_IsAlteringWindow = true;
  if (FS2Windowed)
    CRenderSystemDX::SetFullScreenInternal();

  if (!m_useWindowedDX)
  {
    // if the window isn't focused, bring it to front or SetFullScreen will fail
    BYTE keyState[256] = { 0 };
    // to unlock SetForegroundWindow we need to imitate Alt pressing
    if (GetKeyboardState((LPBYTE)&keyState) && !(keyState[VK_MENU] & 0x80))
      keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);

    BringWindowToTop(m_hWnd);

    if (GetKeyboardState((LPBYTE)&keyState) && !(keyState[VK_MENU] & 0x80))
      keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  }

  // to disable stereo mode in windowed mode we must recreate swapchain and then change display mode
  // so this flags delays call SetFullScreen _after_ resetting render system
  bool delaySetFS = CRenderSystemDX::m_bHWStereoEnabled && UseWindowedDX(fullScreen);
  if (!delaySetFS)
    CWinSystemWin32::SetFullScreen(fullScreen, res, blankOtherDisplays);

  // this needed to prevent resize/move events from DXGI during changing mode
  CWinSystemWin32::m_IsAlteringWindow = true;
  CRenderSystemDX::ResetRenderSystem(res.iWidth, res.iHeight, fullScreen, res.fRefreshRate);
  CWinSystemWin32::m_IsAlteringWindow = false;

  if (delaySetFS)
    // now resize window and force changing resolution if stereo mode disabled
    CWinSystemWin32::SetFullScreenEx(fullScreen, res, blankOtherDisplays, !CRenderSystemDX::m_bHWStereoEnabled);

  return true;
}
예제 #13
0
bool CWinSystemWin32DX::CreateNewWindow(std::string name, bool fullScreen, RESOLUTION_INFO& res, PHANDLE_EVENT_FUNC userFunction)
{
  if(!CWinSystemWin32::CreateNewWindow(name, fullScreen, res, userFunction))
    return false;

  SetFocusWnd(m_hWnd);
  SetDeviceWnd(m_hWnd);
  CRenderSystemDX::m_interlaced = ((res.dwFlags & D3DPRESENTFLAG_INTERLACED) != 0);
  CRenderSystemDX::m_useWindowedDX = UseWindowedDX(fullScreen);
  SetRenderParams(m_nWidth, m_nHeight, fullScreen, res.fRefreshRate);
  SetMonitor(GetMonitor(res.iScreen).hMonitor);

  return true;
}
예제 #14
0
파일: signal.c 프로젝트: ianlater/CS350
int main()
{
  Acquire(0);
  val = GetMonitor(0,0);
  val--;
  PrintInt("Val Decremented to:%d\n", 70, val, 0);
  SetMonitor(0,0,val);
  Signal(0,0);
  Print("Yield to test lock release\n", 60, "", "");
  for(i = 0; i<20000;i++)
    {
      Yield();
    }
  Print("Releasing Lock\n",40,"","");
  Release(0);
}
예제 #15
0
int main(){	
	/*routines for testing lock creation and deletion*/
	printf("Beginning multiClient test. For best results, run with -a debug arguments to see server replies.\n",0,0,0,"","");	
	printf("Creating a new lock on the network...\n",0,0,0,"","");	
	lockID = CreateLock("lock",4);
	printf("LockID = [%d]\n",lockID,0,0,"","");	
	
	printf("Creating a new CV on the network...\n",0,0,0,"","");
	cvID = CreateCondition("CV",2);
	printf("CVID = [%d]\n",cvID,0,0,"","");
	
	
	printf("Creating a new MV on the network...\n",0,0,0,"","");
	mvID = CreateMonitor("MV",2);
	printf("MVID = [%d]\n",mvID,0,0,"","");
	
	printf("Acquiring Lock[%d].\n",lockID,0,0,"","");
	Acquire(lockID);	
	printf("Lock[%d] acquired.\n",lockID,0,0,"","");
		
	printf("Modifying MV[%d].\n",mvID,0,0,"","");
	for (x = 0; x < 20; x++)
	{
		SetMonitor(mvID,x);
	}
	printf("Done modifying. MV[%d] = [%d]\n",mvID,GetMonitor(mvID),0,"","");
	
	
	printf("Signalling CVID[%d].\n",cvID,0,0,"","");
	Signal(cvID,lockID);
	printf("CVID[%d] signaled.\n",cvID,0,0,"","");
	
	
	
	printf("Releasing LockID[%d].\n",lockID,0,0,"","");
	Release(lockID);
	printf("LockID[%d] released",lockID,0,0,"","");		
		
		
	printf("Done.\n",0,0,0,"","");
	
	Exit(0);
}
예제 #16
0
int main(){
	PrintString("Setting monitors\n", 17);
  Acquire(lock1);
	SetMonitor(mon1, 0, 9);
	for (i = 0; i < 30000; ++i){
		Yield();
	}
	Release(lock1);
	PrintString("Waiting on lock2\n", 17);
	Acquire(lock1);
  Wait(lock1, cond1);
	Release(lock1);

	PrintString("Destroying Monitors 1 and 2\n", 28);
	DestroyMonitor(mon1);
	DestroyMonitor(mon2);

	Exit(1);
}
bool CWinSystemWin32DX::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
  // When going DX fullscreen -> windowed, we must reset the D3D device first to
  // get it out of fullscreen mode because it restores a former resolution.
  // We then change to the mode we want.
  // In other cases, set the window/mode then reset the D3D device.

  bool FS2Windowed = !m_useWindowedDX && UseWindowedDX(fullScreen);

  SetMonitor(GetMonitor(res.iScreen).hMonitor);
  CRenderSystemDX::m_interlaced = ((res.dwFlags & D3DPRESENTFLAG_INTERLACED) != 0);
  CRenderSystemDX::m_useWindowedDX = UseWindowedDX(fullScreen);

  if (FS2Windowed)
    CRenderSystemDX::ResetRenderSystem(res.iWidth, res.iHeight, fullScreen, res.fRefreshRate);

  CWinSystemWin32::SetFullScreen(fullScreen, res, blankOtherDisplays);
  CRenderSystemDX::ResetRenderSystem(res.iWidth, res.iHeight, fullScreen, res.fRefreshRate);

  return true;
}
// The mint has a different key pair for each denomination.
// Pass the actual denomination such as 5, 10, 20, 50, 100...
bool OTMint_Lucre::AddDenomination(OTPseudonym & theNotary, int64_t lDenomination, int32_t nPrimeLength/*=1024*/)
{
    OT_ASSERT(NULL != m_pKeyPublic);
    
	bool bReturnValue = false;
	
	// Let's make sure it doesn't already exist
	OTASCIIArmor theArmor;
	if (GetPublic(theArmor, lDenomination))
	{
		// it already exists.
		OTLog::Error("Error: Denomination public already exists in OTMint::AddDenomination\n");
		return false;
	}
	if (GetPrivate(theArmor, lDenomination))
	{
		// it already exists.
		OTLog::Error("Error: Denomination private already exists in OTMint::AddDenomination\n");
		return false;
	}
	
	//		OTLog::Error("%s <size of bank prime in bits> <bank data file> <bank public data file>\n",
	
    if ((nPrimeLength/8) < (MIN_COIN_LENGTH+DIGEST_LENGTH))
	{
		OTLog::vError("Prime must be at least %d bits\n",
				(MIN_COIN_LENGTH+DIGEST_LENGTH)*8);
		return false;
	}
	
    if (nPrimeLength%8)
	{
		OTLog::Error("Prime length must be a multiple of 8\n");
		return false;
	}
	
#ifdef _WIN32
	SetMonitor("openssl.dump");
#else
	SetMonitor(stderr);
#endif
	
    OpenSSL_BIO bio		=	BIO_new(BIO_s_mem());
    OpenSSL_BIO bioPublic	=	BIO_new(BIO_s_mem());
	
	// Generate the mint private key information
    Bank bank(nPrimeLength/8);
    bank.WriteBIO(bio);
	
	// Generate the mint public key information
    PublicBank pbank(bank);
    pbank.WriteBIO(bioPublic);	
	
	// Copy from BIO back to a normal OTString or Ascii-Armor  
	char privateBankBuffer[4096], publicBankBuffer[4096];   // todo stop hardcoding these string lengths
	int32_t  privatebankLen	= BIO_read(bio, privateBankBuffer, 4000); // cutting it a little short on purpose, with the buffer.
	int32_t  publicbankLen	= BIO_read(bioPublic, publicBankBuffer, 4000); // Just makes me feel more comfortable for some reason.
	
	if (privatebankLen && publicbankLen)
	{
		// With this, we have the Lucre public and private bank info converted to OTStrings
		OTString strPublicBank;		strPublicBank.Set(publicBankBuffer, publicbankLen);
		OTString strPrivateBank;	strPrivateBank.Set(privateBankBuffer, privatebankLen);
		
		OTASCIIArmor * pPublic	= new OTASCIIArmor();
		OTASCIIArmor * pPrivate	= new OTASCIIArmor();
		
		OT_ASSERT(NULL != pPublic);
		OT_ASSERT(NULL != pPrivate);
		
		// Set the public bank info onto pPublic
		pPublic->SetString(strPublicBank, true); // linebreaks = true
		
		// Seal the private bank info up into an encrypted Envelope 
		// and set it onto pPrivate
		OTEnvelope theEnvelope;
		theEnvelope.Seal(theNotary, strPrivateBank);	// Todo check the return values on these two functions
		theEnvelope.GetAsciiArmoredData(*pPrivate);
		
		// Add the new key pair to the maps, using denomination as the key
		m_mapPublic[lDenomination]	= pPublic;
		m_mapPrivate[lDenomination]	= pPrivate;
		
		// Grab the Server Nym ID and save it with this Mint
		theNotary.GetIdentifier(m_ServerNymID);
        // ---------------------------
		// Grab the Server's public key and save it with this Mint
        //
        const OTAsymmetricKey & theNotaryPubKey = theNotary.GetPublicSignKey();
        delete m_pKeyPublic;
        m_pKeyPublic = theNotaryPubKey.ClonePubKey();
        // ---------------------------
		m_nDenominationCount++;
        // ---------------------------		
		// Success!
		bReturnValue = true;
		OTLog::vOutput(1, "Successfully added denomination: %lld\n", lDenomination);
	}
	
	return bReturnValue;
}
void CWinSystemWin32DX::UpdateMonitor()
{
  SetMonitor(GetMonitor(m_nScreen).hMonitor);
}
예제 #20
0
void CWinSystemWin32DX::UpdateMonitor()
{
  const MONITOR_DETAILS* monitor = GetMonitor(m_nScreen);
  if (monitor)
    SetMonitor(monitor->hMonitor);
}
예제 #21
0
int chooseCustomerFromLine(int myLine, char* clerkName, int clerkNameLength) {
    int testFlag = false;
    int clerkBribeLineCnt, clerkLineCnt, senatorLineCnt, senatorDoneMon, clerkState, allCustDone;
    do {
        testFlag = false;
        /* TODO: -1 used to be NULL.  Hung needs to figure this out */
        senatorLineCnt = GetMonitor(senatorLineCount, 0);
        senatorDoneMon = GetMonitor(senatorDone, 0);
        if((senatorLineCnt > 0 ) || (senatorLineCnt > 0 && senatorDoneMon == 1)) {
            /* CL: chooses senator line first */
            PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is required by the senator\n", 29);/*HUNG LINE*/
            Acquire(clerkSenatorCVLock[myLine]);
            PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" clerkSenatorCVLock acquired\n", 30);/*HUNG LINE*/
            Signal(clerkSenatorCVLock[myLine], clerkSenatorCV[myLine]);
            PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" clerkSenatorCVLock signal\n", 29);/*HUNG LINE*/
              /*Wait for senator here, if they need me*/
            Wait( clerkSenatorCVLock[myLine], clerkSenatorCV[myLine]);
            PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" clerkSenatorCVLock waited e\n", 30);/*HUNG LINE*/

            if(senatorLineCnt == 0){
              Acquire(clerkLineLock);
              PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" was unused by senator\n", 23);/*HUNG LINE*/
              SetMonitor(clerkStates, myLine, AVAILABLE);
              Release(clerkSenatorCVLock[myLine]);
            }else if(senatorLineCnt > 0 && senatorDoneMon == 1){
              SetMonitor(clerkStates, myLine, AVAILABLE);
              PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is being used by senator\n", 26);/*HUNG LINE*/

              Release(clerkSenatorCVLock[myLine]);
            }else{
              SetMonitor(clerkStates, myLine, BUSY);
              testFlag = true;
            }
            PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" clerkSenatorCVLock waited f\n", 30);/*HUNG LINE*/

        }else{
          PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is not required by the senator\n", 33);/*HUNG LINE*/
            Acquire(clerkLineLock);

              PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" acquired clerkLinelock\n", 24);/*HUNG LINE*/
            clerkBribeLineCnt = GetMonitor(clerkBribeLineCount, myLine);
            clerkLineCnt = GetMonitor(clerkLineCount, myLine);
            if(clerkBribeLineCnt > 0) {
                PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is servicing a customer from bribe line\n", 41);
                Signal(clerkLineLock, clerkBribeLineCV[myLine]);
                SetMonitor(clerkStates, myLine, BUSY); /*redundant setting*/
            } else if(clerkLineCnt > 0) {
                PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is servicing a customer from regular line\n", 43);
                Signal(clerkLineLock, clerkLineCV[myLine]);
                SetMonitor(clerkStates, myLine, BUSY); /*redundant setting*/
            }else{
                Acquire(breakLock[myLine]);
                PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is going on break\n", 19);
                SetMonitor(clerkStates, myLine, ONBREAK);
                Release(clerkLineLock);
                Wait(breakLock[myLine], breakCV[myLine]);
                /*PrintNum(breakLock[myLine]); PrintNl();*/
                PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" is waking up from a break now.\n", 33); PrintNl();/*HUNG LINE*/
                SetMonitor(clerkStates, myLine, AVAILABLE);
                Release(breakLock[myLine]);
                allCustDone = GetMonitor(allCustomersAreDone, 0);
                if(allCustDone == 1) {
                    Exit(0);
                }
            }
        }
        clerkState = GetMonitor(clerkStates, myLine);
    } while(clerkState!= BUSY);

    PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" Acquring clerkLock\n", 21);/*HUNG LINE*/

    Acquire(clerkLock[myLine]);
    PrintString(clerkName, clerkNameLength); PrintNum(myLine); PrintString(" Clerklock acquired\n", 21);/*HUNG LINE*/

    Release(clerkLineLock);
    /*wait for customer*/
    if(testFlag){
      Signal(clerkSenatorCVLock[myLine], clerkSenatorCV[myLine]);
      Release(clerkSenatorCVLock[myLine]);
    }
    Wait(clerkLock[myLine], clerkCV[myLine]);
    /*Do my job -> customer waiting*/
    clerkState = GetMonitor(customerData, myLine);
    return clerkState;
}
예제 #22
0
파일: c_svr.cpp 프로젝트: bagdxk/openafs
BOOL SERVER::RefreshAll (ULONG *pStatus, double dInit, double dFactor)
{
   BOOL rc = TRUE;
   ULONG status = 0;

   if (m_fAggregatesOutOfDate || m_fServicesOutOfDate)
      {
      if ((++cRefreshAllReq) == 1)
         {
         NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllBegin, GetIdentifier(), 0);
         }

      double perAGGREGATES = 65.0; // % of time spent finding aggs & sets
      double perSERVICES   = 25.0; // % of time spent finding services
      double perVLDB       = 10.0; // % of time spent finding VLDB info

      if (cRefreshAllReq >= 2) // being called as part of a cell-wide op?
         {
         perAGGREGATES = 80.0; // % of time spent finding aggs & sets
         perSERVICES   = 20.0; // % of time spent finding services
         perVLDB       = 0.0;  // we won't query VLDB stuff ourself.
         }

      NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusBegin, GetIdentifier());

      if (!CanTalkToServer (&status))  // Determines fCanGetAggregates, fCanGetServices
         {
         if (m_fMonitor)
            SetMonitor (FALSE);
         rc = FALSE;
         }
      else
         {
         if (!m_fCanGetAggregates)
            {
            FreeAggregates();
            m_fAggregatesOutOfDate = FALSE;
            }
         else
            {
            size_t nAggregates = 0;
            size_t iAggregate = 0;
            HENUM hEnum;
            LPAGGREGATE lpAggregate;
            for (lpAggregate = AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = AggregateFindNext (&hEnum))
               {
               ++nAggregates;
               lpAggregate->Close();
               }

            if (nAggregates)
               {
               for (lpAggregate = AggregateFindFirst (&hEnum); lpAggregate; lpAggregate = AggregateFindNext (&hEnum))
                  {
                  ULONG perComplete = (ULONG)( ((double)perAGGREGATES / 100.0) * ((double)iAggregate * 100.0 / nAggregates) );
                  NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllUpdate, lpAggregate->GetIdentifier(), NULL, NULL, NULL, (ULONG)( 100.0 * dInit + dFactor * (double)perComplete ), 0);

                  lpAggregate->RefreshFilesets (TRUE);
                  lpAggregate->Close();

                  ++iAggregate;
                  }
               }
            }

         if (!m_fCanGetServices)
            {
            FreeServices();
            m_fServicesOutOfDate = FALSE;
            }
         else
            {
            size_t nServices = 0;
            size_t iService = 0;
            HENUM hEnum;
            LPSERVICE lpService;
            for (lpService = ServiceFindFirst (&hEnum); lpService; lpService = ServiceFindNext (&hEnum))
               {
               ++nServices;
               lpService->Close();
               }

            if (nServices)
               {
               for (lpService = ServiceFindFirst (&hEnum); lpService; lpService = ServiceFindNext (&hEnum))
                  {
                  ULONG perComplete = (ULONG)( (double)perAGGREGATES + ((double)perSERVICES / 100.0) * ((double)iService * 100.0 / nServices) );
                  NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllUpdate, lpService->GetIdentifier(), NULL, NULL, NULL, (ULONG)( 100.0 * dInit + dFactor * (double)perComplete ), 0);

                  lpService->RefreshStatus (TRUE);
                  lpService->Close();

                  ++iService;
                  }
               }
            }

         if (cRefreshAllReq == 1) // not being called as part of a cell-wide op?
            {
            LPCELL lpCell;
            if ((lpCell = OpenCell()) != NULL)
               {
               lpCell->RefreshVLDB (GetIdentifier(), TRUE, NULL);
               lpCell->Close();
               }
            }
         }

      NOTIFYCALLBACK::SendNotificationToAll (evtRefreshStatusEnd, GetIdentifier(), m_lastStatus);

      if ((--cRefreshAllReq) == 0)
         {
         NOTIFYCALLBACK::SendNotificationToAll (evtRefreshAllEnd, GetIdentifier(), NULL, NULL, NULL, 100, m_lastStatus);
         }
      }

   if (rc && m_lastStatus)
      rc = FALSE;
   if (!rc && pStatus)
      *pStatus = status;
   return rc;
}
예제 #23
0
파일: senator.c 프로젝트: bryan/nachos
void meetPassportClerk(int* isPassCleared, int socialNumber) {
	int i, currentClerkIndex;

	/* will talk to clerk now */
	currentClerkIndex = -1;
	while (currentClerkIndex == -1) {
		for (i = 0; i < passportClerkAmount; i++){
			Acquire(passportLocks[i]);
			if (GetMonitor(passportClerkState[i]) == AVAILABLE){
				currentClerkIndex = i;
				SetMonitor(passportClerkState[i], BUSY);
				break;
			} else {
				Release(passportLocks[i]);
			}
		}
		if (currentClerkIndex == -1) {
			punish(10,100); /* wait a little bit, someone will be available soon */
		}
	}

  Write("Senator ", 8, ConsoleOutput);
  WriteInt(socialNumber);
  Write(" has gotten in regular line for PassportClerk ", sizeof(" has gotten in regular line for PassportClerk "), ConsoleOutput);
  WriteInt(currentClerkIndex);
  Write("\n", 1, ConsoleOutput);

	SetMonitor(passportClerkDB[currentClerkIndex], socialNumber);

  Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has given SSN ", sizeof(" has given SSN "), ConsoleOutput);
	WriteInt(socialNumber);
	Write(" to passportClerk ", sizeof(" to passportClerk "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	Signal(passportCV[currentClerkIndex], passportLocks[currentClerkIndex]);
	Wait(passportCV[currentClerkIndex], passportLocks[currentClerkIndex]);

	/*awoken */

	if (passportClerkDBCleared[currentClerkIndex]){
		/* that means cashier is notified that the previous */
		/* requirements have been completed and is cleared to continue */
		/* for user to pay and get checked off */
		Release(passportLocks[currentClerkIndex]);
		*isPassCleared = TRUE;
	} else {
		/* customer should NOT be here, punish the user */
		
		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has gone to passportClerk ", sizeof(" has gone to passportClerk "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write(" too soon. They are going to the back of the line.", sizeof(" too soon. They are going to the back of the line."), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);

		Release(passportLocks[currentClerkIndex]);
		punish(100, 1000);
	}
}
예제 #24
0
파일: senator.c 프로젝트: bryan/nachos
void meetCashier(int* isCashCleared, int* cash, int socialNumber) {
	int i, currentClerkIndex;

	currentClerkIndex = -1;
	while (currentClerkIndex == -1) {
		for (i = 0; i < cashierAmount; i++) {
			Acquire(cashierLocks[i]);
			if (GetMonitor(cashierClerkState[i]) == AVAILABLE) {
				currentClerkIndex = i;
				/* set clerk to busy, helping us now */
				SetMonitor(cashierClerkState[i], BUSY);
				break;
			} else { /* either on break or busy, can't do anything with this clerk atm */
				Release(cashierLocks[i]);
			}
		}
		if (currentClerkIndex == -1) {
			punish(10,100); /* wait a little bit, someone will be available soon */
		}
	}
	
	Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has gotten in regular line for CashierClerk ", sizeof(" has gotten in regular line for CashierClerk "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	/* customer is at cashier now */
	SetMonitor(cashierDB[currentClerkIndex], socialNumber);

	Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has given SSN ", sizeof(" has given SSN "), ConsoleOutput);
	WriteInt(socialNumber);
	Write(" to cashier ", sizeof(" to cashier "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	Signal(cashierCV[currentClerkIndex], cashierLocks[currentClerkIndex]);
	Wait(cashierCV[currentClerkIndex], cashierLocks[currentClerkIndex]);

	if (GetMonitor(cashierDBCleared[currentClerkIndex])){
		/* that means cashier is notified that the previous */
		/* requirements have been completed and is cleared to continue */
		/* for user to pay and get checked off */
		
		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has given Cashier ", sizeof(" has given Cashier "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write(" $100", sizeof(" $100"), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);

		*cash -= 100;
		*isCashCleared = TRUE;
		Release(cashierLocks[currentClerkIndex]);
	} else {
		/* customer should NOT be here, punish the user */		
		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has gone to Cashier ", sizeof(" has gone to Cashier "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write(" too soon. They are going to the back of the line.", sizeof(" too soon. They are going to the back of the line."), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);

		Release(cashierLocks[currentClerkIndex]);
		punish(100, 1000);
	}
}
예제 #25
0
파일: senator.c 프로젝트: bryan/nachos
void Senator() {
	int isAppCleared = FALSE;
	int isPicCleared = FALSE;
	int isPassCleared = FALSE;
	int isCashCleared = FALSE;
	int receivedPass = FALSE;
	int i;
	int cashList[4] = {100, 600, 1100, 1600};
	int cash = cashList[Rand(1,100) % 4];
	int socialNumber, picOrAppLine;

	setup();
	
	for (i = customerAmount; i < customerAmount + senatorAmount; i++){
		Acquire(customerSenatorLockList[i]);
		if (GetMonitor(customerSenatorList[i]) == !TAKEN) {
			socialNumber = i;
			SetMonitor(customerSenatorList[i], TAKEN);
			Release(customerSenatorLockList[i]);
			break;
		}
		Release(customerSenatorLockList[i]);
	}

	Write("Senator obtained socialNumber: ", sizeof("Senator obtained socialNumber: "), ConsoleOutput);
	WriteInt(socialNumber);
	Write("\n", 1, ConsoleOutput);	

	/* senator enters the post office */
	Acquire(queueWaitLock);
		SetMonitor(queueSenator, GetMonitor(queueSenator) + 1);
		if (GetMonitor(queueCustomer) > 0) {
			Release(queueWaitLock);

			/* that means there are customers */
			/* then senators need to wait until the queue gets cleared */
			Acquire(queueSenatorLock);
				Wait(queueSenatorCV, queueSenatorLock);
			Release(queueSenatorLock);
		} else {
			Release(queueWaitLock);
		}

	while (!receivedPass) {
		if (isAppCleared && isPicCleared && isPassCleared && isCashCleared) {
			/* safe to say that the passport has been received */
			receivedPass = TRUE;
			break;
		}
			
		while (!isPicCleared || !isAppCleared) {
			if (!isPicCleared || !isAppCleared) {
				picOrAppLine = Rand(1, 100) % 2;
				switch(picOrAppLine) {
					case 0: /* get in pic line */
						waitPictureLine(&isPicCleared, &cash, socialNumber);
						break;
					case 1: /* get in app line */
						waitApplicationLine(&isAppCleared, &cash, socialNumber);
						break;
				}
			} else if (!isPicCleared) waitPictureLine(&isPicCleared, &cash, socialNumber);
			else waitApplicationLine(&isAppCleared, &cash, socialNumber);
		}

		while (!isPassCleared) {
			waitPassportLine(&isPassCleared, &cash, socialNumber);
		}

		while (!isCashCleared) {
			waitCashierLine(&isCashCleared, &cash, socialNumber);
		}
	}

	/* senator is done */
	Acquire(queueWaitLock);
		SetMonitor(queueSenator, GetMonitor(queueSenator) - 1); /* remove him from the overall pool */
	
		Write("Senator ", sizeof("Senator "), ConsoleOutput);
		WriteInt(socialNumber);
		Write(" is leaving the Passport Office.", sizeof(" is leaving the Passport Office."), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);  
	
	Release(queueWaitLock);
	Exit(0);

}