コード例 #1
0
CTrafficLights::eTrafficLightState CTrafficLights::GetState()
{
	if(IsLocked())
		return m_eStateSet;

	if(m_eStateSet >= TRAFFIC_LIGHT_STATE_FLASHING_FLASHING)
		return m_eStateSet;

	if(m_uiTotalDuration == 0)
		return TRAFFIC_LIGHT_STATE_DISABLED_DISABLED;


	// Get the state based on the time elapsed in that cycle
	unsigned int uiTimePassed = GetTimeThisCylce();
	if(uiTimePassed < m_uiGreenDuration)
		return TRAFFIC_LIGHT_STATE_GREEN_RED;

	else if(uiTimePassed < m_uiGreenDuration + m_uiYellowDuration)
		return TRAFFIC_LIGHT_STATE_YELLOW_RED;
	
	else if(uiTimePassed < m_uiGreenDuration + m_uiYellowDuration + m_uiRedDuration)
		return TRAFFIC_LIGHT_STATE_RED_RED_1;
	
	else if(uiTimePassed < m_uiGreenDuration + 2 * m_uiYellowDuration + m_uiRedDuration)
		return TRAFFIC_LIGHT_STATE_RED_TO_GREEN;
	
	else if(uiTimePassed < 2 * m_uiGreenDuration + 2 * m_uiYellowDuration + m_uiRedDuration)
		return TRAFFIC_LIGHT_STATE_RED_GREEN;
	
	else if(uiTimePassed < 2 * m_uiGreenDuration + 3 * m_uiYellowDuration + m_uiRedDuration)
		return TRAFFIC_LIGHT_STATE_RED_YELLOW;
	
	else if(uiTimePassed < 2 * m_uiGreenDuration + 3 * m_uiYellowDuration + 2 * m_uiRedDuration)
		return TRAFFIC_LIGHT_STATE_RED_RED_2;

	else
		return TRAFFIC_LIGHT_STATE_TO_GREEN_RED;
}
コード例 #2
0
void CFrobLock::ToggleOpenTargets()
{
	if (IsLocked())
	{
		// We're still locked, play the locked sound and exit
		FrobLockStartSound("snd_locked");
	}
	else
	{
		// Actually open any targetted frobmovers
		for ( int i = 0 ; i < targets.Num() ; i++ )
		{
			idEntity* target = targets[i].GetEntity();

			if ( (target == NULL) || !target->IsType(CBinaryFrobMover::Type))
			{
				continue;
			}

			static_cast<CBinaryFrobMover*>(target)->ToggleOpen();
		}
	}
}
コード例 #3
0
ファイル: account.cpp プロジェクト: Gulden/gulden-official
bool CAccountHD::GetKey(const CKeyID& keyID, CKey& key) const
{
    if (IsLocked())
        return false;

    int64_t nKeyIndex = -1;
    CExtKey privKey;
    if (externalKeyStore.GetKey(keyID, nKeyIndex)) {
        primaryChainKeyPriv.Derive(privKey, nKeyIndex);
        if (privKey.Neuter().pubkey.GetID() != keyID)
            assert(0);
        key = privKey.key;
        return true;
    }
    if (internalKeyStore.GetKey(keyID, nKeyIndex)) {
        changeChainKeyPriv.Derive(privKey, nKeyIndex);
        if (privKey.Neuter().pubkey.GetID() != keyID)
            assert(0);
        key = privKey.key;
        return true;
    }
    return false;
}
コード例 #4
0
int32_t CFDE_TxtEdtEngine::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) {
  if (IsLocked()) {
    return 0;
  }
  ASSERT(nIndex >= 0 && nIndex <= GetTextBufLength());
  if (m_PagePtrArray.GetSize() <= m_nCaretPage) {
    return 0;
  }
  m_bBefore = bBefore;
  m_nCaret = nIndex;
  MovePage2Char(m_nCaret);
  GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore);
  if (!m_bBefore) {
    m_nCaret++;
    m_bBefore = TRUE;
  }
  m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical)
                           ? m_rtCaret.top
                           : m_rtCaret.left;
  m_Param.pEventSink->On_CaretChanged(this, m_nCaretPage, 0);
  m_nAnchorPos = -1;
  return m_nCaret;
}
コード例 #5
0
void
DecodedSurfaceProvider::SetLocked(bool aLocked)
{
  // See DrawableRef() for commentary on these assertions.
  if (Availability().IsPlaceholder()) {
    MOZ_ASSERT_UNREACHABLE("Calling SetLocked() on a placeholder");
    return;
  }

  if (!mSurface) {
    MOZ_ASSERT_UNREACHABLE("Calling SetLocked() when we have no surface");
    return;
  }

  if (aLocked == IsLocked()) {
    return;  // Nothing to do.
  }

  // If we're locked, hold a DrawableFrameRef to |mSurface|, which will keep any
  // volatile buffer it owns in memory.
  mLockRef = aLocked ? mSurface->DrawableRef()
                     : DrawableFrameRef();
}
コード例 #6
0
void FLevelViewModel::SelectActors( bool bSelect, bool bNotify, bool bSelectEvenIfHidden, const TSharedPtr< IFilter< const TWeakObjectPtr< AActor >& > >& Filter )
{
	if( !Level.IsValid() || IsLocked() )
	{
		return;
	}

	Editor->GetSelectedActors()->BeginBatchSelectOperation();
	bool bChangesOccurred = false;

	// Iterate over all actors, looking for actors in this level.
	ULevel* RawLevel = Level.Get();
	for ( int32 ActorIndex = 2 ; ActorIndex < RawLevel->Actors.Num() ; ++ActorIndex )
	{
		AActor* Actor = RawLevel->Actors[ ActorIndex ];
		if ( Actor )
		{
			if( Filter.IsValid() && !Filter->PassesFilter( Actor ) )
			{
				continue;
			}

			bool bNotifyForActor = false;
			Editor->GetSelectedActors()->Modify();
			Editor->SelectActor( Actor, bSelect, bNotifyForActor, bSelectEvenIfHidden );
			bChangesOccurred = true;
		}
	}

	Editor->GetSelectedActors()->EndBatchSelectOperation();

	if( bNotify )
	{
		Editor->NoteSelectionChange();
	}
}
コード例 #7
0
void FLevelViewModel::Save()
{
	if ( !IsLevel() )
	{
		return;
	}

	if ( !IsVisible() )
	{
		FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "UnableToSaveInvisibleLevels", "Save aborted.  Levels must be made visible before they can be saved.") );
		return;
	}
	else if ( IsLocked() )
	{
		FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "UnableToSaveLockedLevels", "Save aborted.  Level must be unlocked before it can be saved.") );
		return;
	}

	// Prompt the user to check out the level from source control before saving if it's currently under source control
	if ( FEditorFileUtils::PromptToCheckoutLevels( false, Level.Get() ) )
	{
		FEditorFileUtils::SaveLevel( Level.Get() );
	}
}
コード例 #8
0
ファイル: Locker.cpp プロジェクト: BackupTheBerlios/nemo
//------------------------------------------------------------------------------
void
BLocker::Unlock(void)
{
	// If the thread currently holds the lockdecrement
	if (IsLocked()) {
	
		// Decrement the number of outstanding locks this thread holds
		// on this BLocker.
		fRecursiveCount--;
		
		// If the recursive count is now at 0, that means the BLocker has
		// been released by the thread.
		if (fRecursiveCount == 0) {
		
			// The BLocker is no longer owned by any thread.
			fLockOwner = B_ERROR;
		
    		// Decrement the benaphore count and store the undecremented
    		// value in oldBenaphoreCount.
			//int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, -1);
			// TODO: use atomic_dec(&fBenaphoreCount) instead
			int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, -1);
			
			// If the oldBenaphoreCount is greater than 1, then there is
			// at lease one thread waiting for the lock in the case of a
			// benaphore.
   		    if (oldBenaphoreCount > 1) {
 				
 				// Since there are threads waiting for the lock, it must
 				// be released.  Note, the old benaphore count will always be
 				// greater than 1 for a semaphore so the release is always done.
    			release_sem(fSemaphoreID);
	    	}
	    }
    }		
}
コード例 #9
0
		Result Machine::Reset(const bool hard) throw()
		{
			if (!Is(ON) || IsLocked())
				return RESULT_ERR_NOT_READY;

			try
			{
				emulator.Reset( hard );
			}
			catch (Result result)
			{
				return result;
			}
			catch (const std::bad_alloc&)
			{
				return RESULT_ERR_OUT_OF_MEMORY;
			}
			catch (...)
			{
				return RESULT_ERR_GENERIC;
			}

			return RESULT_OK;
		}
コード例 #10
0
BOOL S3PDBSocketPool::ShowAllClientInfo()
{
	if (IsLocked())
		return FALSE;
	Lock();
	BOOL b = FALSE;
	GatewayIDMap::iterator i = m_clientIDs.begin();
	int n = 0;
	while (i != m_clientIDs.end())
	{
		KGatewayDataProcess* p = i->second;
		if (p)
		{
			in_addr add;
			add.s_addr = p->m_Address;
			gTrace("Client %d: %s(%s)", n, p->m_ServerName.c_str(), inet_ntoa(in_addr(add))); 
		}
		i++;
		n++;
	}
	b = TRUE;
	Unlock();
	return b;
}
コード例 #11
0
void FLevelModel::SetLocked(bool bLocked)
{
	if (LevelCollectionModel.IsReadOnly())
	{
		return;
	}
		
	ULevel* Level = GetLevelObject();

	if (Level == NULL)
	{
		return;
	}

	// Do nothing if attempting to set the level to the same locked state
	if (bLocked == IsLocked())
	{
		return;
	}

	// If locking the level, deselect all of its actors and BSP surfaces
	if (bLocked)
	{
		DeselectAllActors();
		DeselectAllSurfaces();

		// Tell the editor selection status was changed.
		Editor->NoteSelectionChange();

		// If locking the current level, reset the p-level as the current level
		//@todo: fix this!
	}

	// Change the level's locked status
	FLevelUtils::ToggleLevelLock(Level);
}
コード例 #12
0
 /// \brief
 ///   Flag that determines whether the resource can currently unload itself. Used by the resource manager.
 inline BOOL CanUnload() const         {return IsResourceFlagSet(VRESOURCEFLAG_ALLOWUNLOAD) && !IsLocked();}
コード例 #13
0
ファイル: BlockFile.cpp プロジェクト: ruthmagnus/audacity
BlockFile::~BlockFile()
{
   if (!IsLocked() && mFileName.HasName())
      wxRemoveFile(mFileName.GetFullPath());
}
コード例 #14
0
HRESULT CHWMFT::GetOutputCurrentType(
    DWORD           dwOutputStreamID,
    IMFMediaType**  ppType)
{
    /*****************************************
    ** See http://msdn.microsoft.com/en-us/library/ms696985(v=VS.85).aspx
    *****************************************/

    HRESULT         hr      = S_OK;
    IMFMediaType*   pMT     = NULL;

    do
    {
        /************************************
        ** Since this MFT is a decoder, it
        ** must not allow this function to be
        ** called until it is unlocked. If
        ** your MFT is an encoder, this function
        ** CAN be called before the MFT is
        ** unlocked
        ************************************/
        if(IsLocked() != FALSE)
        {
            hr = MF_E_TRANSFORM_ASYNC_LOCKED;
            break;
        }

        if(ppType == NULL)
        {
            hr = E_POINTER;
            break;
        }

        /*****************************************
        ** Todo: If your MFT supports more than one
        ** stream, make sure you modify
        ** MFT_MAX_STREAMS and adjust this function
        ** accordingly
        *****************************************/
        if(dwOutputStreamID >= MFT_MAX_STREAMS)
        {
            hr = MF_E_INVALIDSTREAMNUMBER;
            break;
        }

        {
            CAutoLock lock(&m_csLock);

            if(m_pOutputMT == NULL)
            {
                hr = MF_E_TRANSFORM_TYPE_NOT_SET;
                break;
            }

            /*******************************************
            ** Return a copy of the media type, not the 
            ** internal one. Returning the internal one 
            ** will allow an external component to modify
            ** the internal media type
            *******************************************/

            hr = MFCreateMediaType(&pMT);
            if(FAILED(hr))
            {
                break;
            }

            hr = DuplicateAttributes(pMT, m_pOutputMT);
            if(FAILED(hr))
            {
                break;
            }
        }

        (*ppType) = pMT;
        (*ppType)->AddRef();
    }while(false);

    SAFERELEASE(pMT);

    return hr;
}
コード例 #15
0
void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
{
    int      nbpad;
    wxString msg;

    aList.push_back( MSG_PANEL_ITEM( m_Reference->GetShownText(), m_Value->GetShownText(), DARKCYAN ) );

    // Display last date the component was edited (useful in Module Editor).
    wxDateTime date( m_LastEditTime );

    if( m_LastEditTime && date.IsValid() )
    // Date format: see http://www.cplusplus.com/reference/ctime/strftime
        msg = date.Format( wxT( "%b %d, %Y" ) ); // Abbreviated_month_name Day, Year
    else
        msg = _( "Unknown" );

    aList.push_back( MSG_PANEL_ITEM( _( "Last Change" ), msg, BROWN ) );

    // display schematic path
    aList.push_back( MSG_PANEL_ITEM( _( "Netlist Path" ), m_Path, BROWN ) );

    // display the board side placement
    aList.push_back( MSG_PANEL_ITEM( _( "Board Side" ),
                     IsFlipped()? _( "Back (Flipped)" ) : _( "Front" ), RED ) );

    EDA_ITEM* PtStruct = m_Pads;
    nbpad = 0;

    while( PtStruct )
    {
        nbpad++;
        PtStruct = PtStruct->Next();
    }

    msg.Printf( wxT( "%d" ), nbpad );
    aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), msg, BLUE ) );

    msg = wxT( ".." );

    if( IsLocked() )
        msg[0] = 'L';

    if( m_ModuleStatus & MODULE_is_PLACED )
        msg[1] = 'P';

    aList.push_back( MSG_PANEL_ITEM( _( "Status" ), msg, MAGENTA ) );

    msg.Printf( wxT( "%.1f" ), GetOrientationDegrees() );
    aList.push_back( MSG_PANEL_ITEM( _( "Rotation" ), msg, BROWN ) );

    // Controls on right side of the dialog
    switch( m_Attributs & 255 )
    {
    case 0:
        msg = _( "Normal" );
        break;

    case MOD_CMS:
        msg = _( "Insert" );
        break;

    case MOD_VIRTUAL:
        msg = _( "Virtual" );
        break;

    default:
        msg = wxT( "???" );
        break;
    }

    aList.push_back( MSG_PANEL_ITEM( _( "Attributes" ), msg, BROWN ) );
    aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), FROM_UTF8( m_fpid.Format().c_str() ), BLUE ) );

    if( m_3D_Drawings.empty() )
        msg = _( "No 3D shape" );
    else
        msg = m_3D_Drawings.front().m_Filename;

    // Search the first active 3D shape in list

    aList.push_back( MSG_PANEL_ITEM( _( "3D-Shape" ), msg, RED ) );

    wxString doc, keyword;
    doc.Printf( _( "Doc: %s" ), GetChars( m_Doc ) );
    keyword.Printf( _( "Key Words: %s" ), GetChars( m_KeyWord ) );
    aList.push_back( MSG_PANEL_ITEM( doc, keyword, BLACK ) );
}
コード例 #16
0
void UScheduler::Timer::SetTimeout(U32 timeout)
{
	DebugAssertTrue(IsLocked());
	_timeoutTime = System::GetTickCount() + timeout;
	AddOperationWithTimeout(_node);
}
コード例 #17
0
HRESULT CHWMFT::ProcessOutput(
    DWORD                   dwFlags,
    DWORD                   dwOutputBufferCount,
    MFT_OUTPUT_DATA_BUFFER* pOutputSamples,
    DWORD*                  pdwStatus)
{
    /*****************************************
    ** See http://msdn.microsoft.com/en-us/library/ms704014(v=VS.85).aspx
    *****************************************/

    HRESULT     hr      = S_OK;
    IMFSample*  pSample = NULL;

    TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): Enter",  __FUNCTION__);

    do
    {
        if(IsLocked() != FALSE)
        {
            hr = MF_E_TRANSFORM_ASYNC_LOCKED;
            break;
        }

        {
            CAutoLock lock(&m_csLock);

            TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): HaveOutputCount: %u",  __FUNCTION__, m_dwHaveOutputCount);

            if(m_dwHaveOutputCount == 0)
            {
                // This call does not correspond to a have output call

                hr = E_UNEXPECTED;
                break;
            }
            else
            {
                m_dwHaveOutputCount--;
            }
        }

        /*****************************************
        ** Todo: If your MFT supports more than one
        ** stream, make sure you modify
        ** MFT_MAX_STREAMS and adjust this function
        ** accordingly
        *****************************************/
        if(dwOutputBufferCount < MFT_MAX_STREAMS)
        {
            hr = E_INVALIDARG;
            break;
        }

        if(IsMFTReady() == FALSE)
        {
            hr = MF_E_TRANSFORM_TYPE_NOT_SET;
            break;
        }

        /***************************************
        ** Since this in an internal function
        ** we know m_pOutputSampleQueue can never be
        ** NULL due to InitializeTransform()
        ***************************************/
        hr = m_pOutputSampleQueue->GetNextSample(&pSample);
        if(FAILED(hr))
        {
            break;
        }

        if(pSample == NULL)
        {
            hr = MF_E_TRANSFORM_NEED_MORE_INPUT;
            break;
        }

        /*******************************
        ** Todo: This MFT only has one
        ** input stream, so the output
        ** samples array and stream ID
        ** will only use the first
        ** member
        *******************************/
        pOutputSamples[0].dwStreamID    = 0;
        
        if((pOutputSamples[0].pSample) == NULL)
        {
            // The MFT is providing it's own samples
            (pOutputSamples[0].pSample)   = pSample;
            (pOutputSamples[0].pSample)->AddRef();
        }
        else
        {
            // The pipeline has allocated the samples
            IMFMediaBuffer* pBuffer = NULL;

            do
            {
                hr = pSample->ConvertToContiguousBuffer(&pBuffer);
                if(FAILED(hr))
                {
                    break;
                }

                hr = (pOutputSamples[0].pSample)->AddBuffer(pBuffer);
                if(FAILED(hr))
                {
                    break;
                }
            }while(false);

            SAFERELEASE(pBuffer);

            if(FAILED(hr))
            {
                break;
            }
        }

        /***************************************
        ** Since this in an internal function
        ** we know m_pOutputSampleQueue can never be
        ** NULL due to InitializeTransform()
        ***************************************/
        if(m_pOutputSampleQueue->IsQueueEmpty() != FALSE)
        {
            // We're out of samples in the output queue
            CAutoLock lock(&m_csLock);

            if((m_dwStatus & MYMFT_STATUS_DRAINING) != 0)
            {
                // We're done draining, time to send the event
                IMFMediaEvent*  pDrainCompleteEvent  = NULL;

                do
                {
                    hr = MFCreateMediaEvent(METransformDrainComplete , GUID_NULL, S_OK, NULL, &pDrainCompleteEvent);
                    if(FAILED(hr))
                    {
                        break;
                    }

                    /*******************************
                    ** Todo: This MFT only has one
                    ** input stream, so the drain
                    ** is always on stream zero.
                    ** Update this is your MFT
                    ** has more than one stream
                    *******************************/
                    hr = pDrainCompleteEvent->SetUINT32(MF_EVENT_MFT_INPUT_STREAM_ID, 0);
                    if(FAILED(hr))
                    {
                        break;
                    }

                    /***************************************
                    ** Since this in an internal function
                    ** we know m_pEventQueue can never be
                    ** NULL due to InitializeTransform()
                    ***************************************/
                    hr = m_pEventQueue->QueueEvent(pDrainCompleteEvent);
                    if(FAILED(hr))
                    {
                        break;
                    }
                }while(false);

                SAFERELEASE(pDrainCompleteEvent);

                if(FAILED(hr))
                {
                    break;
                }

                m_dwStatus &= (~MYMFT_STATUS_DRAINING);
            }
        }
    }while(false);

    SAFERELEASE(pSample);

    TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): Exit (hr=0x%x)",  __FUNCTION__, hr);

    return hr;
}
コード例 #18
0
BOOL CGatewayEpos2ToMaxonSerialV1::Process_SegmentWrite(CCommand_DCS* pCommand, CProtocolStackManagerBase* pProtocolStackManager, HANDLE hPS_Handle, HANDLE hTransactionHandle)
{
    const BYTE MAX_SEGMENT_LENGTH = 63;

    //*Constants DCS*
    const int PARAMETER_INDEX_NODE_ID = 0;
    const int PARAMETER_INDEX_CONTROL_BYTE = 1;
    const int PARAMETER_INDEX_DATA = 2;
    const int RETURN_PARAMETER_INDEX_ERROR_CODE = 0;
    const int RETURN_PARAMETER_INDEX_CONTROL_BYTE = 1;

    //*Constants PS*
    const BYTE OP_CODE = 0x15;
    const BYTE DATA_LENGTH = 1;
    const BYTE RETURN_DATA_LENGTH = 6;

    //*Variables DCS*
    //Parameter
    BYTE uNodeId = 0;
    UEpos2ControlByte controlByte;
    controlByte.bValue = 0;
    void* pData = NULL;
    //Return Parameter
    UEpos2ControlByte retControlByte;
    retControlByte.bValue = 0;
    DWORD dDeviceErrorCode = 0;

    //*Variables PS*
    //Parameter
    BYTE uOpCode = OP_CODE;
    void* pDataBuffer=NULL;
    DWORD dDataBufferLength;
	BYTE ubKeepLock(1);

    //ReturnParameter
    void* pRetDataBuffer=NULL;
    DWORD dRetDataBufferLength = 0;

    BOOL oResult = FALSE;
    CErrorInfo comErrorInfo;
    CErrorInfo cmdErrorInfo;

    void* pDest;
    void* pSource;

    if(pCommand)
    {
        //Check CriticalSection
		if(!IsLocked(pCommand)) return FALSE;

		//GetParameterData
        pCommand->GetParameterData(PARAMETER_INDEX_NODE_ID, &uNodeId, sizeof(uNodeId));
        pCommand->GetParameterData(PARAMETER_INDEX_CONTROL_BYTE, &controlByte.bValue, sizeof(controlByte.bValue));

        //Check Max SegmentLength
        if(controlByte.structure.bLength > MAX_SEGMENT_LENGTH) controlByte.structure.bLength = MAX_SEGMENT_LENGTH;
        pData = malloc(controlByte.structure.bLength);
        pCommand->GetParameterData(PARAMETER_INDEX_DATA, pData, controlByte.structure.bLength);

        //Prepare DataBuffer
        dDataBufferLength = DATA_LENGTH + controlByte.structure.bLength;
        pDataBuffer = malloc(dDataBufferLength);

        //Data
        pDest = pDataBuffer;
        CopyData(pDest, &controlByte.bValue, sizeof(controlByte.bValue));
        CopyData(pDest, pData, controlByte.structure.bLength);

        //Execute Command
        oResult = PS_ProcessProtocol(pProtocolStackManager, hPS_Handle, hTransactionHandle, uOpCode, pDataBuffer, dDataBufferLength, ubKeepLock, &pRetDataBuffer, &dRetDataBufferLength, &comErrorInfo);

        //Check ReturnData Size
        if(oResult && (dRetDataBufferLength != RETURN_DATA_LENGTH))
        {
            if(m_pErrorHandling) m_pErrorHandling->GetError(k_Error_MaxonSerialV1_BadDataSizeReceived, &comErrorInfo);
            oResult = FALSE;
        }

        //ReturnData
        pSource = pRetDataBuffer;
        if(oResult) oResult = CopyReturnData(&dDeviceErrorCode, sizeof(dDeviceErrorCode), pSource, dRetDataBufferLength);
        if(oResult) oResult = CopyReturnData(&retControlByte.bValue, sizeof(retControlByte.bValue), pSource, dRetDataBufferLength);

        //Evaluate ErrorCode
        oResult = EvaluateErrorCode(oResult, dDeviceErrorCode, &comErrorInfo, &cmdErrorInfo);

        //Restore controlByte
        if(oResult && (controlByte.structure.bToggle != retControlByte.structure.bToggle))
        {
            if(m_pErrorHandling) m_pErrorHandling->GetError(ERROR_DEVICE_EPOS_TOGGLE, &cmdErrorInfo);
            oResult = FALSE;
        }

        //SetReturnParameterData
        pCommand->SetStatus(oResult, &cmdErrorInfo);
        pCommand->SetReturnParameterData(RETURN_PARAMETER_INDEX_ERROR_CODE, &dDeviceErrorCode, sizeof(dDeviceErrorCode));
        pCommand->SetReturnParameterData(RETURN_PARAMETER_INDEX_CONTROL_BYTE, &retControlByte, sizeof(retControlByte));

        //Free DataBuffer
        if(pData) free(pData);
        if(pDataBuffer) free(pDataBuffer);
        if(pRetDataBuffer) free(pRetDataBuffer);

		//Unlock CriticalSection
		if(!controlByte.structure.bMoreSegments || !oResult)
		{
			PS_AbortProtocol(pProtocolStackManager, hPS_Handle, hTransactionHandle);
			Unlock();
		}
    }

    return oResult;
}
コード例 #19
0
HRESULT CHWMFT::ProcessInput(
    DWORD       dwInputStreamID,
    IMFSample*  pSample,
    DWORD       dwFlags)
{
    /*****************************************
    ** See http://msdn.microsoft.com/en-us/library/ms703131(v=VS.85).aspx
    *****************************************/

    HRESULT hr = S_OK;

    TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): Enter",  __FUNCTION__);

    do
    {
        if(IsLocked() != FALSE)
        {
            hr = MF_E_TRANSFORM_ASYNC_LOCKED;
            break;
        }

        {
            CAutoLock lock(&m_csLock);

            TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): NeedInputCount: %u",  __FUNCTION__, m_dwNeedInputCount);

            if(m_dwNeedInputCount == 0)
            {
                // This call does not correspond to a need input call
                hr = MF_E_NOTACCEPTING;
                break;
            }
            else
            {
                m_dwNeedInputCount--;
            }
        }

        if(pSample == NULL)
        {
            hr = E_POINTER;
            break;
        }

        /*****************************************
        ** Todo: If your MFT supports more than one
        ** stream, make sure you modify
        ** MFT_MAX_STREAMS and adjust this function
        ** accordingly
        *****************************************/
        if(dwInputStreamID >= MFT_MAX_STREAMS)
        {
            hr = MF_E_INVALIDSTREAMNUMBER;
            break;
        }

        // First, put sample into the input Queue

        /***************************************
        ** Since this in an internal function
        ** we know m_pInputSampleQueue can never be
        ** NULL due to InitializeTransform()
        ***************************************/
        hr = m_pInputSampleQueue->AddSample(pSample);
        if(FAILED(hr))
        {
            break;
        }

        // Now schedule the work to decode the sample
        hr = ScheduleFrameDecode();
        if(FAILED(hr))
        {
            break;
        }
    }while(false);

    TraceString(CHMFTTracing::TRACE_INFORMATION, L"%S(): Exit (hr=0x%x)",  __FUNCTION__, hr);

    return hr;
}
コード例 #20
0
void b2World::DestroyJoint(b2Joint* j)
{
	b2Assert(IsLocked() == false);
	if (IsLocked())
	{
		return;
	}

	bool collideConnected = j->m_collideConnected;

	// Remove from the doubly linked list.
	if (j->m_prev)
	{
		j->m_prev->m_next = j->m_next;
	}

	if (j->m_next)
	{
		j->m_next->m_prev = j->m_prev;
	}

	if (j == m_jointList)
	{
		m_jointList = j->m_next;
	}

	// Disconnect from island graph.
	b2Body* bodyA = j->m_bodyA;
	b2Body* bodyB = j->m_bodyB;

	// Wake up connected bodies.
	bodyA->SetAwake(true);
	bodyB->SetAwake(true);

	// Remove from body 1.
	if (j->m_edgeA.prev)
	{
		j->m_edgeA.prev->next = j->m_edgeA.next;
	}

	if (j->m_edgeA.next)
	{
		j->m_edgeA.next->prev = j->m_edgeA.prev;
	}

	if (&j->m_edgeA == bodyA->m_jointList)
	{
		bodyA->m_jointList = j->m_edgeA.next;
	}

	j->m_edgeA.prev = NULL;
	j->m_edgeA.next = NULL;

	// Remove from body 2
	if (j->m_edgeB.prev)
	{
		j->m_edgeB.prev->next = j->m_edgeB.next;
	}

	if (j->m_edgeB.next)
	{
		j->m_edgeB.next->prev = j->m_edgeB.prev;
	}

	if (&j->m_edgeB == bodyB->m_jointList)
	{
		bodyB->m_jointList = j->m_edgeB.next;
	}

	j->m_edgeB.prev = NULL;
	j->m_edgeB.next = NULL;

	b2Joint::Destroy(j, &m_blockAllocator);

	b2Assert(m_jointCount > 0);
	--m_jointCount;

	// If the joint prevents collisions, then flag any contacts for filtering.
	if (collideConnected == false)
	{
		b2ContactEdge* edge = bodyB->GetContactList();
		while (edge)
		{
			if (edge->other == bodyA)
			{
				// Flag the contact for filtering at the next time step (where either
				// body is awake).
				edge->contact->FlagForFiltering();
			}

			edge = edge->next;
		}
	}
}
コード例 #21
0
status_t ObservableLooper::notify(
    BMessage*								message) {
    ASSERT(IsLocked());

    return Invoke(message);
}
コード例 #22
0
BOOL CGatewayInfoteamSerialToI::Process_ProcessProtocolMaxon(CCommand_PS* pCommand,CInterfaceManagerBase* pInterfaceManager,HANDLE hI_Handle,HANDLE hTransactionHandle)
{
	const DWORD k_MaxPackageSize_Maxon = 256;
	
	//*Constants PS*
	const int k_ParameterIndex_PackageSize = 0;
	const int k_ParameterIndex_ChunkSize = 1;
	const int k_ParameterIndex_LastChunkFlag = 2;
	const int k_ParameterIndex_Checksum = 3;
	const int k_ParameterIndex_PackageType = 4;
	const int k_ParameterIndex_OpCode = 5;
	const int k_ParameterIndex_Data = 6;
	const int k_ParameterIndex_KeepLock = 7;

	const int k_ReturnParameterIndex_PackageSize = 0;
	const int k_ReturnParameterIndex_Checksum = 1;
	const int k_ReturnParameterIndex_PackageType = 2;
	const int k_ReturnParameterIndex_Data = 3;

	//*Variables PS*
	//Parameter
	DWORD dPackageSize;
	WORD wChunkSize;
	BYTE uLastChunkFlag;
	DWORD dChecksum;
	BYTE uPackageType = 0;
	BYTE uOpCode = 0;
	void* pDataBuffer = NULL;
	DWORD dDataBufferLength;
	BYTE ubKeepLock = 0;

	BYTE* p = NULL;
	DWORD dSize;

	//ReturnParameter
	DWORD dRetPackageSize;
	DWORD dRetChecksum;
	BYTE uRetPackageType = 0;
	void* pRetDataBuffer = NULL;
	DWORD dRetDataBufferLength = 0;

	BOOL oResult = FALSE;
	CErrorInfo errorInfo;
	DWORD dTimeout;

	if(pCommand && pInterfaceManager)
	{
		//Lock CriticalSection
		if(!IsLocked(pCommand))
		{
			if(!Lock(pCommand)) return FALSE;
		}

		//Prepare DataBuffer
		dDataBufferLength = pCommand->GetParameterLength(k_ParameterIndex_Data) + sizeof(uPackageType) + sizeof(uOpCode);
		if(dDataBufferLength > 0) pDataBuffer = malloc(dDataBufferLength);

		//Get PS Parameter Data
		pCommand->GetParameterData(k_ParameterIndex_PackageSize,&dPackageSize,sizeof(dPackageSize));
		pCommand->GetParameterData(k_ParameterIndex_ChunkSize,&wChunkSize,sizeof(wChunkSize));
		pCommand->GetParameterData(k_ParameterIndex_LastChunkFlag,&uLastChunkFlag,sizeof(uLastChunkFlag));
		pCommand->GetParameterData(k_ParameterIndex_Checksum,&dChecksum,sizeof(dChecksum));
		pCommand->GetParameterData(k_ParameterIndex_KeepLock,&ubKeepLock,sizeof(ubKeepLock));

		p = (BYTE*)pDataBuffer;
		pCommand->GetParameterData(k_ParameterIndex_PackageType,p,sizeof(uPackageType));p+=sizeof(uPackageType);
		pCommand->GetParameterData(k_ParameterIndex_OpCode,p,sizeof(uOpCode));p+=sizeof(uOpCode);
		pCommand->GetParameterData(k_ParameterIndex_Data,p,pCommand->GetParameterLength(k_ParameterIndex_Data));

		//Execute Command
		dTimeout = pCommand->GetTimeout();
		oResult = SendFrameRepeated(pInterfaceManager,hI_Handle,hTransactionHandle,dPackageSize,wChunkSize,uLastChunkFlag,&dChecksum,pDataBuffer,dDataBufferLength,&errorInfo);
		if(oResult)
		{
			oResult = ReceiveFrameRepeated(pInterfaceManager,hI_Handle,hTransactionHandle, k_MaxPackageSize_Maxon, &dRetPackageSize,&dRetChecksum,&pRetDataBuffer,&dRetDataBufferLength,dTimeout,&errorInfo);
		}

		//Set PS ReturnParameter Data
		pCommand->SetStatus(oResult,&errorInfo);
		pCommand->SetParameterData(k_ParameterIndex_Checksum,&dChecksum,sizeof(dChecksum));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_PackageSize,&dRetPackageSize,sizeof(dRetPackageSize));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Checksum,&dRetChecksum,sizeof(dRetChecksum));

		if(dRetDataBufferLength > 0)
		{
			p = (BYTE*)pRetDataBuffer;
			dSize = dRetDataBufferLength;
			pCommand->SetReturnParameterData(k_ReturnParameterIndex_PackageType,p,sizeof(uRetPackageType)); p+=sizeof(uPackageType); dSize -= sizeof(uPackageType);
			pCommand->SetReturnParameterData(k_ReturnParameterIndex_Data,p,dSize);
		}

		//Free DataBuffer
		if(pDataBuffer) free(pDataBuffer);
		if(pRetDataBuffer) free(pRetDataBuffer);

		//Unlock CriticalSection
		if(!ubKeepLock) Unlock();
	}

	return oResult;
}
コード例 #23
0
ファイル: matrix.cpp プロジェクト: khalid-hasanov/Elemental
bool
Matrix<T>::Locked() const
{ return IsLocked( viewType_ ); }
コード例 #24
0
HRESULT CHWMFT::GetInputAvailableType(
    DWORD           dwInputStreamID,
    DWORD           dwTypeIndex,
    IMFMediaType**  ppType)
{
    /*****************************************
    ** Todo: This function will return a media
    ** type at a given index. The SDK 
    ** implementation uses a static array of
    ** media types. Your MFT may want to use
    ** a dynamic array and modify the list 
    ** order depending on the MFTs state
    ** See http://msdn.microsoft.com/en-us/library/ms704814(v=VS.85).aspx
    *****************************************/

    HRESULT         hr      = S_OK;
    IMFMediaType*   pMT     = NULL;

    do
    {
        if(IsLocked() != FALSE)
        {
            hr = MF_E_TRANSFORM_ASYNC_LOCKED;
            break;
        }

        if(ppType == NULL)
        {
            hr = E_POINTER;
            break;
        }

        /*****************************************
        ** Todo: If your MFT supports more than one
        ** stream, make sure you modify
        ** MFT_MAX_STREAMS and adjust this function
        ** accordingly
        *****************************************/
        if(dwInputStreamID >= MFT_MAX_STREAMS)
        {
            hr = MF_E_INVALIDSTREAMNUMBER;
            break;
        }

        /*****************************************
        ** Todo: Modify the accepted input list
        ** g_ppguidInputTypes or use your own
        ** implementation of this function
        *****************************************/
        if(dwTypeIndex >= g_dwNumInputTypes)
        {
            hr = MF_E_NO_MORE_TYPES;
            break;
        }

        {
            CAutoLock lock(&m_csLock);

            hr = MFCreateMediaType(&pMT);
            if(FAILED(hr))
            {
                break;
            }

            hr = pMT->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
            if(FAILED(hr))
            {
                break;
            }

            hr = pMT->SetGUID(MF_MT_SUBTYPE, *(g_ppguidInputTypes[dwTypeIndex]));
            if(FAILED(hr))
            {
                break;
            }

            (*ppType) = pMT;
            (*ppType)->AddRef();
        }
    }while(false);

    SAFERELEASE(pMT);

    return hr;
}
コード例 #25
0
bool FLevelModel::IsEditable() const
{
	return (IsLoaded() == true && IsLocked() == false);
}
コード例 #26
0
ファイル: XAudio2Effects.cpp プロジェクト: xiangyuan/Unreal4
	/**
	 * Adds a radio distortion to the input buffer if the radio effect is enabled. 
	 *
	 * @param	InputProcessParameterCount	Number of elements in pInputProcessParameters.
	 * @param	pInputProcessParameters		Input buffer containing audio samples. 
	 * @param	OutputProcessParameterCount	Number of elements in pOutputProcessParameters. 
	 * @param	pOutputProcessParameters	Output buffer, which is not touched by this xAPO. 
	 * @param	IsEnabled					true if this effect is enabled; false, otherwise. 
	 */
	STDMETHOD_( void, Process )(	UINT32 InputProcessParameterCount,
									const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters,
									UINT32 OutputProcessParameterCount,
									XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters,
									BOOL IsEnabled )
	{
		// Verify several condition based on the registration 
		// properties we used to create the class. 
		check( IsLocked() );
		check( InputProcessParameterCount == 1 );
		check( OutputProcessParameterCount == 1 );
		check( pInputProcessParameters[0].pBuffer == pOutputProcessParameters[0].pBuffer );

		// Check the global volume multiplier because this effect 
		// will continue to play if the editor loses focus.
		if (IsEnabled && FApp::GetVolumeMultiplier() != 0.0f)
		{
			FAudioRadioEffect* RadioParameters = ( FAudioRadioEffect* )BeginProcess();
			check( RadioParameters );

			// The total sample size must account for multiple channels. 
			const uint32 SampleSize = pInputProcessParameters[0].ValidFrameCount * WaveFormat.nChannels;

			const float ChebyshevPowerMultiplier = Radio_ChebyshevPowerMultiplier->GetValueOnAnyThread();
			const float ChebyshevPower = Radio_ChebyshevPower->GetValueOnAnyThread();
			const float ChebyshevCubedMultiplier = Radio_ChebyshevCubedMultiplier->GetValueOnAnyThread();
			const float ChebyshevMultiplier = Radio_ChebyshevMultiplier->GetValueOnAnyThread();

			// If we have a silent buffer, then allocate the samples. Then, set the sample values 
			// to zero to avoid getting NANs. Otherwise, the user may hear an annoying popping noise.
			if( pInputProcessParameters[0].BufferFlags == XAPO_BUFFER_VALID )
			{
				float* SampleData = ( float* )pInputProcessParameters[0].pBuffer;

				// Process each sample one at a time
				for( uint32 SampleIndex = 0; SampleIndex < SampleSize; ++SampleIndex )
				{
					float Sample = SampleData[SampleIndex];

					// Early-out of processing if the sample is zero because a zero sample 
					// will still create some static even if no audio is playing.
					if( Sample == 0.0f )
					{
						continue;
					}

					// Waveshape it
					const float SampleCubed = Sample * Sample * Sample;
					Sample = ( ChebyshevPowerMultiplier * FMath::Pow( Sample, ChebyshevPower ) ) - ( ChebyshevCubedMultiplier * SampleCubed ) + ( ChebyshevMultiplier * Sample );

					// Again with the bandpass
					Sample = GFinalBandPassFilter.Process( Sample );

					// Store the value after done processing
					SampleData[SampleIndex] = Sample;
				}

				EndProcess();
			}
		}
	}
コード例 #27
0
void b2World::DestroyBody(b2Body* b)
{
	b2Assert(m_bodyCount > 0);
	b2Assert(IsLocked() == false);
	if (IsLocked())
	{
		return;
	}

	// Delete the attached joints.
	b2JointEdge* je = b->m_jointList;
	while (je)
	{
		b2JointEdge* je0 = je;
		je = je->next;

		if (m_destructionListener)
		{
			m_destructionListener->SayGoodbye(je0->joint);
		}

		DestroyJoint(je0->joint);

		b->m_jointList = je;
	}
	b->m_jointList = NULL;

	// Delete the attached contacts.
	b2ContactEdge* ce = b->m_contactList;
	while (ce)
	{
		b2ContactEdge* ce0 = ce;
		ce = ce->next;
		m_contactManager.Destroy(ce0->contact);
	}
	b->m_contactList = NULL;

	// Delete the attached fixtures. This destroys broad-phase proxies.
	b2Fixture* f = b->m_fixtureList;
	while (f)
	{
		b2Fixture* f0 = f;
		f = f->m_next;

		if (m_destructionListener)
		{
			m_destructionListener->SayGoodbye(f0);
		}

		f0->DestroyProxies(&m_contactManager.m_broadPhase);
		f0->Destroy(&m_blockAllocator);
		f0->~b2Fixture();
		m_blockAllocator.Free(f0, sizeof(b2Fixture));

		b->m_fixtureList = f;
		b->m_fixtureCount -= 1;
	}
	b->m_fixtureList = NULL;
	b->m_fixtureCount = 0;

	// Remove world body list.
	if (b->m_prev)
	{
		b->m_prev->m_next = b->m_next;
	}

	if (b->m_next)
	{
		b->m_next->m_prev = b->m_prev;
	}

	if (b == m_bodyList)
	{
		m_bodyList = b->m_next;
	}

	--m_bodyCount;
	b->~b2Body();
	m_blockAllocator.Free(b, sizeof(b2Body));
}
コード例 #28
0
HRESULT CHWMFT::ProcessMessage(
    MFT_MESSAGE_TYPE eMessage,
    ULONG_PTR ulParam)
{
    /*****************************************
    ** See http://msdn.microsoft.com/en-us/library/ms701863(v=VS.85).aspx
    *****************************************/

    HRESULT hr = S_OK;

    do
    {
        if(IsLocked() != FALSE)
        {
            hr = MF_E_TRANSFORM_ASYNC_LOCKED;
            break;
        }

        if((m_pInputMT == NULL) || (m_pOutputMT == NULL))
        {
            // Can't process messages until media types are set
            hr = MF_E_TRANSFORM_TYPE_NOT_SET;
            break;
        }

        switch(eMessage)
        {
        case MFT_MESSAGE_NOTIFY_START_OF_STREAM:
            {
                hr = OnStartOfStream();
                if(FAILED(hr))
                {
                    break;
                }
            }
            break;
        case MFT_MESSAGE_NOTIFY_END_OF_STREAM:
            {
                hr = OnEndOfStream();
                if(FAILED(hr))
                {
                    break;
                }
            }
            break;
        case MFT_MESSAGE_COMMAND_DRAIN:
            {
                hr = OnDrain((UINT32)ulParam);
                if(FAILED(hr))
                {
                    break;
                }
            }
            break;
        case MFT_MESSAGE_COMMAND_FLUSH:
            {
                hr = OnFlush();
                if(FAILED(hr))
                {
                    break;
                }
            }
            break;
        case MFT_MESSAGE_COMMAND_MARKER:
            {
                hr = OnMarker(ulParam);
                if(FAILED(hr))
                {
                    break;
                }
            }
            break;
        /************************************************
        ** Todo: Add any MFT Messages that are not already
        ** covered
        ************************************************/
        default:
            // Nothing to do, return S_OK
            break;
        };
    }while(false);

    return hr;
}
コード例 #29
0
/// unlocks the blockfile only if it has a file that exists.  This needs to be done
/// so that the unsaved ODPCMAliasBlockfiles are deleted upon exit 
void ODPCMAliasBlockFile::Unlock()
{
   if(IsSummaryAvailable() && IsLocked())
      PCMAliasBlockFile::Unlock();
}
コード例 #30
0
ファイル: Locker.cpp プロジェクト: BackupTheBerlios/nemo
//------------------------------------------------------------------------------
bool
BLocker::AcquireLock(bigtime_t timeout,
               status_t *error)
{
	// By default, return no error.
    *error = B_OK;

	// Only try to acquire the lock if the thread doesn't already own it.
    if (!IsLocked()) {
	
   		// Increment the benaphore count and test to see if it was already greater
   		// than 0.  If it is greater than 0, then some thread already has the
   		// benaphore or the style is a semaphore.  Either way, we need to acquire
   		// the semaphore in this case.
   		//int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, 1);
   		// TODO: use atomic_inc(&fBenaphoreCount) instead
   		int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, 1);
   		
  		if (oldBenaphoreCount > 0) {

			// NOTE: "timeout" is always considered zero			
			*error = acquire_sem_etc(fSemaphoreID, 1,
				timeout == B_INFINITE_TIMEOUT? 0 : B_RELATIVE_TIMEOUT,
				timeout);

   			// Note, if the lock here does time out, the benaphore count
   			// is not decremented.  By doing this, the benaphore count will
   			// never go back to zero.  This means that the locking essentially
   			// changes to semaphore style if this was a benaphore.
   			//
   			// Doing the decrement of the benaphore count when the acquisition
   			// fails is a risky thing to do.  If you decrement the counter at
   			// the same time the thread which holds the benaphore does an
   			// Unlock(), there is serious risk of a race condition.
   			//
   			// If the Unlock() sees a positive count and releases the semaphore
   			// and then the timed out thread decrements the count to 0, there
   			// is no one to take the semaphore.  The next two threads will be
   			// able to acquire the benaphore at the same time!  The first will
   			// increment the counter and acquire the lock.  The second will
   			// acquire the semaphore and therefore the lock.  Not good.
   			//
   			// This has been discussed on the becodetalk mailing list and
   			// Trey from Be had this to say:
   			//
   			// I looked at the LockWithTimeout() code, and it does not have
   			// _this_ (ie the race condition) problem.  It circumvents it by
   			// NOT doing the atomic_add(&count, -1) if the semaphore
   			// acquisition fails.  This means that if a
   			// BLocker::LockWithTimeout() times out, all other Lock*() attempts
   			// turn into guaranteed semaphore grabs, _with_ the overhead of a
   			// (now) useless atomic_add().
   			//
   			// Given Trey's comments, it looks like Be took the same approach
   			// I did.  The output of CountLockRequests() of Be's implementation
   			// confirms Trey's comments also.
   			//
   			// Finally some thoughts for the future with this code:
   			//   - If 2^31 timeouts occur on a 32-bit machine (ie today),
   			//     the benaphore count will wrap to a negative number.  This
   			//     would have unknown consequences on the ability of the BLocker
   			//     to continue to function.
   			//
    	}
    }
    
    // If the lock has successfully been acquired.	
   	if (*error == B_NO_ERROR) {
   		
   		// Set the lock owner to this thread and increment the recursive count
   		// by one.  The recursive count is incremented because one more Unlock()
   		// is now required to release the lock (ie, 0 => 1, 1 => 2 etc).
   		fLockOwner = find_thread(NULL);
    	fRecursiveCount++;
    }
   	
   	// Return true if the lock has been acquired.
    return (*error == B_NO_ERROR);
}