summaryrefslogtreecommitdiff
path: root/ACE/TAO/examples/RTScheduling/MIF_Scheduler/MIF_DT_Creator.cpp
blob: fd82206321097e47a376231bc63d760e9c35c44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//$Id$

#include "MIF_DT_Creator.h"
#include "test.h"
#include "MIF_Task.h"

MIF_DT_Creator::MIF_DT_Creator (void)
{
  DT_TEST::instance ()->dt_creator (this);
}

Thread_Task*
MIF_DT_Creator::create_thr_task (int importance,
                                 time_t start_time,
                                 int load,
                                 int iter,
                                 int dist,
                                 char *job_name)
{
  MIF_Task* task;
  ACE_NEW_RETURN (task,
                  MIF_Task (importance,
                            start_time,
                            load,
                            iter,
                            dist,
                            job_name,
                            this),
                  0);
  return task;
}

CORBA::Policy_ptr
MIF_DT_Creator::sched_param (int importance)
{
  return DT_TEST::instance ()->scheduler ()->create_segment_scheduling_parameter (importance);
}

void
MIF_DT_Creator::yield (time_t suspend_time,
                       Thread_Task*)
{
  try
    {
      CORBA::Object_var object =
        this->orb_->resolve_initial_references ("RTScheduler_Current");
      RTScheduling::Current_var current =
        RTScheduling::Current::_narrow (object.in ());

      ACE_Time_Value const sus_time_value (suspend_time);
      ACE_Time_Value now (ACE_OS::gettimeofday ());
      while (((now - *base_time_) < sus_time_value) || (suspend_time == 1))
        {

          ACE_OS::sleep (1);
          CORBA::Policy_var sched_param;
          sched_param = CORBA::Policy::_duplicate (this->sched_param (100));
          const char * name = 0;
          current->update_scheduling_segment (name,
                                              sched_param.in (),
                                              sched_param.in ());
          now = ACE_OS::gettimeofday ();
          if (suspend_time == 1)
            break;
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
    }
}

int
MIF_DT_Creator::total_load (void)
{
  return 1000;
}

void
MIF_DT_Creator::wait (void)
{
  while (active_dt_count_ > 0 || active_job_count_ > 0)
    {
      yield(1,0);
    }
}

ACE_STATIC_SVC_DEFINE(MIF_DT_Creator,
                      ACE_TEXT ("MIF_DT_Creator"),
                      ACE_SVC_OBJ_T,
                      &ACE_SVC_NAME (MIF_DT_Creator),
                      ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
                      0)

ACE_FACTORY_DEFINE (ACE_Local_Service, MIF_DT_Creator)