diff options
Diffstat (limited to 'ace/Barrier.cpp')
-rw-r--r-- | ace/Barrier.cpp | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/ace/Barrier.cpp b/ace/Barrier.cpp index 6637f1ec638..739e249cd76 100644 --- a/ace/Barrier.cpp +++ b/ace/Barrier.cpp @@ -9,12 +9,17 @@ #endif /* __ACE_INLINE__ */ #include "ace/Guard_T.h" +#include "ace/OS_NS_errno.h" #if defined (ACE_HAS_DUMP) # include "ace/Log_Msg.h" #endif /* ACE_HAS_DUMP */ -ACE_RCSID(ace, Barrier, "$Id$") +ACE_RCSID (ace, + Barrier, + "$Id$") + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_ALLOC_HOOK_DEFINE(ACE_Sub_Barrier) @@ -69,7 +74,7 @@ ACE_Barrier::ACE_Barrier (unsigned int count, sub_barrier_1_ (count, lock_, name, arg), sub_barrier_2_ (count, lock_, name, arg) { -// ACE_TRACE ("ACE_Barrier::ACE_Barrier"); + ACE_TRACE ("ACE_Barrier::ACE_Barrier"); this->sub_barrier_[0] = &this->sub_barrier_1_; this->sub_barrier_[1] = &this->sub_barrier_2_; } @@ -77,7 +82,7 @@ ACE_Barrier::ACE_Barrier (unsigned int count, int ACE_Barrier::wait (void) { -// ACE_TRACE ("ACE_Barrier::wait"); + ACE_TRACE ("ACE_Barrier::wait"); ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); ACE_Sub_Barrier *sbp = @@ -85,14 +90,18 @@ ACE_Barrier::wait (void) // Check for shutdown... if (sbp == 0) - return -1; + { + errno = ESHUTDOWN; + return -1; + } + + int retval = 0; if (sbp->running_threads_ == 1) { // We're the last running thread, so swap generations and tell // all the threads waiting on the barrier to continue on their // way. - sbp->running_threads_ = this->count_; // Swap generations. this->current_generation_ = 1 - this->current_generation_; @@ -105,8 +114,43 @@ ACE_Barrier::wait (void) // Block until all the other threads wait(). while (sbp->running_threads_ != this->count_) sbp->barrier_finished_.wait (); + + // We're awake and the count has completed. See if it completed + // because all threads hit the barrier, or because the barrier + // was shut down. + if (this->sub_barrier_[this->current_generation_] == 0) + { + errno = ESHUTDOWN; + retval = -1; + } + } + + return retval; +} + +int +ACE_Barrier::shutdown (void) +{ + ACE_TRACE ("ACE_Barrier::shutdown"); + ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1); + + ACE_Sub_Barrier *sbp = + this->sub_barrier_[this->current_generation_]; + + // Check for shutdown... + if (sbp == 0) + { + errno = ESHUTDOWN; + return -1; } + // Flag the shutdown + this->sub_barrier_[0] = 0; + this->sub_barrier_[1] = 0; + // Tell all the threads waiting on the barrier to continue on their way. + sbp->running_threads_ = this->count_; + sbp->barrier_finished_.broadcast (); + return 0; } @@ -148,4 +192,6 @@ ACE_Process_Barrier::dump (void) const } #endif /* 0 */ +ACE_END_VERSIONED_NAMESPACE_DECL + #endif /* ACE_HAS_THREADS */ |