EC_Thread_Flags.cpp

Go to the documentation of this file.
00001 // $Id: EC_Thread_Flags.cpp 75402 2006-11-15 16:43:47Z cleeland $
00002 
00003 #include "orbsvcs/Event/EC_Thread_Flags.h"
00004 
00005 #include "ace/OS_NS_Thread.h"
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/OS_NS_strings.h"
00008 #include "ace/Log_Msg.h"
00009 #include "ace/Sched_Params.h"
00010 
00011 ACE_RCSID(Event, EC_Thread_Flags , "$Id: EC_Thread_Flags.cpp 75402 2006-11-15 16:43:47Z cleeland $")
00012 
00013 #define TETFSF(flag)  { #flag, flag }
00014 TAO_EC_Thread_Flags::Supported_Flag TAO_EC_Thread_Flags::supported_flags_[] = {
00015 #if defined (ACE_HAS_THREADS)
00016     TETFSF(THR_CANCEL_DISABLE),
00017     TETFSF(THR_CANCEL_ENABLE),
00018     TETFSF(THR_CANCEL_DEFERRED),
00019     TETFSF(THR_CANCEL_ASYNCHRONOUS),
00020     TETFSF(THR_BOUND),
00021     TETFSF(THR_NEW_LWP),
00022     TETFSF(THR_DETACHED),
00023     TETFSF(THR_SUSPENDED),
00024     TETFSF(THR_DAEMON),
00025     TETFSF(THR_JOINABLE),
00026     TETFSF(THR_SCHED_FIFO),
00027     TETFSF(THR_SCHED_RR),
00028     TETFSF(THR_SCHED_DEFAULT),
00029     TETFSF(THR_EXPLICIT_SCHED),
00030     TETFSF(THR_SCOPE_SYSTEM),
00031     TETFSF(THR_SCOPE_PROCESS)
00032 #endif /* ACE_HAS_THREADS */
00033   };
00034 #undef TETFSF
00035 
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 TAO_EC_Thread_Flags::~TAO_EC_Thread_Flags ()
00039 {
00040 }
00041 
00042 void
00043 TAO_EC_Thread_Flags::parse_symbols (const char* syms)
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 }
00124 
00125 long
00126 TAO_EC_Thread_Flags::default_priority () const
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 }
00141 
00142 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:44:06 2010 for TAO_RTEvent by  doxygen 1.4.7