Exemple #1
0
int customersAreAllDone() {
    int boolCount = 0, i, temp, appMon, likeMon, certMon, doneMon;
    for(i = 0; i < customerCount + senatorCount; ++i) {
        temp = GetMonitor(isDone, i);
        boolCount += temp;
    }
    prevTotalBoolCount = currentTotalBoolCount;
    currentTotalBoolCount = 0;
    for(i = 0; i < customerCount; ++i) {
        appMon = GetMonitor(applicationIsFiled, i);
        likeMon = GetMonitor(likesPicture, i);
        certMon = GetMonitor(hasCertification, i);
        doneMon = GetMonitor(isDone, i);
        /*  currentTotalBoolCount = currentTotalBoolCount + appMon + likeMon + certMon + doneMon;*/

        currentTotalBoolCount = currentTotalBoolCount + doneMon;
    }
    PrintString("Manager is counting finished customers ", 39);
    PrintNum(currentTotalBoolCount);
    PrintNl();

    if(prevTotalBoolCount == currentTotalBoolCount) {
        wakeUpClerks();
    }

    if(boolCount == customerCount + senatorCount) {
        return true;
    }
    return false;
}
Exemple #2
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();

}
Exemple #3
0
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);
}
Exemple #4
0
/* 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);
}
Exemple #5
0
/* 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);
}
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);
    }
}
Exemple #7
0
void CWinSystemWin32DX::OnMove(int x, int y)
{
  HMONITOR newMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
  const MONITOR_DETAILS* monitor = GetMonitor(m_nScreen);
  if (newMonitor != monitor->hMonitor)
  {
    m_deviceResources->SetMonitor(newMonitor);
    m_nScreen = GetCurrentScreen();
  }
}
Exemple #8
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);
}
Ptr<FlowMonitor>
FlowMonitorHelper::Install (Ptr<Node> node)
{
  Ptr<FlowMonitor> monitor = GetMonitor ();
  Ptr<FlowClassifier> classifier = GetClassifier ();
  Ptr<Ipv4FlowProbe> probe = Create<Ipv4FlowProbe> (monitor,
                                                    DynamicCast<Ipv4FlowClassifier> (classifier),
                                                    node);
  return m_flowMonitor;
}
bool
RegisterContextPOSIXProcessMonitor_arm64::ReadRegister(const unsigned reg,
                                                       lldb_private::RegisterValue &value)
{
    ProcessMonitor &monitor = GetMonitor();
    return monitor.ReadRegisterValue(m_thread.GetID(),
                                     GetRegisterOffset(reg),
                                     GetRegisterName(reg),
                                     GetRegisterSize(reg),
                                     value);
}
bool
RegisterContextPOSIXProcessMonitor_arm64::WriteRegister(const unsigned reg,
                                                         const lldb_private::RegisterValue &value)
{
    unsigned reg_to_write = reg;
    lldb_private::RegisterValue value_to_write = value;

    // Check if this is a subregister of a full register.
    const lldb_private::RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
    if (reg_info->invalidate_regs && (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM))
    {
        lldb_private::RegisterValue full_value;
        uint32_t full_reg = reg_info->invalidate_regs[0];
        const lldb_private::RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);

        // Read the full register.
        if (ReadRegister(full_reg_info, full_value))
        {
            lldb_private::Error error;
            lldb::ByteOrder byte_order = GetByteOrder();
            uint8_t dst[lldb_private::RegisterValue::kMaxRegisterByteSize];

            // Get the bytes for the full register.
            const uint32_t dest_size = full_value.GetAsMemoryData (full_reg_info,
                                                                   dst,
                                                                   sizeof(dst),
                                                                   byte_order,
                                                                   error);
            if (error.Success() && dest_size)
            {
                uint8_t src[lldb_private::RegisterValue::kMaxRegisterByteSize];

                // Get the bytes for the source data.
                const uint32_t src_size = value.GetAsMemoryData (reg_info, src, sizeof(src), byte_order, error);
                if (error.Success() && src_size && (src_size < dest_size))
                {
                    // Copy the src bytes to the destination.
                    ::memcpy (dst + (reg_info->byte_offset & 0x1), src, src_size);
                    // Set this full register as the value to write.
                    value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
                    value_to_write.SetType(full_reg_info);
                    reg_to_write = full_reg;
                }
            }
        }
    }

    ProcessMonitor &monitor = GetMonitor();
    return monitor.WriteRegisterValue(m_thread.GetID(),
                                      GetRegisterOffset(reg_to_write),
                                      GetRegisterName(reg_to_write),
                                      value_to_write);
}
Exemple #12
0
VOID
	PrepareMainThread()
{
	PMONITOR Monitor = GetMonitor();
	HMODULE hModule = NULL;
	HWINSTA hWinsta = NULL;
	HDESK hDesk = NULL;
	PCLIENT_THREAD_SETUP ClientThreadSetup = NULL;

	hModule = LoadLibrary(L"user32.dll");
	if (hModule == NULL) {
		DebugPrint(L"LoadLibrary failed\n");
		return;
	}
	
	DebugPrint(L"IsGUIThread=%x\n", IsGUIThread(TRUE));

	ClientThreadSetup = (PCLIENT_THREAD_SETUP)GetProcAddress(hModule, "ClientThreadSetup");
	if (ClientThreadSetup == NULL) {
		DebugPrint(L"ClientThreadSetup not found in mod=%p\n", hModule);
		goto cleanup;
	}
	
	BOOL Result = ClientThreadSetup();
	DebugPrint(L"ClientThreadSetup=%x\n", Result);
	hWinsta = DeviceOpenWinsta(L"WinSta0");
	if (hWinsta != NULL) {
		hDesk = DeviceOpenDesktop(hWinsta, L"Default");
	}
	
	DebugPrint(L"Opened hwinsta=%p, hdesk=%p\n", hWinsta, hDesk);

	if (hWinsta != NULL) {
		if (!SetProcessWindowStation(hWinsta)) {
			DebugPrint(L"SetProcessWindowStation failed, err=%d, hWinsta=%x\n", GetLastError(), hWinsta);
		}
	}

	if (hDesk != NULL) {
		if (!SetThreadDesktop(hDesk)) {
			DebugPrint(L"SetThreadDesktop failed, error=%d\n", GetLastError());
		}
	}

	if (hDesk != NULL)
		CloseDesktop(hDesk);

	if (hWinsta != NULL)
		CloseWindowStation(hWinsta);
	
cleanup:	
	FreeLibrary(hModule);
}
Exemple #13
0
bool CWinSystemWin32DX::CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res)
{
  const MONITOR_DETAILS* monitor = GetMonitor(res.iScreen);
  if (!monitor)
    return false;

  m_deviceResources = DX::DeviceResources::Get();
  // setting monitor before creating window for proper hooking into a driver
  m_deviceResources->SetMonitor(monitor->hMonitor);

  return CWinSystemWin32::CreateNewWindow(name, fullScreen, res) && m_deviceResources->HasValidDevice();
}
Exemple #14
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;
}
Exemple #15
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;
}
Exemple #16
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;
}
Exemple #17
0
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;
}
Exemple #18
0
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);
}
Exemple #19
0
RECT CWinSystemWin32::ScreenRect(int screen)
{
  const MONITOR_DETAILS &details = GetMonitor(screen);

  DEVMODE sDevMode;
  ZeroMemory(&sDevMode, sizeof(DEVMODE));
  sDevMode.dmSize = sizeof(DEVMODE);
  EnumDisplaySettings(details.DeviceName, ENUM_CURRENT_SETTINGS, &sDevMode);

  RECT rc;
  rc.left = sDevMode.dmPosition.x;
  rc.right = sDevMode.dmPosition.x + sDevMode.dmPelsWidth;
  rc.top = sDevMode.dmPosition.y;
  rc.bottom = sDevMode.dmPosition.y + sDevMode.dmPelsHeight;

  return rc;
}
Exemple #20
0
RECT CWinSystemWin32::ScreenRect(int screen)
{
    const MONITOR_DETAILS &details = GetMonitor(screen);

    DEVMODE sDevMode;
    ZeroMemory(&sDevMode, sizeof(DEVMODE));
    sDevMode.dmSize = sizeof(DEVMODE);
    if(!EnumDisplaySettings(details.DeviceName, ENUM_CURRENT_SETTINGS, &sDevMode))
        CLog::Log(LOGERROR, "%s : EnumDisplaySettings failed with %d", __FUNCTION__, GetLastError());

    RECT rc;
    rc.left = sDevMode.dmPosition.x;
    rc.right = sDevMode.dmPosition.x + sDevMode.dmPelsWidth;
    rc.top = sDevMode.dmPosition.y;
    rc.bottom = sDevMode.dmPosition.y + sDevMode.dmPelsHeight;

    return rc;
}
Exemple #21
0
void CSVSortList::enumMonitor(string &szDeviceIndex)
{
    OBJECT objDevice = GetEntity(szDeviceIndex,  m_szIDCUser, m_szIDCPwd);
    if(objDevice != INVALID_VALUE)
    {
        list<string> lsMonitorID;
        list<string>::iterator lstItem;
        if (GetSubMonitorsIDByEntity(objDevice, lsMonitorID))
        {
            string szDeviceName ("");
            MAPNODE mainnode = GetEntityMainAttribNode(objDevice);
            if(mainnode != INVALID_VALUE)
                FindNodeValue(mainnode, "sv_name", szDeviceName);
            
            int nIndex = 0;
            base_param monitor;
            for(lstItem = lsMonitorID.begin(); lstItem != lsMonitorID.end(); lstItem ++)
            {
                string szMonitorId = (*lstItem).c_str();
                OBJECT objMonitor = GetMonitor(szMonitorId, m_szIDCUser, m_szIDCPwd);
                if(objMonitor != INVALID_VALUE)
                {
                    MAPNODE node = GetMonitorMainAttribNode(objMonitor);
                    if(node != INVALID_VALUE)
                    {
                        string szName (""), szIndex ("");
                        FindNodeValue(node, "sv_name", szName);
                        FindNodeValue(node, "sv_index", szIndex);
                        if(szIndex.empty())
                            nIndex = FindIndexByID(szMonitorId);
                        else
                            nIndex = atoi(szIndex.c_str());

                        monitor.szIndex = szMonitorId;
                        monitor.szName = szDeviceName + ":" + szName;
                        m_sortList[nIndex] = monitor;
                    }
                    CloseMonitor(objMonitor);
                }
            }
        }
        CloseEntity(objDevice);
    }
}
Exemple #22
0
/*This function wakes up ALL clerks, so they check their lines, if noone is in their line, they'll go back on break*/
void wakeUpClerks() {
    int i;
    for(i = 0; i < clerkCount; ++i) {
        if(GetMonitor(clerkStates, i) == ONBREAK) {
            PrintString("Manager has woken up a ", 23);
            PrintString(clerkTypes[i], clerkTypesLengths[i]);
            PrintString("_", 1);
            PrintNum(i);
            PrintNl();
            Acquire(breakLock[i]);
            Signal(breakLock[i],breakCV[i]);
            Release(breakLock[i]);
            PrintString(clerkTypes[i], clerkTypesLengths[i]);
            PrintString("_", 1);
            PrintNum(i);
            PrintString(" is coming off break\n", 21);
        }
    }
}
Exemple #23
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);
}
Exemple #24
0
string  GetMonitorPropValue(string strId, string strPropName)
{
	string strTmp = "";

	//监测器id
	OBJECT objMonitor = GetMonitor(strId);
	if(objMonitor != INVALID_VALUE)
    {
        MAPNODE motnitornode = GetMonitorMainAttribNode(objMonitor);
        if(motnitornode != INVALID_VALUE)
        {
			FindNodeValue(motnitornode, strPropName, strTmp);
		}

		CloseMonitor(objMonitor);
	}

	return strTmp;
}
Exemple #25
0
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;
}
Exemple #26
0
/*Function to print money owned by clerks*/
void printMoney() {
    int totalMoney = 0;
    int applicationMoney = 0;
    int pictureMoney = 0;
    int passportMoney = 0;
    int cashierMoney = 0;
    int i, tempMon;
    for(i = 0; i < clerkCount; ++i) {
        tempMon = GetMonitor(clerkMoney, i);
        if (i < clerkArray[0]) { /*ApplicationClerk index*/
            applicationMoney += tempMon;
        } else if (i < clerkArray[0] + clerkArray[1]) { /*PictureClerk index*/
            pictureMoney += tempMon;
        } else if (i < clerkArray[0] + clerkArray[1] + clerkArray[2]) { /*PassportClerk index*/
            passportMoney += tempMon;
        } else if (i < clerkArray[0] + clerkArray[1] + clerkArray[2] + clerkArray[3]) { /*Cashier index*/
            cashierMoney += tempMon;
        }
        totalMoney += tempMon;
    }
    applicationMoney = applicationMoney * 100;
    pictureMoney = pictureMoney * 100;
    passportMoney = passportMoney * 100;
    cashierMoney = cashierMoney * 100;
    totalMoney = totalMoney * 100;

    PrintString("Manager has counted a total of ", 31);
    PrintNum(applicationMoney);
    PrintString(" for ApplicationClerks\n", 23);
    PrintString("Manager has counted a total of ", 31);
    PrintNum(pictureMoney);
    PrintString(" for PictureClerks\n", 19);
    PrintString("Manager has counted a total of ", 31);
    PrintNum(passportMoney);
    PrintString(" for PassportClerks\n", 20);
    PrintString("Manager has counted a total of ", 31);
    PrintNum(cashierMoney);
    PrintString(" for Cashiers\n", 14);
    PrintString("Manager has counted a total of ", 31);
    PrintNum(totalMoney);
    PrintString(" for passport office\n", 21);
}
Exemple #27
0
void CSVSortList::saveMonitor(map<int, string, less<int> > &lsDis)
{
    map<int, string, less<int> >::iterator lsDisItem;
    for(lsDisItem = lsDis.begin(); lsDisItem != lsDis.end(); lsDisItem ++)
    {
        string szMonitorID = lsDisItem->second;
        OBJECT objMonitor = GetMonitor(szMonitorID,  m_szIDCUser, m_szIDCPwd);
        if(objMonitor != INVALID_VALUE)
        {
            char szIndex[8] = {0};
            sprintf(szIndex, "%d", lsDisItem->first);
            
            MAPNODE mainnode = GetMonitorMainAttribNode(objMonitor);
            if(mainnode != INVALID_VALUE)
                AddNodeAttrib(mainnode, "sv_index", szIndex);
            SubmitMonitor(objMonitor);
            CloseMonitor(objMonitor);           
        } 
    }
}
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;
}
Exemple #29
0
bool CWinSystemWin32::ChangeResolution(RESOLUTION_INFO res)
{
  const MONITOR_DETAILS &details = GetMonitor(res.iScreen);

  DEVMODE sDevMode;
  ZeroMemory(&sDevMode, sizeof(DEVMODE));
  sDevMode.dmSize = sizeof(DEVMODE);

  // If we can't read the current resolution or any detail of the resolution is different than res
  if (!EnumDisplaySettings(details.DeviceName, ENUM_CURRENT_SETTINGS, &sDevMode) ||
      sDevMode.dmPelsWidth != res.iWidth || sDevMode.dmPelsHeight != res.iHeight ||
      sDevMode.dmDisplayFrequency != (int)res.fRefreshRate ||
      ((sDevMode.dmDisplayFlags & DM_INTERLACED) && !(res.dwFlags & D3DPRESENTFLAG_INTERLACED)) ||
      (!(sDevMode.dmDisplayFlags & DM_INTERLACED) && (res.dwFlags & D3DPRESENTFLAG_INTERLACED)) )
  {
    ZeroMemory(&sDevMode, sizeof(DEVMODE));
    sDevMode.dmSize = sizeof(DEVMODE);
    sDevMode.dmDriverExtra = 0;
    sDevMode.dmPelsWidth = res.iWidth;
    sDevMode.dmPelsHeight = res.iHeight;
    sDevMode.dmDisplayFrequency = (int)res.fRefreshRate;
    sDevMode.dmDisplayFlags = (res.dwFlags & D3DPRESENTFLAG_INTERLACED) ? DM_INTERLACED : 0;
    sDevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS;

    // CDS_FULLSCREEN is for temporary fullscreen mode and prevents icons and windows from moving
    // to fit within the new dimensions of the desktop
    LONG rc = ChangeDisplaySettingsEx(details.DeviceName, &sDevMode, NULL, CDS_FULLSCREEN, NULL);
    if (rc != DISP_CHANGE_SUCCESSFUL)
    {
      CLog::Log(LOGERROR, "%s: error, code %d", __FUNCTION__, rc);
      return false;
    }
    else
    {
      return true;
    }
  }
  // nothing to do, return success
  return true;
}
Exemple #30
0
RECT CWinSystemWin32::ScreenRect(int screen)
{
    const MONITOR_DETAILS* details = GetMonitor(screen);

    if (!details)
    {
        CLog::LogFunction(LOGERROR, __FUNCTION__, "no monitor found for screen %i", screen);
    }

    DEVMODEW sDevMode;
    ZeroMemory(&sDevMode, sizeof(sDevMode));
    sDevMode.dmSize = sizeof(sDevMode);
    if(!EnumDisplaySettingsW(details->DeviceNameW.c_str(), ENUM_CURRENT_SETTINGS, &sDevMode))
        CLog::Log(LOGERROR, "%s : EnumDisplaySettings failed with %d", __FUNCTION__, GetLastError());

    RECT rc;
    rc.left = sDevMode.dmPosition.x;
    rc.right = sDevMode.dmPosition.x + sDevMode.dmPelsWidth;
    rc.top = sDevMode.dmPosition.y;
    rc.bottom = sDevMode.dmPosition.y + sDevMode.dmPelsHeight;

    return rc;
}