#include <EC_Thread_Flags.h>
Collaboration diagram for TAO_EC_Thread_Flags:
Public Member Functions | |
TAO_EC_Thread_Flags () | |
TAO_EC_Thread_Flags (const char *symbolic_flags) | |
See operator=(). | |
~TAO_EC_Thread_Flags () | |
const TAO_EC_Thread_Flags & | operator= (const char *symbolic_flags) |
Assign a new set of symbolic flags, setting flags, scope, and sched as possible. | |
long | flags () const |
Returns numeric equivalent of the thread flags suitable for passing to ACE_Task::activate. | |
long | scope () const |
Returns value of THR_SCOPE_* used, or zero if unknown. | |
long | sched () const |
Returns value of THR_SCHED_* used, or zero if unknown. | |
operator long () const | |
Synonym for flags(), i.e., syntactic sugar. | |
long | default_priority () const |
Return an acceptable default priority for the scheduler returned by sched(). | |
Static Public Attributes | |
static Supported_Flag | supported_flags_ [] |
Protected Member Functions | |
void | parse_symbols (const char *syms) |
Value of THR_SCHED_*. | |
Protected Attributes | |
long | flags_ |
long | scope_ |
Value of all flags OR'd together. | |
long | sched_ |
Value of THR_SCOPE_*. | |
Classes | |
struct | Supported_Flag |
Encapsulate flags used for creating threads with ACE_OS::thr_create and ACE_Task::activate.
Definition at line 44 of file EC_Thread_Flags.h.
TAO_EC_Thread_Flags::TAO_EC_Thread_Flags | ( | ) | [inline] |
TAO_EC_Thread_Flags::TAO_EC_Thread_Flags | ( | const char * | symbolic_flags | ) | [inline] |
See operator=().
Definition at line 49 of file EC_Thread_Flags.h.
00050 { this->parse_symbols(symbolic_flags); }
TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_EC_Thread_Flags::~TAO_EC_Thread_Flags | ( | ) |
long TAO_EC_Thread_Flags::default_priority | ( | ) | const |
Return an acceptable default priority for the scheduler returned by sched().
Definition at line 126 of file EC_Thread_Flags.cpp.
References ACE_DEFAULT_THREAD_PRIORITY, ACE_Sched_Params::next_priority(), ACE_Sched_Params::priority_max(), and ACE_Sched_Params::priority_min().
Referenced by TAO_EC_Default_Factory::init().
00127 { 00128 long priority = ACE_DEFAULT_THREAD_PRIORITY; 00129 00130 // use the implementation 00131 if (this->sched() == 0) 00132 return priority; 00133 00134 priority = 00135 ACE_Sched_Params::priority_min (this->sched()) + 00136 ACE_Sched_Params::priority_max (this->sched()) / 2; 00137 priority = ACE_Sched_Params::next_priority (this->sched(), priority); 00138 00139 return priority; 00140 }
long TAO_EC_Thread_Flags::flags | ( | void | ) | const [inline] |
Returns numeric equivalent of the thread flags suitable for passing to ACE_Task::activate.
Definition at line 73 of file EC_Thread_Flags.h.
Referenced by TAO_EC_Default_Factory::init().
00073 { return this->flags_; }
TAO_EC_Thread_Flags::operator long | ( | ) | const [inline] |
Synonym for flags(), i.e., syntactic sugar.
Definition at line 86 of file EC_Thread_Flags.h.
00086 { return this->flags(); }
const TAO_EC_Thread_Flags& TAO_EC_Thread_Flags::operator= | ( | const char * | symbolic_flags | ) | [inline] |
Assign a new set of symbolic flags, setting flags, scope, and sched as possible.
The flags can be symbolic, separated by the vertical bar ('|'). In case a platform supports a creation flag not available symbolically, the user can specify a numeric value any place a symbol could be used.
Definition at line 67 of file EC_Thread_Flags.h.
00068 { this->parse_symbols(symbolic_flags); return *this; }
void TAO_EC_Thread_Flags::parse_symbols | ( | const char * | syms | ) | [protected] |
Value of THR_SCHED_*.
Definition at line 43 of file EC_Thread_Flags.cpp.
References ACE_ERROR, flags_, ACE_OS::free(), LM_ERROR, sched_, scope_, strcasecmp(), strdup(), strtok_r(), strtol(), supported_flags_, THR_SCHED_DEFAULT, THR_SCHED_FIFO, THR_SCHED_RR, THR_SCOPE_PROCESS, THR_SCOPE_SYSTEM, and TAO_EC_Thread_Flags::Supported_Flag::v.
00044 { 00045 // PRE: we assume nothing other than that syms is valid 00046 // POST: 00047 // 1. flags_ is bitwise-OR of all flags 00048 // 2. sched_ is THR_SCHED_*, or THR_SCHED_DEFAULT if not specified 00049 // 3. scope_ is THR_SCOPE_*, or THR_SCOPE_PROCESS if not specified 00050 00051 // NOTE: I'm not sure if #2 and #3 are consistent with what happens 00052 // in ACE_Task::activate. I really need to double-check that, and 00053 // make sure that they are consistent. 00054 00055 flags_ = scope_ = sched_ = 0; // zero out everything 00056 00057 // short-circuit on the trivial case 00058 if (syms == 0 || *syms == '\0') 00059 return; 00060 00061 static size_t num_flags = sizeof(supported_flags_)/sizeof(Supported_Flag); 00062 char* s = ACE_OS_String::strdup (syms); // need a mutable string 00063 if (s == 0) 00064 return; 00065 00066 const char* SEPARATORS = " |"; // this should probably be at class level 00067 char* ptr = 0; 00068 char* tok = ACE_OS_String::strtok_r (s, SEPARATORS, &ptr); 00069 while (tok != 0) 00070 { 00071 // This would allow for easy accomodation of flags that 00072 // aren't currently supported, but is it a good idea? 00073 00074 if (tok[0] >= '0' && tok[0] <= '9') // Numeric, so just accept it! 00075 { 00076 // parse it as a long straight to the flags 00077 00078 // If somebody specifies the scheduler this way, then they 00079 // lose range checking on the priority. Bummer, but those 00080 // are the breaks. 00081 this->flags_ |= ACE_OS_String::strtol (tok, 0, 0); 00082 } 00083 else 00084 { 00085 int found = 0; 00086 for (size_t i = 0; !found && i < num_flags; ++i) 00087 { 00088 if (ACE_OS_String::strcasecmp (tok, supported_flags_[i].n) == 0) 00089 { 00090 this->flags_ |= supported_flags_[i].v; 00091 00092 // Can't use a switch for this b/c for some 00093 // platforms the THR_* constants end up with 00094 // the same values, and compiles get upset. 00095 long &sf = supported_flags_[i].v; 00096 if (sf == THR_SCHED_FIFO || 00097 sf == THR_SCHED_RR || 00098 sf == THR_SCHED_DEFAULT) 00099 { 00100 this->sched_ = supported_flags_[i].v; 00101 } 00102 else if (sf == THR_SCOPE_SYSTEM || 00103 sf == THR_SCOPE_PROCESS) 00104 { 00105 this->scope_ = supported_flags_[i].v; 00106 } 00107 found = 1; 00108 } 00109 } 00110 if (!found) 00111 { 00112 // Ideally this would call some sort of on-error function... 00113 // but, it doesn't. 00114 ACE_ERROR ((LM_ERROR, 00115 "RTEC (%P|%t) unable to parse %s as a thread flag - skipping\n", 00116 tok)); 00117 } 00118 } 00119 tok = ACE_OS_String::strtok_r (0, SEPARATORS, &ptr); 00120 } 00121 00122 ACE_OS::free (s); // clean up after ourselves 00123 }
long TAO_EC_Thread_Flags::sched | ( | ) | const [inline] |
Returns value of THR_SCHED_* used, or zero if unknown.
Definition at line 83 of file EC_Thread_Flags.h.
00083 { return this->sched_; }
long TAO_EC_Thread_Flags::scope | ( | ) | const [inline] |
Returns value of THR_SCOPE_* used, or zero if unknown.
Definition at line 78 of file EC_Thread_Flags.h.
00078 { return this->scope_; }
long TAO_EC_Thread_Flags::flags_ [protected] |
long TAO_EC_Thread_Flags::sched_ [protected] |
Value of THR_SCOPE_*.
Definition at line 108 of file EC_Thread_Flags.h.
Referenced by parse_symbols().
long TAO_EC_Thread_Flags::scope_ [protected] |
Value of all flags OR'd together.
Definition at line 107 of file EC_Thread_Flags.h.
Referenced by parse_symbols().