Changeset 39:d45d6f5f5d3a in rrlib_thread


Ignore:
Timestamp:
24.09.2017 18:06:22 (15 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Tags:
tip
Message:

Makes condition variable wrapper return status from Wait() method with timeout

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tConditionVariable.cpp

    r30 r39  
    7171 
    7272#ifndef RRLIB_SINGLE_THREADED 
     73 
     74namespace 
     75{ 
     76 
     77inline tConditionVariableStatus ToConditionVariableStatus(std::cv_status status) 
     78{ 
     79  return status == std::cv_status::timeout ? tConditionVariableStatus::TIMEOUT : tConditionVariableStatus::NO_TIMEOUT; 
     80} 
     81 
    7382typedef rrlib::design_patterns::tSingletonHolder<std::vector<tConditionVariable*>> tConditionVariableListSingleton; 
    7483static std::vector<tConditionVariable*>* GetConditionVariableList() 
     
    8291  return NULL; 
    8392} 
     93 
     94/*! 
     95 * This object increments value while it exists 
     96 */ 
     97struct tTemporalIncrement : private util::tNoncopyable 
     98{ 
     99  int& value; 
     100  tTemporalIncrement(int& value) : value(value) 
     101  { 
     102    value++; 
     103  } 
     104 
     105  ~tTemporalIncrement() 
     106  { 
     107    value--; 
     108  } 
     109}; 
     110 
     111} // namespace 
    84112 
    85113class tTimeStretchingListenerImpl : public rrlib::time::tTimeStretchingListener 
     
    181209static tTimeStretchingListenerImpl time_stretching_listener; 
    182210 
    183 /*! 
    184  * This object increments value while it exists 
    185  */ 
    186 struct tTemporalIncrement : private util::tNoncopyable 
    187 { 
    188   int& value; 
    189   tTemporalIncrement(int& value) : value(value) 
    190   { 
    191     value++; 
    192   } 
    193  
    194   ~tTemporalIncrement() 
    195   { 
    196     value--; 
    197   } 
    198 }; 
    199211 
    200212tConditionVariable::tConditionVariable(tMutex& mutex) : 
     
    261273} 
    262274 
    263 void tConditionVariable::Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until) 
     275tConditionVariableStatus tConditionVariable::Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until) 
    264276{ 
    265277  assert(ConditionVariableLockCorrectlyAcquired(l)); 
     
    268280  if (!use_application_time) 
    269281  { 
    270     wrapped.wait_for(l.GetSimpleLock(), wait_for); 
     282    return ToConditionVariableStatus(wrapped.wait_for(l.GetSimpleLock(), wait_for)); 
    271283  } 
    272284  else 
     
    284296      { 
    285297        RRLIB_LOG_PRINT(DEBUG_WARNING, "Won't wait after rrlibs have been (partly) destructed."); 
    286         return; 
     298        return tConditionVariableStatus::TIMEOUT; 
    287299      } 
    288300    } 
     
    352364    waiting_until_application_time = rrlib::time::cNO_TIME; 
    353365  } 
     366  return notified ? tConditionVariableStatus::TIMEOUT : tConditionVariableStatus::NO_TIMEOUT; 
    354367} 
    355368#else // RRLIB_SINGLE_THREADED 
     
    370383{} 
    371384 
    372 void tConditionVariable::Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until) 
    373 {} 
     385tConditionVariableStatus tConditionVariable::Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until) 
     386{ 
     387  return tConditionVariableStatus::TIMEOUT;  // TODO support pending tasks (to do something during wait) in single-threaded mode 
     388} 
    374389 
    375390#endif // RRLIB_SINGLE_THREADED 
  • tConditionVariable.h

    r30 r39  
    6464//---------------------------------------------------------------------- 
    6565 
     66/*! equivalent to std::cv_status that may be used without <condition_variable> header */ 
     67enum tConditionVariableStatus 
     68{ 
     69  NO_TIMEOUT, 
     70  TIMEOUT 
     71}; 
     72 
    6673//---------------------------------------------------------------------- 
    6774// Class declaration 
     
    125132   * \param use_application_time Use application time? 
    126133   * \param wait_until Time point until to wait (optional). If specified, this function won't need call clock's now() in case application time is used. 
     134   * \return Whether wait operation timed out or a notification occured 
    127135   */ 
    128   void Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until = rrlib::time::cNO_TIME); 
     136  tConditionVariableStatus Wait(tLock& l, const rrlib::time::tDuration& wait_for, bool use_application_time, rrlib::time::tTimestamp wait_until = rrlib::time::cNO_TIME); 
    129137 
    130138//---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.