summaryrefslogtreecommitdiff
path: root/ace/Thread_Priority.h
blob: 4e6cd5b68e8f76c3a25154938f5d8625bcdc2da3 (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
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    ACE
//
// = FILENAME
//    Thread_Priority.h
//
// = CREATION DATE
//    28 January 1997
//
// = AUTHOR
//    David Levine
//
// ============================================================================

#if ! defined (ACE_THREAD_PRIORITY_H)
#define ACE_THREAD_PRIORITY_H

class ACE_Export ACE_Thread_Priority
  // = TITLE
  //    Provides OS-independent scheduling priority classes and thread
  //    priorities.
  //
  // = DESCRIPTION
  //    ACE_Thread_Priority provides OS-independent scheduling priority
  //    classes and thread priority values.  Applications that use
  //    these priority values don't have to be concerned that lower
  //    values indicate higher thread priorities on some platforms but
  //    lower on others.  ACE_Thread_Priorities are typically used with
  //    ACE_Scheduling_Parameters to specify scheduling behavior to the
  //    OS.
{
public:
  enum Priority_Class
  {
    ACE_LOW_PRIORITY_CLASS,
    ACE_NORMAL_PRIORITY_CLASS,
    ACE_HIGH_PRIORITY_CLASS,
    ACE_REALTIME_PRIORITY_CLASS
  };

  enum Thread_Priority
  {
    ACE_PRIORITY_0 = 0,
    ACE_PRIORITY_MIN = ACE_PRIORITY_0,
    ACE_PRIORITY_1,
    ACE_PRIORITY_2,
    ACE_PRIORITY_3,
    ACE_PRIORITY_4,
    ACE_PRIORITY_5,
    ACE_PRIORITY_6,
    ACE_PRIORITY_MAX = ACE_PRIORITY_6
  };
  // = This enum helps users create OS-independent priorities.
  //
  // For applications that don't require OS- independence, they can
  // take advantage of a greater range of thread priorities offered by
  // their platform.  This can be done by casting the OS-specific
  // priority to ACE_Thread_Priority::Thread_Priority when calling the
  // member functions that take it as an argument.  In other words,
  // this class will not "break" if a Thread_Priority outside of
  // [ACE_PRIORITY_MIN .. ACE_PRIORITY_MAX] is used.

  // = NOTE
  //
  // the following distinct ACE_Thread_Priority combinations map to
  // identical priority class/thread priority combinations on Win32.
  // They may map to distinct priorities on other platforms.  So, if
  // OS-independent behavior is desired, applications should not
  // depend on these having either the same or different OS-specific
  // priorities:
  //
  // * ACE_LOW_PRIORITY_CLASS/ACE_PRIORITY_0 ==
  //       ACE_NORMAL_PRIORITY_CLASS/ACE_PRIORITY_0 ==
  //       ACE_HIGH_PRIORITY_CLASS/ACE_PRIORITY_0
  // * ACE_NORMAL_PRIORITY_CLASS/ACE_PRIORITY_5 ==
  //       ACE_HIGH_PRIORITY_CLASS/ACE_PRIORITY_1
  // * ACE_LOW_PRIORITY_CLASS/ACE_PRIORITY_6 ==
  //       ACE_NORMAL_PRIORITY_CLASS/ACE_PRIORITY_6 ==
  //       ACE_HIGH_PRIORITY_CLASS/ACE_PRIORITY_5 ==
  //       ACE_HIGH_PRIORITY_CLASS/ACE_PRIORITY_6

  ACE_Thread_Priority (Priority_Class priority_class = ACE_NORMAL_PRIORITY_CLASS,
                       Thread_Priority default_thread_priority = ACE_PRIORITY_MIN);
  // There can be more than one ACE_Thread_Priority instance per
  // process, e.g., one per Solaris Lightweight Process.

  ~ACE_Thread_Priority (void);

  // = Set/Get accessors for priority class.
  long priority_class (const Priority_Class);
  // Return 0 on success and -1 on failure (and sets errno).
  Priority_Class priority_class (void) const;

  // = Set/Get accessors for default thread priority.
  long default_thread_priority (const Thread_Priority);
  // Return 0 on success and -1 on failure (and sets errno).
  Thread_Priority default_thread_priority (void) const;

  ACE_id_t os_priority_class (void) const;
  // Get accessor for the OS-specific priority class.

  ACE_pri_t os_default_thread_priority (void) const;
  // Get accessor for the numeric default thread priority value, which
  // is OS-dependent.

private:
  Priority_Class priority_class_;
  // Priority class of this thread, OS-independent.

  Thread_Priority default_thread_priority_;
  // Default thread priority value, OS-independent.

  ACE_id_t os_priority_class_;
  // OS-specific value of priority_class_.

  ACE_pri_t os_default_thread_priority_;
  // OS-specific value of default_thread_priority_.

  long convert_to_os_priority (void);
  // Convert OS-independent priorities into OS-specific priorities.
};

#if defined (__ACE_INLINE__)
#include "ace/Thread_Priority.i"
#endif /* __ACE_INLINE__ */

#endif /* ACE_THREAD_PRIORITY_H */