OpenWalnut  1.5.0dev
WThreadedFunction.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <memory>
26 
27 #include "WThreadedFunction.h"
28 
30  : m_doneCondition( new WCondition ),
31  m_exceptionSignal(),
32  m_status()
33 {
34  // set initial status
35  m_status.getWriteTicket()->get() = W_THREADS_INITIALIZED;
36 }
37 
39 {
40  m_exceptionSignal.disconnect_all_slots();
41 }
42 
43 WThreadedFunctionStatus WThreadedFunctionBase::status()
44 {
45  return m_status.getReadTicket()->get();
46 }
47 
48 std::shared_ptr< WCondition > WThreadedFunctionBase::getThreadsDoneCondition()
49 {
50  return m_doneCondition;
51 }
52 
54 {
55  if( func )
56  {
57  m_exceptionSignal.connect( func );
58  }
59 }
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
std::shared_ptr< WCondition > m_doneCondition
a condition that gets notified when the work is complete
std::shared_ptr< WCondition > getThreadsDoneCondition()
Returns a condition that gets fired when all threads have finished.
WThreadedFunctionStatus status()
Get the status of the threads.
boost::function< void(WException const &) > ExceptionFunction
a type for exception callbacks
ExceptionSignal m_exceptionSignal
a signal for exceptions
WThreadedFunctionBase()
Standard constructor.
void subscribeExceptionSignal(ExceptionFunction func)
Subscribe a function to an exception signal.
virtual ~WThreadedFunctionBase()
Destroys the thread pool and stops all threads, if any one of them is still running.
WSharedObject< WThreadedFunctionStatus > m_status
the current status