TAO_EC_Thread_Flags Class Reference

Parse thread flags from string to a long. More...

#include <EC_Thread_Flags.h>

Collaboration diagram for TAO_EC_Thread_Flags:

Collaboration graph
[legend]
List of all members.

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_Flagsoperator= (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

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_*.


Detailed Description

Parse thread flags from string to a long.

Encapsulate flags used for creating threads with ACE_OS::thr_create and ACE_Task::activate.

Note:
On platforms that do not support the thread schedulers, the ACE OS adaptation layer preserves the symbols for THR_SCHED_*, but defines them as zero. Thus, on such platforms, setting a scheduler in the flags, then inquiring for the scheduler type will yield the same result as an unknown or unset scheduler.
This should really be part of ACE or ACE_OS, and maybe someday it will, but right now it's not.

Definition at line 44 of file EC_Thread_Flags.h.


Constructor & Destructor Documentation

TAO_EC_Thread_Flags::TAO_EC_Thread_Flags  )  [inline]
 

Definition at line 47 of file EC_Thread_Flags.h.

00047 { }

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  ) 
 

Definition at line 38 of file EC_Thread_Flags.cpp.

00039 {
00040 }


Member Function Documentation

long TAO_EC_Thread_Flags::default_priority  )  const
 

Return an acceptable default priority for the scheduler returned by sched().

Returns:
the priority, or ACE_DEFAULT_THREAD_PRIORITY if the scheduler is unknown.

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(), ACE_Sched_Params::priority_min(), and sched().

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.

See also:
TAO_EC_Thread_Flags::supported_flags
Note:
The sched value only gets set if the scheduler is specified using symbols.

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, ACE_OS::free(), LM_ERROR, sched_, supported_flags_, 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.

Referenced by default_priority().

00083 { return this->sched_; }

long TAO_EC_Thread_Flags::scope void   )  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_; }


Member Data Documentation

long TAO_EC_Thread_Flags::flags_ [protected]
 

Definition at line 106 of file EC_Thread_Flags.h.

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.

TAO_EC_Thread_Flags::Supported_Flag TAO_EC_Thread_Flags::supported_flags_ [static]
 

Initial value:

 {

    TETFSF(THR_CANCEL_DISABLE),
    TETFSF(THR_CANCEL_ENABLE),
    TETFSF(THR_CANCEL_DEFERRED),
    TETFSF(THR_CANCEL_ASYNCHRONOUS),
    TETFSF(THR_BOUND),
    TETFSF(THR_NEW_LWP),
    TETFSF(THR_DETACHED),
    TETFSF(THR_SUSPENDED),
    TETFSF(THR_DAEMON),
    TETFSF(THR_JOINABLE),
    TETFSF(THR_SCHED_FIFO),
    TETFSF(THR_SCHED_RR),
    TETFSF(THR_SCHED_DEFAULT),
    TETFSF(THR_EXPLICIT_SCHED),
    TETFSF(THR_SCOPE_SYSTEM),


  }

Definition at line 14 of file EC_Thread_Flags.cpp.

Referenced by parse_symbols().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 13:43:11 2008 for TAO_RTEvent by doxygen 1.3.6