示例#1
0
	void NIDAQWrapper::Initialize()
	{
		BuildUI();
		// Setup our read channel
		readHandle = GetTask("readTask", winLog);
		for(int x = 0; x < 12; x++)
		{
			std::stringstream s;
			std::string name;
			s << "Voltage_" << x;
			s >> name;
			GetReadChannel(readHandle, name.c_str(), x, winLog);
		}
		StartTask(readHandle, EveryNCallback, this, winLog);

		// Setup our write channels
		writeHandles.push_back(TaskHandle());
		writeHandles[0] = GetTask("write0");
		GetWriteChannel(writeHandles[0], "DigitalOut_0", 0, winLog);
		writeHandles.push_back(TaskHandle());
		writeHandles[1] = GetTask("write1");
		GetWriteChannel(writeHandles[1], "DigitalOut_1", 1, winLog);

		StartTask(writeHandles[0], NULL, NULL, winLog);
		StartTask(writeHandles[1], NULL, NULL, winLog);

		wrefresh(winLog);

		return;
	}
示例#2
0
void Task::Run( TaskManager* task_manager )
{
	ASSERT( IsReadyToBeExecuted() );

	TaskContext taskContext( *task_manager, this );

	// Execute task function:
	m_functionPtr( taskContext );

	// We are finished, so we can't have any dependant tasks now.
	unsigned dependent_num = m_numberOfChildTasks.Decrement();
	ASSERT( dependent_num == 0 );

	if( m_parentTask )
	{
		// Inform parent that we are finished.
		unsigned parent_dependant_task = m_parentTask->m_numberOfChildTasks.Decrement();
		ASSERT( parent_dependant_task > 0 );

		// Parent is ready to be executed, so add it to our thread.
		if( parent_dependant_task == 1 )
		{
			bool submitted = task_manager->SubmitTask( TaskHandle( m_parentTask ) );
			ASSERT( submitted );
		}		
	}
}
示例#3
0
TaskHandle CreateTask(TaskPool& pool,
                      TaskHandle* parentTask,
                      const DELEGATE_CBK<void, const Task&>& threadedFunction)
{
    Task* freeTask = pool.createTask(parentTask ? parentTask->_task : nullptr,
                                     threadedFunction);
    return TaskHandle(freeTask, &pool);
}
示例#4
0
TaskHandle TaskAllocator::AllocateNewTask()
{
    // Hashing is used to avoid false sharing of pool markers.
    // [NOTE] : think about the hash taking cache line size into calcualtion to avoid contention. (?)
    ++m_hashedNumber;
    unsigned num = CalcHashedNumber< TASK_POOL_SIZE >( m_hashedNumber );

    for( unsigned i = 0; i < TASK_POOL_SIZE; ++i )
    {
        unsigned expected = 0;
        unsigned index = ( num + i ) & ( TASK_POOL_SIZE - 1 ); // fast modulo
        if( m_poolMarkers[ index ].CompareExchange( expected, 1 ), MemoryOrder::Acquire )
        {
            // We have available task:
            return TaskHandle( &m_taskPool[ index ] );
        }
    }

    return INVALID_TASK_HANDLE;
}
示例#5
0
int loadTask(const std::string & name){//Load a task into memory, do not run
	tasks.push_back(TaskHandle(new t(), name));
	size++;
	return tasks.size()-1;
}