summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Sched/Scheduler_Generic.h
blob: b007c81109e5c9b5810319f2fef3237f2218da83 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Scheduler_Generic.h
 *
 *  @author David Levine
 */
//=============================================================================


#ifndef SCHEDULER_INTERNAL_H
#define SCHEDULER_INTERNAL_H
#include /**/ "ace/pre.h"

#include "orbsvcs/Sched/Scheduler.h"
#include "ace/Unbounded_Set.h"
#include "ace/Synch_Traits.h"
#include "ace/Recursive_Thread_Mutex.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class Scheduler_Generic
 *
 * @brief Implementation of an off-line scheduler.
 *
 * Schedules tasks, assigning the same priority to all of them.
 */
class TAO_RTSched_Export Scheduler_Generic : public ACE_Scheduler
{
public:
  Scheduler_Generic ();
  virtual ~Scheduler_Generic ();

  // = Initialize the scheduler.
  virtual void init (const int minimum_priority,
                     const int maximum_priority,
                     const char *runtime_filename = 0,
                     const char *rt_info_filename = 0,
                     const char *timeline_filename = 0);

  // = Registers a task.
  virtual status_t register_task (RT_Info *[],
                                  const u_int number_of_modes,
                                  handle_t &handle);

  /// Obtains an RT_Info based on its "handle".
  virtual status_t lookup_rt_info (handle_t handle,
                                   RT_Info* &rtinfo);

  /// Obtains a Config_Info based on its priority.
  virtual status_t lookup_config_info (Preemption_Priority priority,
                                       Config_Info* &config_info);

  // = Computes the schedule.
  virtual status_t
    schedule (ACE_Unbounded_Set<Scheduling_Anomaly *> &anomaly_set);

  // = Access a thread priority.
  /**
   * Defines "priority" as the priority that was assigned to the Task that
   * was assigned "handle", for the specified mode.  Defines "subpriority"
   * as the relative ordering (due to dependencies) within the priority.
   * Returns 0 on success, or 1 if an invalid mode or handle are supplied.
   */
  virtual int priority (const handle_t handle,
                        OS_Thread_Priority &priority,
                        Sub_Priority &subpriority,
                        Preemption_Priority &preemption_prio,
                        const mode_t = CURRENT_MODE) const;

private:
  /// The number of task handles dispensed so far.
  u_int handles_;

  /// The minimum priority value that the application specified (in
  /// its call to init ()).
  int minimum_priority_;

  /// The maximum priority value that the application specified (in
  /// its call to init ()).
  int maximum_priority_;

  /// Destination file of Scheduler output from the configuration run.
  const char *runtime_filename_;

  /// Destination file of all rt_info data from the configuration run.
  const char *rt_info_filename_;

  /// The destination of the timeline.
  const char *timeline_filename_;

  /**
   * Set to 1 if priority values increase with increasing priority,
   * such as on Solaris and Win32, or 0 if they decrease, such as on
   * VxWorks.
   */
  int increasing_priority_;

  /// Collection of known tasks.
  ACE_Unbounded_Set <RT_Info **> task_entries_;

  /// dispatchin configuration info
  Config_Info config_info_;

#if defined (ACE_HAS_THREADS)
  typedef TAO_SYNCH_RECURSIVE_MUTEX LOCK;
#else
  typedef ACE_Null_Mutex LOCK;
#endif /* ACE_HAS_THREADS */

  /// This protects access to the scheduler during configuration runs.
  LOCK lock_;


  ///////////////////////////////////////
  // member functions for internal use //
  ///////////////////////////////////////

  /// Prepare for another schedule computation, but do not
  /// disturb the "output" (priorities that have already been assigned).
  void reset ();

  /// Display the schedule, task-by-task.
  void print_schedule ();

  Scheduler_Generic (const Scheduler_Generic &);
  Scheduler_Generic &operator= (const Scheduler_Generic &);
};

TAO_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"
#endif /* SCHEDULER_INTERNAL_H */

// EOF