int main(){
    Poco::RWLock lock;
    Task task1(1, &lock);
    Task task2(2, &lock);
    Poco::ThreadPool pool;
    pool.start(task1);
    pool.start(task2);
    pool.joinAll();
    return 0;
}
Exemple #2
0
/* FUNCION que contiene el planificador y despachador de tareas. */
static void scheduleAndDispatchTasks(void){

   /* Tarea planificada cada TASK1_PERIODICITY ms */
   if( task1Counter++ == TASK1_PERIODICITY ){
      /* Despacho de la tarea (la ejecuta) */
      task1();

      /* Resetea el contador de la tarea */
      task1Counter = 0;
   }

   /* Tarea planificada cada TASK2_PERIODICITY ms */
   if( task2Counter++ == TASK2_PERIODICITY ){
      /* Despacho de la tarea (la ejecuta) */
      task2();

      /* Resetea el contador de la tarea */
      task2Counter = 0;
   }

   /* Tarea planificada cada TASK3_PERIODICITY ms */
   if( task3Counter++ == TASK3_PERIODICITY ){
      /* Despacho de la tarea (la ejecuta) */
      task3();

      /* Resetea el contador de la tarea */
      task3Counter = 0;
   }

}
Exemple #3
0
/* FUNCION que contiene el despachador de tareas. */
void seosDispatchTask(void){

   /* Tarea planificada cada TASK1_PERIODICITY ms */
   if( task1RunFlag ){
      /* Si el flag esta en 1 despacha de la tarea 
         (la ejecuta) */
      task1();

      /* Resetea el flag de ejecucion de la tarea */
      task1RunFlag = 0;
   }

   /* Tarea planificada cada TASK2_PERIODICITY ms */
   if( task2RunFlag ){
      /* Si el flag esta en 1 despacha de la tarea 
         (la ejecuta) */
      task2();

      /* Resetea el flag de ejecucion de la tarea */
      task2RunFlag = 0;
   }

   /* Tarea planificada cada TASK3_PERIODICITY ms */
   if( task3RunFlag ){
      /* Si el flag esta en 1 despacha de la tarea 
         (la ejecuta) */
      task3();

      /* Resetea el flag de ejecucion de la tarea */
      task3RunFlag = 0;
   }

}
Exemple #4
0
int main(int argc, char** argv) {

    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " path/to/lena" << std::endl;
        exit(1);
    }

    cv::Mat image, orig, lena, noize, diag, tool;
    image = cv::imread(argv[1], 1);
    diag = cv::imread(DIAG, CV_LOAD_IMAGE_GRAYSCALE);
    orig = cv::imread(ORIG, CV_LOAD_IMAGE_GRAYSCALE);
    lena = cv::imread(LENA, 1);
    noize = cv::imread(NOIZE, 1);
    tool = cv::imread(TOOL, CV_LOAD_IMAGE_GRAYSCALE);

    std::cout << "Task 1 Status: " << (task1(image) ? "OK" : "Error") << std::endl;
    std::cout << "Task 2 Status: " << (task2(image) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3 Status: " << (task3(image) ? "OK" : "Error") << std::endl;
    std::cout << "Task 4 Status: " << (task4(image) ? "OK" : "Error") << std::endl;
    std::cout << "Task 5 Status: " << (task5((PATH + "noize/").c_str()) ? "OK" : "Error") << std::endl;
    std::cout << "Task 6 Status: " << (task6(image) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3.1 Status: " << (task3_1(orig) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3.2 Status: " << (task3_2(orig) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3.3 Status: " << (task3_3(tool) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3.5 Status: " << (task3_5(diag, orig) ? "OK" : "Error") << std::endl;
    std::cout << "Task 3.6 Status: " << (task3_6(lena, noize) ? "OK" : "Error") << std::endl;

    //    cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL);
    //    cv::imshow("Lesson 2", image);
    //    cv::waitKey(0);
    return 0;

}
Exemple #5
0
int main ( )
{
    task1( );
    task2( );
    task3( );
    return 0;
}
Exemple #6
0
void CharmDataModelTests::modifyTaskTest()
{
    CharmDataModel model;
    Task task1( 1000, "Task 1" );
    Task task1_1( 1001, "Task 1-1", task1.id() );
    Task task1_2( 1002, "Task 1-2", task1.id() );
    Task task1_3( 1003, "Task 1-3", task1.id() );
    model.addTask( task1 );
    model.addTask( task1_3 );
    model.addTask( task1_1 );
    model.addTask( task1_2 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 3 );

    // new values:
    Task task1b( task1 );
    task1b.setName( "Task 1, modified" );
    Task task1_1b( task1_1 );
    task1_1b.setParent( 0 );

    QVERIFY( model.taskTreeItem( task1.id() ).task() == task1 );
    model.modifyTask( task1b );
    QVERIFY( model.taskTreeItem( task1.id() ).task() == task1b );

    QVERIFY( model.taskTreeItem( task1_1.id() ).task() == task1_1 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    model.modifyTask( task1_1b ); // now a top level
    QVERIFY( model.taskTreeItem( task1_1.id() ).task() == task1_1b );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 2 );

    model.clearTasks();
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 0 );
}
Exemple #7
0
    void Scheduler_ut::test_aperiodic_task()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        const units::Nanoseconds test_delay(3 * units::SEC);
        IPRINTF("\nTesting aperiodic tasks. "
                "This test takes at least %" PRId64 " seconds\n",
                int64_t(test_delay / units::SEC));

        /* Create an aperiodic task and make sure it is valid.
         */
        Task_properties task1_props;
        task1_props.prio = higher_priority;
        Test_task task1("aperiodic_1", 5, 3);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(task1_props));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        /* Off to the races.
         */
        CPPUNIT_ASSERT_EQUAL(true, task1.start());

        /* Not the most reliable timing method.
         */
        sleep(test_delay);
        task1.stop();

        /* Check the counters to see if the counts match.
         */
        CPPUNIT_ASSERT_EQUAL(3, counter[5]);
    }
void
PriorityTapeTest::testPriority()
{
    boost::posix_time::ptime begin;
    boost::posix_time::ptime current;
    int duration;


    CPPUNIT_ASSERT( true == priority_->Enable(true) );

    PriorityTapeTask task0(priority_.get(),100,0,10);
    PriorityTapeTask task1(priority_.get(),100,1,10);
    PriorityTapeTask task2(priority_.get(),100,2,10);
    PriorityTapeTask task3(priority_.get(),100,3,10);
    PriorityTapeTask task4(priority_.get(),100,4,10);
    PriorityTapeTask task5(priority_.get(),100,5,10);

    task0.Start();
    boost::this_thread::sleep(
        boost::posix_time::milliseconds(5) );
    task1.Start();
    task2.Start();
    task3.Start();
    task4.Start();
    task5.Start();
    CPPUNIT_ASSERT( false == task0.Finished() );
    CPPUNIT_ASSERT( false == task1.Finished() );
    CPPUNIT_ASSERT( false == task2.Finished() );
    CPPUNIT_ASSERT( false == task3.Finished() );
    CPPUNIT_ASSERT( false == task4.Finished() );
    CPPUNIT_ASSERT( false == task5.Finished() );
    boost::this_thread::sleep(
        boost::posix_time::milliseconds(100) );
    CPPUNIT_ASSERT( true == task0.Finished() );
    CPPUNIT_ASSERT( true == task5.Finished() );
    CPPUNIT_ASSERT( true == task4.Finished() );
    CPPUNIT_ASSERT( true == task3.Finished() );
    CPPUNIT_ASSERT( true == task2.Finished() );
    CPPUNIT_ASSERT( true == task1.Finished() );

    duration = (task0.End() - task0.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    duration = (task1.End() - task1.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    duration = (task2.End() - task2.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    duration = (task3.End() - task3.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    duration = (task4.End() - task4.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    duration = (task5.End() - task5.Begin()).total_milliseconds();
    CPPUNIT_ASSERT( duration >= 10 );
    CPPUNIT_ASSERT( task0.End() <= task5.Begin() );
    CPPUNIT_ASSERT( task5.End() <= task4.Begin() );
    CPPUNIT_ASSERT( task4.End() <= task3.Begin() );
    CPPUNIT_ASSERT( task3.End() <= task2.Begin() );
    CPPUNIT_ASSERT( task2.End() <= task1.Begin() );
}
Exemple #9
0
void test_tasker_yield() {
  double result;

  // Main loop that executes all base tasks
  do {
    result = task1();
  } while(hasNoResult);

  printf("Got %f\n", result);
}
int main(){
    boost::mutex mutex;
    Task task1(1, &mutex);
    Task task2(2, &mutex);
	
	boost::thread th1(&Task::run, &task1); 
	boost::thread th2(&Task::run, &task2); 
	th1.join();
	th2.join();	
    return 0;
}
Exemple #11
0
rtems_task Init(
  rtems_task_argument argument
)
{
  TEST_BEGIN();

  task1();
  /* does not return */
  puts( "Init - task1 should not have returned" );
  rtems_test_exit( 0 );
}
Exemple #12
0
rtems_task Init(
    rtems_task_argument argument
)
{
    puts( "\n\n*** TEST 26 ***" );

    task1();
    /* does not return */
    puts( "Init - task1 should not have returned" );
    exit( 0 );
}
Exemple #13
0
void firsttask(void *arg) {
	POSTASK_t  t;
	UVAR_t i;

	posAtomicSet(&counter, 0);

	/* creating the flag */
	flagset = posFlagCreate();
  
	if (flagset == NULL)
	{
		nosPrint("Failed to create a set of flags!\n");
		return;
	}

	/* creating semaphore object with set one default value */
	semaphore = posSemaCreate(1);

	if (semaphore == NULL){
		
		nosPrint("Failed to create a semaphore!\n");
		return;
	}

	t = nosTaskCreate(task2,    /* ptr to function:  task2 that is executed 	*/
		NULL,					/* optional argument, not used here             */
		1,						/* priority of the first task                   */
		0,						/* stack size for the first task, 0 = default   */
		"task2");				/* task name       								*/

	if (t == NULL) {
		nosPrint("Failed to start second task!\n");
	}

	t = nosTaskCreate(task3,    /* ptr to function: task3 that is executed */
                    NULL,       /* optional argument, not used here             */
                    1,          /* priority of the first task                   */
                    0,          /* stack size for the first task, 0 = default   */
                    "task3");   /* task name       				*/

	if (t == NULL) {
		nosPrint("Failed to start third task!\n");
	}

	/* first flag status change */
	posFlagSet(flagset, 1);
	
  	/* task1 handled */
	task1(arg);
}
Exemple #14
0
int main()
{
  int i, sleepTime;
  // The condition the threads will be using
  ArCondition cond;
  // The threads
  Task task1(1, &cond);
  Task task2(2, &cond);
  Task task3(3, &cond);
  Task task4(4, &cond);

  // Initialize Aria, which in turn initializes the thread layer
  Aria::init();

  // Initialize the rand() function
  srand((unsigned)time(NULL));

  // Lets start all correct threads.
  task1.create();
  task2.create();
  task3.create();
  task4.create();

  // Lets wake up the threads at different random times
  for (i=0; i<10; ++i)
  {
    sleepTime=rand()%400+100;
    printf("Main: Sleeping %dms\n", sleepTime);
    ArUtil::sleep(sleepTime);
    printf("Main: Waking up a thread\n");
    cond.signal();
  }

  printf("Exiting\n");

  // Stop all the threads, which sets their running variable to false
  ArThread::stopAll();

  // Now that all the threads are marked as not running, wake them up
  // so that we can exit the program gracefully.
  cond.broadcast();

  // Wait for all the threads to exit
  ArThread::joinAll();

  // Uninit Aria
  Aria::uninit();

  return(0);
}
/* This is the first function that is called in the multitasking context.
 * (See file ex_init4.c for how to setup pico]OS).
 */
void firsttask(void *arg)
{
  POSTASK_t  t;

  posAtomicSet(&counter, 0);

  /* Create a semaphore, initialize to 2.
   * You may vary the initialization count between
   * 1 and 3 and observe the output of this program.
   *
   * The initialization semaphore count limits the number
   * of tasks that are allowed to access a shared resource
   * at the same time.
   */
  semaphore = posSemaCreate(2);

  if (semaphore == NULL)
  {
    nosPrint("Failed to create a semaphore!\n");
    return;
  }

  /* start a second task */
  t = nosTaskCreate(task2,      /* pointer to new task-function            */
                    NULL,       /* optional argument for the task-function */
                    2,          /* priority level of the new task          */
                    0,          /* stack size (0 = default size)           */
                    "task2");   /* optional name of the second task        */

  if (t == NULL)
  {
    nosPrint("Failed to start second task!\n");
  }

  /* start a second task */
  t = nosTaskCreate(task3,      /* pointer to new task-function            */
                    NULL,       /* optional argument for the task-function */
                    3,          /* priority level of the new task          */
                    0,          /* stack size (0 = default size)           */
                    "task3");   /* optional name of the third task         */

  if (t == NULL)
  {
    nosPrint("Failed to start third task!\n");
  }

  /* continue execution in function task1 */
  task1(arg);
}
int main() {
    // task 1
    std::packaged_task<int(int)> task1(mult2);
    std::future<int> fut1 = task1.get_future();
    task1(3);
    std::cout << fut1.get() << std::endl;

    // task 2
    std::packaged_task<long(int)> task2(mult2);
    std::future<long> fut2 = task2.get_future();
    task2(4);
    std::cout << fut2.get() << std::endl;

    // task 3
    std::packaged_task<int(int)> task3(mult2);
    task3(5);
    std::future<int> fut3 = task3.get_future();
    std::cout << fut3.get() << std::endl;

    // task 4
    std::packaged_task<void()> task4([]{std::cout << "void" << std::endl;});
    task4();
    task4.get_future().get();
}
int main() {

	std::thread task1(foo);
	std::thread task2(bar, 5, 2);

	std::cout << "main, foo and bar now execute concurrently...\n";

	// synchronize threads:
	task1.join();                // pauses until first finishes
	task2.join();               // pauses until second finishes

	std::cout << "foo and bar completed.\nNow I'll finish\n";

	return 0;
}
int main(int argc, char *argv[])
{
    int a = 5;

    task1(&a);

#pragma omp taskwait

    if (a != 7)
    {
        fprintf(stderr, "a == %d != 7\n", a);
        abort();
    }

    return 0;
}
Exemple #19
0
int main(int argc, const char * argv[]) {
    // insert code here...
    int t;
    printf("Меню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n");
    printf("Выберите номер задания\n");
    scanf("%d",&t);
    while(t!=6)
    {
        switch(t)
        {
            case 1:
            {
                printf("Все числа от 1 до n\n");
                task1();
                break;
            }
            case 2:
            {
                printf("Все числа от А до В\n");
                task2();
                break;
            }
            case 3:
            {
                printf("Функция Аккермана\n");
                task3();
                break;
            }
            case 4:
            {
                printf("Точная степень двойки\n");
                task4();
                break;
            }
            case 5:
            {
                printf("Сумма цифр числа\n");
                task5();
                break;
            }
        }
        printf("\nМеню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n");
        printf("Выберите номер задания\n");
        scanf("%d",&t);
    }
    return 0;
}
void
runTestMulti()
{
#if defined(DEBUG)
  os::diag::trace.putString(__PRETTY_FUNCTION__);
  os::diag::trace.putNewLine();
#endif

  ts.setClassName("os::core::Thread");
  ts.setFunctionNameOrPrefix("sleep()");

  Task task1("T1", hal::arch::MIN_STACK_SIZE);
  Task task2("T2", hal::arch::MIN_STACK_SIZE);
  Task task3("T3", hal::arch::MIN_STACK_SIZE);
  Task task4("T4", hal::arch::MIN_STACK_SIZE);
  Task task5("T5", hal::arch::MIN_STACK_SIZE);

  Task* taskArray[5] =
    { &task1, &task2, &task3, &task4, &task5 };

  for (auto pTask : taskArray)
    {
      ts.setPreconditions(pTask->getName());
      ts.assertCondition(pTask->getCount() == 0);
    }

  for (auto pTask : taskArray)
    {
      ts.assertCondition(pTask->getThread().start());
    }

  for (auto pTask : taskArray)
    {
      pTask->getThread().join();
    }

  for (auto pTask : taskArray)
    {
      ts.setPreconditions(pTask->getName());
      ts.assertCondition(
          ((pTask->getDeltaTicks() - pTask->getCount())
              <= pTask->getSleepCalls()));
    }

}
void BackendIntegrationTests::simpleCreateModifyDeleteTaskTest()
{
    Task task1( 1000, "Task 1" );
    Task task1b( task1 );
    task1b.setName( "Task 1, modified" );
    // add:
    controller()->addTask( task1 );
    QVERIFY( controller()->storage()->getAllTasks().size() == 1 );
    QVERIFY( controller()->storage()->getAllTasks().first() == task1 );
    QVERIFY( model()->taskTreeItem( task1.id() ).task() == task1 );
    // modify:
    controller()->modifyTask( task1b );
    QVERIFY( controller()->storage()->getAllTasks().size() == 1 );
    QVERIFY( controller()->storage()->getAllTasks().first() == task1b );
    QVERIFY( model()->taskTreeItem( task1.id() ).task() == task1b );
    // delete:
    controller()->deleteTask( task1 );
    QVERIFY( controller()->storage()->getAllTasks().size() == 0 );
    QVERIFY( model()->taskTreeItem( 0 ).childCount() == 0 );
}
const TaskList& BackendIntegrationTests::referenceTasks()
{
    static TaskList Tasks;
    if ( Tasks.isEmpty() ) {
        Task task1( 1000, "Task 1" );
        Task task1_1( 1001, "Task 1-1", task1.id() );
        Task task1_2( 1002, "Task 1-2", task1.id() );
        Task task1_3( 1003, "Task 1-3", task1.id() );
        Task task2( 2000, "Task 2" );
        Task task2_1( 2100, "Task 2-1", task2.id() );
        Task task2_1_1( 2110, "Task 2-1-1", task2_1.id() );
        Task task2_1_2( 2120, "Task 2-1-2", task2_1.id() );
        Task task2_2( 2200, "Task 2-2", task2.id() );
        Task task2_2_1( 2210, "Task 2-2-1", task2_2.id() );
        Task task2_2_2( 2220, "Task 2-2-2", task2_2.id() );
        Tasks << task1 << task1_1 << task1_2 << task1_3
              << task2 << task2_1 << task2_1_1 << task2_1_2
              << task2_2 << task2_2_1 << task2_2_2;
    }
    return Tasks;
}
Exemple #23
0
void auto_ctrl(void)
{
	static char L1_count = 0;
	static char old_L1;

	if (PSCON_PRE_L1>0 && D_direction_U>0)task_final();
	else if (PSCON_PRE_L1>0 && D_direction_D>0)task_home();
	else if(PSCON_PRE_L2>0)task_center();
	else
	{ 
		if (PSCON_PRE_L1>0 && L1_count == 1)task1();
		if (PSCON_PRE_L1>0 && L1_count == 2)task_center();
		if (PSCON_PRE_L1>0 && L1_count == 3)task_home();
		if (PSCON_PRE_L1>0 && L1_count == 4)task_final();
		if (PSCON_PRE_L1>0 && L1_count > 4)task_home();
		
		if (PSCON_PRE_L1>0 && old_L1 == 0)L1_count++;
		old_L1 = PSCON_PRE_L1;
	}

}
Exemple #24
0
void CharmDataModelTests::initTestCase ()
{
    // set up a model that the other tests can clone to use:
    m_referenceModel = new CharmDataModel;
    Task task1( 1000, "Task 1" );
    Task task1_1( 1001, "Task 1-1", task1.id() );
    Task task1_2( 1002, "Task 1-2", task1.id() );
    Task task1_3( 1003, "Task 1-3", task1.id() );
    Task task2( 2000, "Task 2" );
    Task task2_1( 2100, "Task 2-1", task2.id() );
    Task task2_1_1( 2110, "Task 2-1-1", task2_1.id() );
    Task task2_1_2( 2120, "Task 2-1-2", task2_1.id() );
    Task task2_2( 2200, "Task 2-2", task2.id() );
    Task task2_2_1( 2210, "Task 2-2-1", task2_2.id() );
    Task task2_2_2( 2220, "Task 2-2-2", task2_2.id() );
    TaskList tasks;
    tasks << task1 << task1_1 << task1_2 << task1_3
          << task2 << task2_1 << task2_1_1 << task2_1_2
          << task2_2 << task2_2_1 << task2_2_2;
    // test setAllTasks, only slightly, more detailed tests follow
    m_referenceModel->setAllTasks( tasks );
    QVERIFY( m_referenceModel->taskTreeItem( task2_2.id() ).childCount() == 2 );
    QVERIFY( m_referenceModel->taskTreeItem( task2.id() ).childCount() == 2 );
}
Exemple #25
0
/* This is the first function that is called in the multitasking context.
 * (See file ex_init4.c for how to setup pico]OS).
 */
void firsttask(void *arg)
{
  POSTASK_t  t;

  /* Note: You may uncomment the source below by setting the #if to
   *       zero and then observe the output of this program.
   *       This is a nice example of how synchronization works.
   */
#if 1

  /* create a mutex */
  mutex = posMutexCreate();

  if (mutex == NULL)
  {
    nosPrint("Failed to create a mutex!\n");
    return;
  }

#endif

  /* start a second task */
  t = nosTaskCreate(task2,      /* pointer to new task-function            */
                    NULL,       /* optional argument for the task-function */
                    2,          /* priority level of the new task          */
                    0,          /* stack size (0 = default size)           */
                    "task2");   /* optional name of the second task        */

  if (t == NULL)
  {
    nosPrint("Failed to start second task!\n");
  }

  /* continue execution in function task1 */
  task1(arg);
}
Exemple #26
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {

      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      // Resolve HomeFinder interface
      CORBA::Object_var obj1
        = orb->string_to_object (ior1);

      CORBA::Object_var obj2
        = orb->string_to_object (ior2);

      CORBA::Object_var obj3
        = orb->string_to_object (ior3);

      CORBA::Object_var obj4
        = orb->string_to_object (ior4);

      if (CORBA::is_nil (obj1.in ()) ||
          CORBA::is_nil (obj2.in ()) ||
          CORBA::is_nil (obj3.in ()) ||
          CORBA::is_nil (obj4.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Nil Benchmark::RoundtripClient reference\n"),
                            1);
        }

      //Narrow to appropriate interfaces
      Benchmark::RoundTripClient_var client1=
        Benchmark::RoundTripClient::_narrow (obj1.in());

      Benchmark::RoundTripClient_var client2=
        Benchmark::RoundTripClient::_narrow (obj1.in());

      Benchmark::RoundTripClient_var client3=
        Benchmark::RoundTripClient::_narrow (obj1.in());

      Benchmark::RoundTripClient_var client4=
        Benchmark::RoundTripClient::_narrow (obj1.in());

      //Create Tasks
      Client_Task task1(client1.in());
      Client_Task task2(client2.in());
      Client_Task task3(client3.in());
      Client_Task task4(client4.in());

      task1.activate(THR_NEW_LWP | THR_JOINABLE);
      task2.activate(THR_NEW_LWP | THR_JOINABLE);
      task3.activate(THR_NEW_LWP | THR_JOINABLE);
      task4.activate(THR_NEW_LWP | THR_JOINABLE);

      task1.thr_mgr()->wait();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception Caught:");
      return 1;
    }
  return 0;
}
//
//  a task gets dispatched on every tick_flag tick (10ms)
//
void task_dispatch(void)
{
  /* scan the task bits for an active task and execute it */

  char task;
    

/* take care of the task timers. if the value ==0 skip it
    else decrement it. If it decrements to zero, activate the task associated with it */

  task=0;
  while (task < NUM_TASKS )
    {
    if (task_timers[task])
       {
       task_timers[task]--;            /* dec the timer */
       if (task_timers[task] == 0 )
            {
            set_task(task); /* if ==0 activate the task bit */
            }
       }
    task++;
    }

  task = 0; /* start at the most significant task */
  while (task <= NUM_TASKS )
    {
      if ((task_bits & pgm_read_byte(&bit_mask[task])))
            {
            break; /* if activate task found..*/
            }
      task++;         /* else try the next one */
    }
  switch(task)            /* if task bit is active..execute the task */
    {
    case 0:
      task0();
      break;
    case 1:
      task1();
      break;
    case 2:
      task2();
      break;
    case 3:
      task3();
      break;
    case 4:
      task4();
      break;
    case 5:
      task5();
      break;
    case 6:
      task6();
      break;
    case 7:
      task7();
      break;
    default:
      break;                  /* no task was active!! */
    }                       
}
Exemple #28
0
    void Scheduler_ut::test_schedules()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        Task_db::value_t task_props;
        Scheduler &sched = Scheduler::get_instance();
#if 0

        /* Halt the scheduler.
         */
        sched.stop();

        /* Store the task properties.
         */
        task_props.prio = 98;
        task_props.period = sched_period;

        CPPUNIT_ASSERT_EQUAL(true, sched.set_properties(task_props));
#endif

        CPPUNIT_ASSERT_EQUAL((unsigned)0, sched.get_schedule());

        for(schedule_t i = 0; i < 32; ++i)
        {
            sched.set_schedule(i);
            CPPUNIT_ASSERT_EQUAL(i, sched.get_schedule());
        }

        /* Create the tasks and make sure they're valid.
         */
        task_props.period = units::Nanoseconds(20 * units::MSEC);
        task_props.prio = higher_priority;
        task_props.schedule_presence = 0x000A; // 1010
        Test_task task1("task_1", 1);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(task_props));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        task_props.prio = lower_priority;
        task_props.schedule_presence = 0x000D; // 1101
        Test_task task2("task_2", 2);
        CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(task_props));
        CPPUNIT_ASSERT_EQUAL(true, task2.is_valid());

        sched.set_schedule(31);

        /* Off to the races.
         */
        CPPUNIT_ASSERT_EQUAL(true, task1.start());
        CPPUNIT_ASSERT_EQUAL(true, task2.start());
        // CPPUNIT_ASSERT_EQUAL(true, sched.start());

        IPRINTF("\nTesting multiple schedules.\n"
                "This test will take at least 4 seconds to complete.\n");
        for(int i = 0; i < 4; ++i)
        {
            sched.set_schedule(i);

            /* Not the most reliable timing method.
             */
            sleep(units::Nanoseconds(1 * units::SEC));

            sched.set_schedule(31);

            /* Check the counters to see if the counts match. Allow some
             * variance to account for the imprecision of halting the task
             * based on a timer.
             */
            if(task1.is_present_in_schedule(i))
            {
                CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60));
            }
            else
            {
                CPPUNIT_ASSERT_EQUAL(0, counter[1]);
            }

            if(task2.is_present_in_schedule(i))
            {
                CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60));
            }
            else
            {
                CPPUNIT_ASSERT_EQUAL(0, counter[2]);
            }

            counter[1] = 0;
            counter[2] = 0;
        }

        DPRINTF("Halting all test tasks\n");
        DPRINTF("Stopping task 1\n");
        task1.stop();
        DPRINTF("Stopping task 2\n");
        task2.stop();

        sched.set_schedule(0);
        CPPUNIT_ASSERT_EQUAL((unsigned)0, sched.get_schedule());
    }
Exemple #29
0
void CharmDataModelTests::addAndRemoveTasksTest()
{   // set up a structure of tasks:
    Task task1( 1000, "Task 1" );
    Task task1_1( 1001, "Task 1-1", task1.id() );
    Task task1_2( 1002, "Task 1-2", task1.id() );
    Task task1_3( 1003, "Task 1-3", task1.id() );
    Task task2( 2000, "Task 2" );
    Task task2_1( 2100, "Task 2-1", task2.id() );
    Task task2_1_1( 2110, "Task 2-1-1", task2_1.id() );
    Task task2_1_2( 2120, "Task 2-1-2", task2_1.id() );
    Task task2_2( 2200, "Task 2-2", task2.id() );
    Task task2_2_1( 2210, "Task 2-2-1", task2_2.id() );
    Task task2_2_2( 2220, "Task 2-2-2", task2_2.id() );

    // set up a data model, and add all the tasks to it, step by step:
    CharmDataModel model;
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 0 );
    model.addTask( task1 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 0 );
    model.addTask( task1_1 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 1 );
    model.addTask( task1_2 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 2 );
    model.addTask( task1_3 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 3 );
    model.addTask( task2 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 2 );
    model.addTask( task2_1 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 1 );
    model.addTask( task2_2 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );
    QVERIFY( model.taskTreeItem( task2_1.id() ).childCount() == 0 );
    model.addTask( task2_1_1 );
    QVERIFY( model.taskTreeItem( task2_1.id() ).childCount() == 1 );
    model.addTask( task2_1_2 );
    QVERIFY( model.taskTreeItem( task2_1.id() ).childCount() == 2 );
    QVERIFY( model.taskTreeItem( task2_2.id() ).childCount() == 0 );
    model.addTask( task2_2_1 );
    QVERIFY( model.taskTreeItem( task2_2.id() ).childCount() == 1 );
    model.addTask( task2_2_2 );
    QVERIFY( model.taskTreeItem( task2_2.id() ).childCount() == 2 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );

    // now the whole game in reverse: remove tasks, one by one:
    model.deleteTask( task2_2_2 );
    QVERIFY( model.taskTreeItem( task2_2.id() ).childCount() == 1 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );
    model.deleteTask( task2_2_1 );
    QVERIFY( model.taskTreeItem( task2_2.id() ).childCount() == 0 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );
    model.deleteTask( task2_1_1 );
    QVERIFY( model.taskTreeItem( task2_1.id() ).childCount() == 1 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );
    model.deleteTask( task2_1_2 );
    QVERIFY( model.taskTreeItem( task2_1.id() ).childCount() == 0 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 2 );
    model.deleteTask( task2_2 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 1 );
    model.deleteTask( task2_1 );
    QVERIFY( model.taskTreeItem( task2.id() ).childCount() == 0 );
    model.deleteTask( task2 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    model.deleteTask( task1_2 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 2 );
    model.deleteTask( task1_3 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 1 );
    model.deleteTask( task1_1 );
    QVERIFY( model.taskTreeItem( task1.id() ).childCount() == 0 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 1 );
    model.deleteTask( task1 );
    QVERIFY( model.taskTreeItem( 0 ).childCount() == 0 );
}
Exemple #30
0
    void Scheduler_ut::test_tasks()
    {
        IPRINTF("\nExecuting %s\n", __func__);
        /* Create the tasks.
         */
        Task_properties tprops;
        tprops.period = units::Nanoseconds(20 * units::MSEC);
        tprops.prio = higher_priority;
        Test_task task1("task_2_1", 1);
        CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task1.is_valid());

        tprops.prio = lower_priority;
        Test_task task2("task_2_2", 2);
        CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task2.is_valid());

        tprops.period = units::Nanoseconds(10 * units::MSEC);
        tprops.prio = highest_priority;
        Test_task task3("task_1_3", 3);
        CPPUNIT_ASSERT_EQUAL(true, task3.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task3.is_valid());

        tprops.period = units::Nanoseconds(40 * units::MSEC);
        tprops.prio = lowest_priority;
        Test_task task4("task_4_4", 4);
        CPPUNIT_ASSERT_EQUAL(true, task4.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task4.is_valid());

        /* Set up this task with invalid period (faster than the scheduler).
         */
        tprops.period = units::Nanoseconds(sched_period / 2);
        tprops.prio = lowest_priority;
        Test_task task5("task_invalid_period", 5);
        CPPUNIT_ASSERT_EQUAL(true, task5.set_properties(tprops));
        CPPUNIT_ASSERT_EQUAL(true, task5.is_valid());

        /* Runtimes should be zero before the task starts.
         */
        units::Nanoseconds last_runtime = task1.get_last_runtime();
        CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), last_runtime);
        CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), task1.get_max_runtime());

        /* Off to the races.
         */
        task_terminated = false;
        CPPUNIT_ASSERT_EQUAL(true, task1.start());
        CPPUNIT_ASSERT_EQUAL(true, task2.start());
        CPPUNIT_ASSERT_EQUAL(true, task3.start());
        CPPUNIT_ASSERT_EQUAL(true, task4.start());

        IPRINTF("\nTesting invalid period, an error is expected\n");
        CPPUNIT_ASSERT_EQUAL(false, task5.start());

        /* Not the most reliable timing method.
         */
        sleep(units::Nanoseconds(1 * units::SEC));

        /* Stop the tasks so the counters stop incrementing. This makes
         * cleanup faster too.
         */
        DPRINTF("Halting all test tasks\n");
        DPRINTF("Stopping task 1\n");
        task1.stop();
        DPRINTF("Stopping task 2\n");
        task2.stop();
        DPRINTF("Stopping task 3\n");
        task3.stop();
        DPRINTF("Stopping task 4\n");
        task4.stop();
        CPPUNIT_ASSERT_EQUAL(true, task_terminated);

        /* Check the counters to see if the counts match. Allow some variance
         * to account for the imprecision of halting the task based on a
         * timer.
         */
        CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60));
        CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60));
        CPPUNIT_ASSERT((counter[3] >= 98) && (counter[3] <= 110));
        CPPUNIT_ASSERT((counter[4] >= 23) && (counter[4] <= 35));

        /* Check that the runtimes are reasonable.
         */
        last_runtime = task1.get_last_runtime();
        IPRINTF("last_runtime = %" PRId64 "\n", int64_t(last_runtime));
        CPPUNIT_ASSERT(last_runtime > units::Nanoseconds(0));
        CPPUNIT_ASSERT(task1.get_max_runtime() >= last_runtime);
    }