Exemplo n.º 1
0
void HandleSends() {
    //Send address
    if (state == Started) {
         SSPBUF = personBeingHelped->address << 1;
         state = SentAddress;
     //Send some data
     } else if (state == SentAddress || state == SentSomeData) {
         if (personBeingHelped->bytesLeft < personBeingHelped->len) {
            SSPBUF = personBeingHelped->data[personBeingHelped->bytesLeft];
            ++personBeingHelped->bytesLeft;
            state = SentSomeData;
         } else {
             PEN = 1;
             state = Stopped;
         }

     //Stop
     } else if (state == Stopped) {
         if (personBeingHelped->callback)
            Async(personBeingHelped->callback, NULL);
         personBeingHelped->address = -1;
         personBeingHelped = NULL;
         TryToHelp();
     }
}
Exemplo n.º 2
0
void HandleReads() {
    //Send address
    if (state == Started) {
         SSPBUF = personBeingHelped->address << 1 | 1;
         state = WaitingForSomeData;

     //Waiting for data
     } else if (state == WaitingForSomeData) {
         RCEN = 1;
         state = GotSomeData;
     //Got some data
     } else if (state == SentAddress || state == GotSomeData) {
         personBeingHelped->data[personBeingHelped->len] = SSPBUF;

         if (personBeingHelped->data[personBeingHelped->len] == 0) {
             PEN = 1;
             state = Stopped;
         } else {
             state = WaitingForSomeData;
             ACKEN = 1;
         }

         ++personBeingHelped->len;

     //Stop
     } else if (state == Stopped) {
         if (personBeingHelped->callback)
            Async(personBeingHelped->callback, personBeingHelped->data);
         personBeingHelped->address = -1;
         personBeingHelped = NULL;
         TryToHelp();
     }
}
Exemplo n.º 3
0
	FDataScannerImpl::FDataScannerImpl(const uint64 InDataOffset, const TArray<uint8>& InData, const FCloudEnumerationRef& InCloudEnumeration, const FDataMatcherRef& InDataMatcher, const FStatsCollectorRef& InStatsCollector)
		: DataStartOffset(InDataOffset)
		, Data(InData)
		, CloudEnumeration(InCloudEnumeration)
		, DataMatcher(InDataMatcher)
		, StatsCollector(InStatsCollector)
		, bIsComplete(false)
		, bShouldAbort(false)
	{
		// Create statistics
		StatCreatedScanners = StatsCollector->CreateStat(TEXT("Scanner: Created Scanners"), EStatFormat::Value);
		StatRunningScanners = StatsCollector->CreateStat(TEXT("Scanner: Running Scanners"), EStatFormat::Value);
		StatCpuTime = StatsCollector->CreateStat(TEXT("Scanner: CPU Time"), EStatFormat::Timer);
		StatConsumeBytesTime = StatsCollector->CreateStat(TEXT("Scanner: Consume Bytes Time"), EStatFormat::Timer);
		StatFindMatchTime = StatsCollector->CreateStat(TEXT("Scanner: Find Match Time"), EStatFormat::Timer);
		StatDataMatchTime = StatsCollector->CreateStat(TEXT("Scanner: Data Match Time"), EStatFormat::Timer);
		StatChunkWriterTime = StatsCollector->CreateStat(TEXT("Scanner: Chunk Writer Time"), EStatFormat::Timer);
		StatHashCollisions = StatsCollector->CreateStat(TEXT("Scanner: Hash Collisions"), EStatFormat::Value);
		StatChunkDataChecks = StatsCollector->CreateStat(TEXT("Scanner: Chunk Data Checks"), EStatFormat::Value);
		StatChunkDataMatches = StatsCollector->CreateStat(TEXT("Scanner: Chunk Data Matches"), EStatFormat::Value);
		StatMissingChunks = StatsCollector->CreateStat(TEXT("Scanner: Missing Chunks"), EStatFormat::Value);
		StatMatchedData = StatsCollector->CreateStat(TEXT("Scanner: Matched Data"), EStatFormat::DataSize);
		StatExtraData = StatsCollector->CreateStat(TEXT("Scanner: Extra Data"), EStatFormat::DataSize);
		// Queue thread
		NumIncompleteScanners.Increment();
		TFunction<FDataScanResult()> Task = [this]()
		{
			FDataScanResult Result = ScanData();
			FDataScannerImpl::NumIncompleteScanners.Decrement();
			return MoveTemp(Result);
		};
		FutureResult = Async(EAsyncExecution::ThreadPool, Task);
	}
Exemplo n.º 4
0
void OnSerialInterrupt() {
    static char data;
    data = RCREG;

    //Error
    if (FERR | OERR) {
        CREN = 0;
        CREN = 1;
        return;
    }

    //EOF
    if (data == 0) {
        for (int i = 0; i < 10; ++i)
        LA3 = ~LA3;
        bufferSerial[bufferPosition] = 0;
        bufferPosition = 0;

        //Que the handler
        if (callback) {

            Async(callback, bufferSerial);
        }

        return;
     }

     //Put data in buffer
     bufferSerial[bufferPosition] = data;
     ++bufferPosition;
}
Exemplo n.º 5
0
//Register this callback function for incomming messages
void TwitterOnReceive() {
    char *message = AsyncMessage;

    //Get the 'to' field of this message
    JsonGetString(message, "to", tempBuffer);

    //Hashtag multicast
    if (tempBuffer[0] == '#') {
        //Is there any callbacks registered to this message?
        if (hashtagA.callback && !strcmp(hashtagA.hashtag, tempBuffer)) {
            hashtagA.callback();
        } else if (hashtagB.callback && !strcmp(hashtagB.hashtag, tempBuffer)) {
            hashtagB.callback();
        } else if (hashtagC.callback && !strcmp(hashtagC.hashtag, tempBuffer)) {
            hashtagC.callback();
        }

        //Send message back if needed
        isARelay = 1;
        TwitterSendToAll(message);
        isARelay = 0;

        //Is this message directed towards me?
    } else if (!strcmp(tempBuffer, name)) {
        JsonGetString(message, "sub", tempBuffer);
        //Is this part of a session?
        if (tempBuffer[0] == 'c' && tempBuffer[1] == 'c') {
            int key = JsonGetValue(message, "key");
            //Find the callback
            if (sessionA.key == key && sessionA.key != -1) {
                Async(sessionA.callback, message);
                sessionA.key = -1;
            } else if (sessionB.key == key && sessionB.key != -1) {
                Async(sessionB.callback, message);
                sessionB.key = -1;
            }
        }

        //Is there any callbacks registered to this message
        else if (subjectA.callback && !strcmp(subjectA.subject, tempBuffer)) {
            subjectA.callback();
        } else if (subjectB.callback && !strcmp(subjectB.subject, tempBuffer)) {
            subjectB.callback();
        }
    }
}
void CBBSubSessionImpl::Deleted(const TTupleName& aName, const TDesC& aSubName)
{
	CALLSTACKITEM_N(_CL("CBBSubSessionImpl"), _CL("NewValue"));

	TItem t(0, aName, aSubName, KNoComponent, 0);
	iPending->AppendL(t);
	Async();
}
void CBBSubSessionImpl::NewValue(TUint aId, const TTupleName& aTupleName, const TDesC& aSubName, const TComponentName& aComponentName, 
	const CRefCountedData* aData)
{
	CALLSTACKITEM_N(_CL("CBBSubSessionImpl"), _CL("NewValue"));

	TItem t(aId, aTupleName, aSubName, aComponentName, aData);
	iPending->AppendL(t);
	t.iData->AddRef();
	Async();
}
Exemplo n.º 8
0
Arquivo: main.cpp Projeto: CCJY/coliru
 Scheduler()
 {
     Async([=]{
         try {
             while (true) {
                 std::function<void()> f;
                 concurrent_queue.pop(f);
                 f();
             }
         } catch (QuitException) {
             // exit the thread.
         }
     });
 }
void CBBSubSessionImpl::CheckedRunL()
{
	CALLSTACKITEM_N(_CL("CBBSubSessionImpl"), _CL("CheckedRunL"));

	TItem t=iPending->Pop();
	TInt err;
	if (iPending->iCount > 0) Async();
	if (t.iData) {
		CC_TRAP(err, iObserver->NewValueL(t.iId, t.iName, t.iSubName, t.iComponentName, t.iData->Get()));
		t.iData->Release();
	} else {
		CC_TRAP(err, iObserver->DeletedL(t.iName, t.iSubName));
	}
	User::LeaveIfError(err);
}
Exemplo n.º 10
0
static STDMETHODIMP
WinSendCom_Invoke(
    IDispatch *This,
    DISPID dispidMember,
    REFIID riid,
    LCID lcid,
    WORD wFlags,
    DISPPARAMS *pDispParams,
    VARIANT *pvarResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr)
{
    HRESULT hr = DISP_E_MEMBERNOTFOUND;
    TkWinSendCom *this = (TkWinSendCom*)This;

    switch (dispidMember) {
    case TKWINSENDCOM_DISPID_SEND:
	if (wFlags | DISPATCH_METHOD) {
	    if (pDispParams->cArgs != 1) {
		hr = DISP_E_BADPARAMCOUNT;
	    } else {
		hr = Send(this, pDispParams->rgvarg[0], pvarResult,
			pExcepInfo, puArgErr);
	    }
	}
	break;

    case TKWINSENDCOM_DISPID_ASYNC:
	if (wFlags | DISPATCH_METHOD) {
	    if (pDispParams->cArgs != 1) {
		hr = DISP_E_BADPARAMCOUNT;
	    } else {
		hr = Async(this, pDispParams->rgvarg[0], pExcepInfo, puArgErr);
	    }
	}
	break;
    }
    return hr;
}
Exemplo n.º 11
0
	FManifestBuilderImpl::FManifestBuilderImpl(const FManifestDetails& InDetails, const FBuildStreamerRef& InBuildStreamer)
		: BuildStreamer(InBuildStreamer)
		, Manifest(MakeShareable(new FBuildPatchAppManifest()))
		, FileAttributesMap(InDetails.FileAttributesMap)
		, EndOfData(false)
		, CheckForWork(FPlatformProcess::GetSynchEventFromPool(true))
	{
		Manifest->Data->bIsFileData = InDetails.bIsFileData;
		Manifest->Data->AppID = InDetails.AppId;
		Manifest->Data->AppName = InDetails.AppName;
		Manifest->Data->BuildVersion = InDetails.BuildVersion;
		Manifest->Data->LaunchExe = InDetails.LaunchExe;
		Manifest->Data->LaunchCommand = InDetails.LaunchCommand;
		Manifest->Data->PrereqName = InDetails.PrereqName;
		Manifest->Data->PrereqPath = InDetails.PrereqPath;
		Manifest->Data->PrereqArgs = InDetails.PrereqArgs;
		for (const auto& CustomField : InDetails.CustomFields)
		{
			int32 VarType = CustomField.Value.GetType();
			if (VarType == EVariantTypes::Float || VarType == EVariantTypes::Double)
			{
				Manifest->SetCustomField(CustomField.Key, (double)CustomField.Value);
			}
			else if (VarType == EVariantTypes::Int8 || VarType == EVariantTypes::Int16 || VarType == EVariantTypes::Int32 || VarType == EVariantTypes::Int64 ||
				VarType == EVariantTypes::UInt8 || VarType == EVariantTypes::UInt16 || VarType == EVariantTypes::UInt32 || VarType == EVariantTypes::UInt64)
			{
				Manifest->SetCustomField(CustomField.Key, (int64)CustomField.Value);
			}
			else if (VarType == EVariantTypes::String)
			{
				Manifest->SetCustomField(CustomField.Key, CustomField.Value.GetValue<FString>());
			}
		}
		TFunction<void()> Task = [this]() { BuildManifest(); };
		Future = Async(EAsyncExecution::Thread, Task);
	}
Exemplo n.º 12
0
//I2C interrupted us
void JWireOnInterrupt() {
    //Master is about to write us some data
    if (WriteGotAddress) {
        int addr = SSPBUF;
        CKP = 1;
        //Get ready for data!
        bufferReadPos = 0;
    }

    //Master is writing us some data
    if (WriteGotData) {
        int data = SSPBUF;

        //Read some data!
        buffer[bufferReadPos] = data;

        if (buffer[bufferReadPos] == 0) {
            if (receiveCallback) {
                Async(receiveCallback, buffer);
            }
        }

        ++bufferReadPos;

        CKP = 1;
    }


    //Master is requesting some data (First byte)
    else if (ReadGotAddress) {
        // Check for the lock
        if(!locked) {
            if(requestCallback) {
                requestCallback();
            }
            locked = 1;

            //Send some data back, specifically the first data byte
            bufferWritePos = 0;
        }

        int temp = SSPBUF;


        if ((buffer[bufferWritePos]) == 0) {
            locked = 0;
            SSPBUF = 0;
            CKP = 1;
            return;
        }

          SSPBUF = buffer[bufferWritePos];
          CKP = 1;

//        LA4 = ~LA4;
//        LA4 = ~LA4;
//        LA4 = ~LA4;
    }

    //Master really wants some more data (Not the first byte)
    else if (ReadGotData) {
        if (locked) {
        bufferWritePos = bufferWritePos + 1;
        SSPBUF = buffer[bufferWritePos];

//        LA5 = ~LA5;
//        LA5 = ~LA5;
//        LA5 = ~LA5;


        if(buffer[bufferWritePos] == 0) {
            locked = 0;
        }

        CKP = 1;
        }
    }

    //Master dosen't want anything more D:, :[
    else if (ReadDone) {
//        LA7 = ~LA7;
//        LA7 = ~LA7;
//        LA7 = ~LA7;
    }
}
Exemplo n.º 13
0
void AsyncBlank(AsyncCallback_t function) {
    Async(function, NULL, 0);
}
Exemplo n.º 14
0
void ffplayer::RenderThreadRun()
{
	if (m_hwnd)
	{
		CreateRender();
	}

	int iWidth = 0;
	int iHeight = 0;

	bool bFirst = true;
	while (1)
	{
	//	Sleep(10);
		if (m_bStop)
			break;
		
		/*
		if (bFirst)
		{
			if (m_renderBuf.getCurCount() < 2)//这里会导致音乐.mp3的画面没显示
			{
				continue;
			}
		}*/
		if (m_bStepNext&&m_bStepEnd){
			RefreshRender();
			continue;
		}
		if (m_bPause &&!m_bPausedSeek){		
			RefreshRender();
			continue;
		}
	
		PInfo pYuvInfo = m_renderBuf.getInfoFromList();
		if (!pYuvInfo){
			RefreshRender();
			if (m_bFileEnd&&m_fileEndBak){
				m_fileEndBak(m_nID, m_pUser);
				Sleep(1000);
				continue;//
			}
			Sleep(10);
			continue;
		}else{
			if (bFirst){
				bFirst = false;
			}else{
				
				if (pYuvInfo->frameInfo.serial == m_serial/*&&!m_bSeekState&&m_serial == m_audclk.serial*/)//暂停后再seek后,声音暂停了m_audclk.serial还是原来的,不等于m_serial
				{
					if (pYuvInfo->frameInfo.serial == m_lastserial){

				/*		if (m_seekTime != 0)
						{
							//秒
							double duation = pYuvInfo->frameInfo.iTimestampObsolute* av_q2d(m_pFormatCtx->streams[m_videoStream]->time_base);
							if (m_seekTime < duation)
							{
								UpdateVideoPts(pYuvInfo);
								m_freeRenderBuf.insertList(pYuvInfo);//
								continue;
							}
							else
							{
								m_seekTime = 0;
							}

						}*/
					//	if (m_serial == m_audclk.serial)//有这句会导致无音频的视频不会Async
						if (!m_bFastNoDelay)
						{
							int dif = Async(pYuvInfo->frameInfo.iTimestampObsolute);
						}
						
					/*	if (dif < 0)
						{
							UpdateVideoPts(pYuvInfo);
							m_freeRenderBuf.insertList(pYuvInfo);
							continue;
						}*/
						if (m_bPausedSeek)
							m_bPausedSeek = false;

					 }else{
						
						UpdateVideoPts(pYuvInfo);
						m_freeRenderBuf.insertList(pYuvInfo);//只更新pts和serial,不显示,显示会花屏
						continue;
					}
				}else{
					m_freeRenderBuf.insertList(pYuvInfo);//另一个系列不用显示,忽略
					continue;		
				}
			}		

			if (m_displayBak)
			{
				DISPLAYCALLBCK_INFO pDisplayInfo;
				pDisplayInfo.pBuf = (char*)pYuvInfo->Data;
				pDisplayInfo.nBufLen = pYuvInfo->width*pYuvInfo->height * 3 / 2;
				pDisplayInfo.nWidth = pYuvInfo->width;
				pDisplayInfo.nHeight = pYuvInfo->height;
				pDisplayInfo.nUser = (long)m_pDisplayUser;
				pDisplayInfo.nStamp = GetPlayedTime();
				m_displayBak(&pDisplayInfo);
			}
			if (m_hwnd)
			{
				int w, h;
				RECT rc;
				GetWindowRect(m_hwnd, &rc);
				w = rc.right - rc.left;
				h = rc.bottom - rc.top;
				if (iWidth != w || iHeight != h){
					iWidth = w;
					iHeight = h;
					SDL_SetWindowSize(m_sdlWindow, w, h);
				}

				if (m_pTexture == NULL)
					m_pTexture = SDL_CreateTexture(m_pRender, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, pYuvInfo->width, pYuvInfo->height);


				//计算yuv一行数据占的字节数
				int iPitch = pYuvInfo->width*SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_IYUV);

				int i = SDL_UpdateTexture(m_pTexture, NULL, pYuvInfo->Data, iPitch);

				SDL_RenderClear(m_pRender);
				SDL_RenderCopy(m_pRender, m_pTexture, NULL, NULL);
				SDL_RenderPresent(m_pRender);
			}
			if (m_bReadFrameFinish)
				m_curFrameCount++;
			else
				m_tmpFrameCount++;			

			m_picSnopshot = pYuvInfo;

			UpdateVideoPts(pYuvInfo);
			m_freeRenderBuf.insertList(pYuvInfo);
			m_bStepEnd = true;		
		}
	}

	DestoryRender();	
}
Exemplo n.º 15
0
nsresult
HTMLScriptElement::GetAsync(bool* aValue)
{
  *aValue = Async();
  return NS_OK;
}