IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
ThreadManager.h
1 // ThreadManager.h:
3 // ----------------
4 //
14 
15 #ifndef __IPSDKCORE_THREADMANAGER_H__
16 #define __IPSDKCORE_THREADMANAGER_H__
17 
18 // suppression warnings
19 // warning C4275: non dll-interface class 'boost::noncopyable_::noncopyable' used as base for dll-interface class 'ipsdk::core::ThreadManager'
20 // warning C4251: 'ipsdk::core::ThreadManager::_mutex' : class 'boost::mutex' needs to have dll-interface to be used by clients of class 'ipsdk::core::ThreadManager'
21 #pragma warning (push)
22 #pragma warning (disable : 4275 4251)
23 
26 #include <boost/thread/mutex.hpp>
27 #include <boost/noncopyable.hpp> // Anticipating Boost 1.75
28 
29 namespace ipsdk {
30 namespace processor {
31  class BaseAsyncProcessor;
32 }
33 namespace core {
34 
37 
38 class IPSDKCORE_API ThreadManager : public boost::noncopyable
39 {
40  // friend class for protected accesses
41  friend class processor::BaseAsyncProcessor;
42 
43 protected:
46  ThreadManager();
47  ~ThreadManager();
49 
50 // access to singleton
51 public:
53  static ThreadManager& getInstance();
54 
55 // methods
56 public:
58  bool isInit() const;
59 
61  void init(ipUInt32 nbThreads);
62 
65  ipUInt32 getNbThreads() const;
66 
74  BoolResult addProvider(const ActionProviderPtr& pActionProvider);
75 
80  bool restartProvider(const Guid& providerGuid);
81 
86  bool removeProvider(const Guid& providerGuid);
87 
91  ActionProviderPtr getProvider(const Guid& providerGuid) const;
92 
94  void terminate();
95 
97  ProviderManagerPtr getProviderManager() const;
98 
99 protected:
101  void threadFunction(ipUInt32 threadIdx);
102 
104  void notifyCompletion(const ActionProviderPtr& pActionProvider);
105 
113  BoolResult addProvider(const ActionProviderPtr& pActionProvider,
114  bool bPushBack);
115 
116 // attributes
117 protected:
120 
123 
126 
128  bool volatile _bTerminateRequested;
129 
131  mutable boost::mutex _mutex;
132 
134  bool _bInit;
135 };
136 
139 
140 inline bool
142 {
143  return _bInit;
144 }
145 
148 
149 } // end of namespace core
150 } // end of namespace ipsdk
151 
152 #pragma warning (pop)
153 
154 #endif // __IPSDKCORE_THREADMANAGER_H__
std::map< ipUInt32, ThreadPtr > ThreadColl
collection of indexed threads
Definition: ThreadManagerTypes.h:40
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
boost::shared_ptr< ProviderManager > ProviderManagerPtr
shared pointer to provider manager
Definition: ThreadManagerTypes.h:55
Predefined types used for execution thread management.
ThreadColl _threadColl
collection of threads associated to object
Definition: ThreadManager.h:125
bool isInit() const
retrieve object initialization flag
Definition: ThreadManager.h:141
Definition of import/export macro for library.
#define IPSDKCORE_API
Import/Export macro for library IPSDKCore.
Definition: IPSDKCoreExports.h:27
ProviderMap _providerMap
global collection of execution providers ordered by guid
Definition: ThreadManager.h:119
Class encapsulating an auto initialized uuid.
Definition: Guid.h:27
Base class for asynchronous processors.
Definition: BaseAsyncProcessor.h:29
std::map< Guid, ActionProviderPtr > ProviderMap
collection of providers ordered by guid
Definition: ThreadManagerTypes.h:43
ProviderManagerPtr _pProviderManager
object used to manage provider execution priority
Definition: ThreadManager.h:122
bool volatile _bTerminateRequested
flag indicating whether termination has been requested for threads
Definition: ThreadManager.h:128
boost::mutex _mutex
mutex allowing to protect concurrent accesses to object
Definition: ThreadManager.h:131
boost::shared_ptr< BaseActionProvider > ActionProviderPtr
shared pointer to action provider
Definition: ActionProviderTypes.h:58
Singleton class used to manage execution threads.
Definition: ThreadManager.h:38
bool _bInit
object initialization flag
Definition: ThreadManager.h:134
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53