void MediaInfoList_Internal::Entry()
{
    if (ToParse_Total==0)
        return;

    while (1)
    {
        CS.Enter();
        if (!ToParse.empty())
        {
            MediaInfo* MI=new MediaInfo();
            for (std::map<String, String>::iterator Config_MediaInfo_Item=Config_MediaInfo_Items.begin(); Config_MediaInfo_Item!=Config_MediaInfo_Items.end(); Config_MediaInfo_Item++)
                MI->Option(Config_MediaInfo_Item->first, Config_MediaInfo_Item->second);
            if (BlockMethod==1)
                MI->Option(_T("Thread"), _T("1"));
            MI->Open(ToParse.front());
            if (BlockMethod==1)
            {
                CS.Leave();
                while (MI->State_Get()<10000)
                {
                    size_t A=MI->State_Get();
                    CS.Enter();
                    State=(ToParse_AlreadyDone*10000+A)/ToParse_Total;
                    CS.Leave();
                    if (IsTerminating())
                    {
                        break;
                    }
                    Yield();
                }
                CS.Enter();
            }
            Info.push_back(MI);
            ToParse.pop();
            ToParse_AlreadyDone++;
            State=ToParse_AlreadyDone*10000/ToParse_Total;
        }
        if (IsTerminating() || State==10000)
        {
            CS.Leave();
            break;
        }
        CS.Leave();
        Yield();
    }
}
Example #2
0
/*
============================
idAutoRender::Run
============================
*/
int idAutoRender::Run()
{
	while( !IsTerminating() )
	{
		RenderFrame();
	}
	
	
	return 0;
}
Example #3
0
int htThreadItf::Execute()
{
	// Notify that thread has started
	onStart();
	
	// Loop until termination requested
	while( !IsTerminating() ) {
		mMutex.Acquire();
		if( run() ) break;
		mMutex.Release();
		Sleep( waitTime() );
	}
	
	// Notify that thread is ending
	onStop();
}
int
DataGloveThread::Execute()
{
	unsigned short currentData[MAX_SENSORS];
	while( !IsTerminating() ) {
		for(int i = 0; i < MAX_SENSORS; i++) currentData[i] = 0;

		currentData[0]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_THUMBNEAR);
		currentData[1]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_INDEXNEAR);
		currentData[2]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_MIDDLENEAR);
		currentData[3]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_RINGNEAR);
		currentData[4]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_LITTLENEAR);

		if (m_type == FD_GLOVE14U_USB) {
			currentData[5]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_THUMBFAR);
			currentData[6]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_INDEXFAR);
			currentData[7]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_MIDDLEFAR);
			currentData[8]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_RINGFAR);
			currentData[9]  = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_LITTLEFAR);
			currentData[10] = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_THUMBINDEX);
			currentData[11] = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_INDEXMIDDLE);
			currentData[12] = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_MIDDLERING);
			currentData[13] = mpLogger->m_fdGetSensorRawCall(mpGlove, FD_RINGLITTLE);
		}
		if(m_deriv) {
			for(int i = 0; i < MAX_SENSORS; i++) {
				double diff = (double)currentData[i] - (double)mPreviousReading[i];
				mPreviousReading[i] = currentData[i];
				long min = -(1L << (SENSOR_PRECISION-1));
				long max =  (1L << (SENSOR_PRECISION-1)) - 1;
				diff = (diff < min ? min : diff > max ? max : diff);
				currentData[i] = (unsigned short)(diff - min);
			}
		}

		for(int i = 0; i < MAX_SENSORS; i++) {
			if(currentData[i] != mPreviousOutput[i])
				bcievent << "Glove" << m_index << "Sensor" << setfill('0') << setw(2) << (i+1) << " " << currentData[i];
			mPreviousOutput[i] = currentData[i];
		}
		::Sleep(1);
	}
	::Sleep(10);
	return 0;
}
Example #5
0
void FolderUser::ThreadMain()
{
	Output("Initializing FolderUser, scanning " + m_folder + " ...");
	IO::Folder folder;

	folder.Path(m_folder);

	Output("Init complete, running ...");

	auto files = folder.CurrentContents();
	auto i = files.begin();

	while(IsTerminating() == false)
	{
		i++;
		if (i != files.end())
		{
			if (i->Type == IO::TypeFile)
			{
				auto name = m_folder + i->Name;

				IO::FileReader file(name);
				if (file.Open())
				{
					uint8_t buf[4096];
					file.Read(buf, 1, 4096);
				}
			}
		}
		else
		{
			files = folder.CurrentContents();
			i = files.begin();
		}
	}
}
//---------------------------------------------------------------------------
void QueueElement::Entry()
{
    std::string file = real_filename;
    std::string err;

    //Pre hook plugins
    int ret = 0;

    std::stringstream log;
    log << "start analyze:" << file;
    scheduler->write_log_timestamp(PluginLog::LOG_LEVEL_DEBUG, log.str());

    ret = scheduler->execute_pre_hook_plugins(this, err);

    if (ret || !mil_analyze)
    {
        log.str("");
        log << "end analyze:" << file;
        scheduler->write_log_timestamp(PluginLog::LOG_LEVEL_DEBUG, log.str());
        scheduler->work_finished(this, NULL);
        return;
    }

    MI_CS.Enter();
    MI = new MediaInfoNameSpace::MediaInfo;
    MI_CS.Leave();

    // Currently avoiding to have a big trace
    bool found = false;
    for (size_t i = 0; i < options.size(); ++i)
    {
        if (options[i].first == "parsespeed" || options[i].first == "file_parsespeed")
        {
            found = true;
            break;
        }
    }
    if (found == false)
        MI->Option(__T("ParseSpeed"), __T("0"));

    // Configuration of the parsing
    found = false;
    for (size_t i = 0; i < options.size(); ++i)
        if (options[i].first == "details")
            found = true;
    if (found == false)
        MI->Option(__T("Details"), __T("1"));

    // Attachment
    std::stringstream ss;
    ss << "CallBack=memory://" << (int64u)Event_CallBackFunction << ";UserHandler=memory://" << (int64u)this;
    MI->Option(__T("File_Event_CallBackFunction"), ZenLib::Ztring().From_UTF8(ss.str()));

    // Partial configuration of the output (note: this options should be removed after libmediainfo has a support of these options after Open() )
    MI->Option(__T("ReadByHuman"), __T("1"));
    MI->Option(__T("Language"), __T("raw"));
    MI->Option(__T("Inform"), __T("MICRO_XML"));

    for (size_t i = 0; i < options.size(); ++i)
        MI->Option(Ztring().From_UTF8(options[i].first), Ztring().From_UTF8(options[i].second));

    MI->Open(ZenLib::Ztring().From_UTF8(file));
    if (!IsTerminating()) //If terminating was requested, file is partially parsed (and there is some thread lock because the scheduler calls the queue which calls the scheduler) //TODO: reorganize calls
        scheduler->work_finished(this, MI);
    MI_CS.Enter();
    MI->Close();
    delete MI;
    MI = NULL;
    MI_CS.Leave();
    log.str("");
    log << "end analyze:" << file;
    scheduler->write_log_timestamp(PluginLog::LOG_LEVEL_DEBUG, log.str());

    // Delete a generated file
    if (real_filename != filename)
    {
        Ztring z_path = ZenLib::Ztring().From_UTF8(real_filename);
        ZenLib::File::Delete(z_path);
    }
}
/*
========================
idJobThread::Run
========================
*/
int idJobThread::Run()
{
	threadJobListState_t threadJobListState[MAX_JOBLISTS];
	int numJobLists = 0;
	int lastStalledJobList = -1;
	
	while( !IsTerminating() )
	{
	
		// fetch any new job lists and add them to the local list
		if( numJobLists < MAX_JOBLISTS && firstJobList < lastJobList )
		{
			threadJobListState[numJobLists].jobList = jobLists[firstJobList & ( MAX_JOBLISTS - 1 )].jobList;
			threadJobListState[numJobLists].version = jobLists[firstJobList & ( MAX_JOBLISTS - 1 )].version;
			threadJobListState[numJobLists].signalIndex = 0;
			threadJobListState[numJobLists].lastJobIndex = 0;
			threadJobListState[numJobLists].nextJobIndex = -1;
			numJobLists++;
			firstJobList++;
		}
		if( numJobLists == 0 )
		{
			break;
		}
		
		int currentJobList = 0;
		jobListPriority_t priority = JOBLIST_PRIORITY_NONE;
		if( lastStalledJobList < 0 )
		{
			// find the job list with the highest priority
			for( int i = 0; i < numJobLists; i++ )
			{
				if( threadJobListState[i].jobList->GetPriority() > priority && !threadJobListState[i].jobList->WaitForOtherJobList() )
				{
					priority = threadJobListState[i].jobList->GetPriority();
					currentJobList = i;
				}
			}
		}
		else
		{
			// try to hide the stall with a job from a list that has equal or higher priority
			currentJobList = lastStalledJobList;
			priority = threadJobListState[lastStalledJobList].jobList->GetPriority();
			for( int i = 0; i < numJobLists; i++ )
			{
				if( i != lastStalledJobList && threadJobListState[i].jobList->GetPriority() >= priority && !threadJobListState[i].jobList->WaitForOtherJobList() )
				{
					priority = threadJobListState[i].jobList->GetPriority();
					currentJobList = i;
				}
			}
		}
		
		// if the priority is high then try to run through the whole list to reduce the overhead
		// otherwise run a single job and re-evaluate priorities for the next job
		bool singleJob = ( priority == JOBLIST_PRIORITY_HIGH ) ? false : jobs_prioritize.GetBool();
		
		// try running one or more jobs from the current job list
		int result = threadJobListState[currentJobList].jobList->RunJobs( threadNum, threadJobListState[currentJobList], singleJob );
		
		if( ( result & idParallelJobList_Threads::RUN_DONE ) != 0 )
		{
			// done with this job list so remove it from the local list
			for( int i = currentJobList; i < numJobLists - 1; i++ )
			{
				threadJobListState[i] = threadJobListState[i + 1];
			}
			numJobLists--;
			lastStalledJobList = -1;
		}
		else if( ( result & idParallelJobList_Threads::RUN_STALLED ) != 0 )
		{
			// yield when stalled on the same job list again without making any progress
			if( currentJobList == lastStalledJobList )
			{
				if( ( result & idParallelJobList_Threads::RUN_PROGRESS ) == 0 )
				{
					Sys_Yield();
				}
			}
			lastStalledJobList = currentJobList;
		}
		else
		{
			lastStalledJobList = -1;
		}
	}
	return 0;
}
Example #8
0
void Reader_File_Thread::Entry()
{
    for (;;)
    {
        Base->CS.Enter();
        if (Base->Buffer_Begin==Base->Buffer_Max)
        {
            Base->IsLooping=false;
            Base->Buffer_End=Base->Buffer_End2;
            Base->Buffer_End2=0;
            Base->Buffer_Begin=0;
        }

        size_t ToRead;
        size_t Buffer_ToReadOffset;
        if (Base->IsLooping)
        {
            ToRead=Base->Buffer_Begin-Base->Buffer_End2;
            Buffer_ToReadOffset=Base->Buffer_End2;
        }
        else
        {
            ToRead=Base->Buffer_Max-Base->Buffer_End;
            Buffer_ToReadOffset=Base->Buffer_End;
        }
        Base->CS.Leave();

        if (ToRead)
        {
            if (ToRead>4*1024*1024)
                ToRead=4*1024*1024;
            size_t BytesRead=Base->F.Read(Base->Buffer+Buffer_ToReadOffset, ToRead);
            if (!BytesRead)
                break;

            Base->CS.Enter();
            if (Base->IsLooping)
            {
                Base->Buffer_End2+=BytesRead;
            }
            else
            {
                Base->Buffer_End+=BytesRead;
                if (Base->Buffer_End==Base->Buffer_Max)
                {
                    Base->IsLooping=true;
                }
            }
            Base->CS.Leave();

            #ifdef WINDOWS
                SetEvent(Base->Condition_WaitingForMoreData);
            #endif //WINDOWS
        }
        #ifdef WINDOWS
            else
                WaitForSingleObject(Base->Condition_WaitingForMorePlace, INFINITE);
        #endif //WINDOWS

        if (IsTerminating())
            break;
        Yield();
    }
}