summaryrefslogtreecommitdiff
path: root/Kokyu/tests/DSRT_MIF/MIF.cpp
blob: 136523c8aaa7efce16c3578ea2452848ead7425e (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// $Id$

#include "ace/Auto_Ptr.h"

#include "Kokyu.h"
#include "ace/Task.h"
#include "ace/Sched_Params.h"

class MyTask : public ACE_Task_Base
{
public:

  MyTask (ACE_Barrier& barrier,
          Kokyu::DSRT_Dispatcher* dispatcher,
          Kokyu::DSRT_QoSDescriptor& qos)
    :barrier_ (barrier),
     dispatcher_ (dispatcher),
     qos_ (qos)
  {}

  int svc (void)
  {
    ACE_hthread_t thr_handle;
    ACE_Thread::self (thr_handle);
    int prio;

    prio = dispatcher_->schedule (0, qos_);
    ACE_Thread::setprio (thr_handle, prio);
    barrier_.wait ();

    if (ACE_Thread::getprio (thr_handle, prio) == -1)
      {
        if (errno == ENOTSUP)
          {
            ACE_DEBUG((LM_DEBUG,
                       ACE_TEXT ("getprio not supported on this platform\n")
                       ));
            return 0;
          }
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("%p\n"),
                           ACE_TEXT ("getprio failed")),
                          -1);
      }

    ACE_DEBUG ((LM_DEBUG, "(%t) Thread prio is %d\n", prio));
    return 0;
  }

private:
  ACE_Barrier& barrier_;
  Kokyu::DSRT_Dispatcher* dispatcher_;
  Kokyu::DSRT_QoSDescriptor& qos_;

};

int main (int,char**)
{
  Kokyu::DSRT_ConfigInfo config_info;

  //  config_info.scheduler_type_ = Kokyu::SCHED_MIF;

  ACE_Barrier barrier (3);

  ACE_DEBUG ((LM_DEBUG, "before create_dispatcher\n" ));
  auto_ptr<Kokyu::DSRT_Dispatcher>
    disp (Kokyu::Dispatcher_Factory::create_DSRT_dispatcher (config_info));

  ACE_DEBUG ((LM_DEBUG, "after create_dispatcher\n" ));

  ACE_ASSERT (disp.get () != 0);

  Kokyu::DSRT_QoSDescriptor qos1, qos2, qos3;

  qos1.importance_ = 1;
  qos2.importance_ = 2;
  qos3.importance_ = 3;

  MyTask mytask1 (barrier, disp.get (), qos1);
  MyTask mytask2 (barrier, disp.get (), qos2);
  MyTask mytask3 (barrier, disp.get (), qos3);

  long flags = THR_BOUND | THR_SCHED_FIFO;

  if (mytask1.activate (flags) == -1)
    {
      flags = THR_BOUND;
      if (mytask1.activate (flags) == -1)
        ACE_ERROR ((LM_ERROR,
                        "EC (%P|%t) cannot activate task\n"));
    }

  if (mytask2.activate (flags) == -1)
    {
      flags = THR_BOUND;
      if (mytask2.activate (flags) == -1)
        ACE_ERROR ((LM_ERROR,
                        "EC (%P|%t) cannot activate task\n"));
    }

  if (mytask3.activate (flags) == -1)
    {
      flags = THR_BOUND;
      if (mytask3.activate (flags) == -1)
        ACE_ERROR ((LM_ERROR,
                        "EC (%P|%t) cannot activate task\n"));
    }

  while(1){}

  return 0;
}