HRESULT CAAFInProcServer::CanUnloadNow( ) { // If there are any outstanding locks or active objects then we cannot // unload the server. if (0 < GetLockCount() || 0 < GetActiveObjectCount()) return S_FALSE; else return S_OK; }
void Button::Draw(double xOffset, double yOffset) { Color textColor; if (GetIsDisabled()) { textColor = DisabledTextColor; } else if (isMouseDown) { textColor = MouseDownTextColor; } else if (isMouseOver) { textColor = MouseOverTextColor; } else { textColor = NormalTextColor; } Vector2 textPosition = Vector2( GetXPosition() + animationOffset + xOffset, GetYPosition() + yOffset); pTextFont->Draw(GetText(), textPosition, textColor); if (pCustomIconSprite != NULL) { Vector2 spritePosition = Vector2( textPosition.GetX() - pCustomIconSprite->GetWidth() - 4, textPosition.GetY() - 4 + (36 - pCustomIconSprite->GetHeight()) / 2); pCustomIconSprite->Draw(spritePosition); } else if (GetLockCount() > 0 || GetUnlockedLockCount() > 0) { int lockPositionOffset = 0; for (int i = 0; i < GetLockCount(); i++) { lockPositionOffset += pLockSprite->GetWidth() + 2; Vector2 lockPosition = Vector2( textPosition.GetX() - lockPositionOffset, textPosition.GetY() - 9); pLockSprite->Draw(lockPosition); } for (int i = 0; i < GetUnlockedLockCount(); i++) { lockPositionOffset += pUnlockingAnimation->GetSize().GetX() + 2; Vector2 lockPosition = Vector2( textPosition.GetX() - lockPositionOffset, textPosition.GetY() - 9); pUnlockingAnimation->Draw(lockPosition); } } else if (GetShowCheckMark()) { Vector2 checkMarkPosition = Vector2( textPosition.GetX() - pCheckMarkImage->width, textPosition.GetY() - 4); pCheckMarkImage->Draw(checkMarkPosition); } }
void UScheduler::SwitchThread() { UnlockInner(GetLockCount()); }
void UScheduler::UnlockInner(U32 lockCount) { DebugAssertTrue(lockCount+1 == GetLockCount() || lockCount == GetLockCount()); do { /// /// If there are pending pisrs run them. /// if(InterruptController::ArePisrsPending()) InterruptController::RunPendingPisrs(); else { UThread& currentThread = GetRunningThread(); /// /// Check if this thread already consumed its time stamp. /// if so and there are no more threads to run, renew its timestamp and return. /// if(currentThread.GetThreadState() == UThread::READY) { if(!HasCurrentThreadTimestampPassed()) break; if(!HaveReadyThreads()) { RenewThread(currentThread); break; } if(!currentThread._node.IsInList()) { InsertThreadInReadyQueue(currentThread); } } /// /// Get the next thread from the scheduler. And a reference to the current. /// UThread& nextThread = Schedule(); DebugAssertNotEqualsP(UThread,¤tThread,&nextThread); /// /// Set the next thread as the running thread. /// _Scheduler._pRunningThread = &nextThread; DebugExec( if(!currentThread._node.IsInList()) DebugAssertTrue(currentThread.GetThreadState() != UThread::READY) ); /// /// Disable interrupts so that no interrupt occur during context switching, /// that way its impossible an interrupt service routine switchs threads /// without their contexts are properly saved. /// bool prevState = System::AcquireSystemLock(); /// /// Set scheduler lock count to 0 this thread isn't doing any critical operation on /// the scheduler instance. /// SetLockCount(0); /// /// Switch threads. /// _Scheduler.ContextSwitch(¤tThread,&nextThread); DebugAssertFalse(currentThread._node.IsInList()); DebugAssertEquals(0,GetLockCount()); DebugAssertEquals(¤tThread,(void*)_Scheduler._pRunningThread); SetLockCount(lockCount); /// /// Reenable interrupts, disabled before context switching. /// System::ReleaseSystemLock(prevState); return; } }while(true); /// /// Set the scheduler lock with the value before the switch happened. /// SetLockCount(lockCount); DebugAssertFalse(GetRunningThread()._node.IsInList()); }