diff options
Diffstat (limited to 'cpp/src/Ice/ThreadPool.h')
-rw-r--r-- | cpp/src/Ice/ThreadPool.h | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h index 9bf068ddc61..fe80f9b129e 100644 --- a/cpp/src/Ice/ThreadPool.h +++ b/cpp/src/Ice/ThreadPool.h @@ -24,6 +24,8 @@ #include <Ice/EventHandler.h> #include <Ice/Selector.h> #include <Ice/BasicStream.h> +#include <Ice/ObserverHelper.h> +#include <Ice/Observer.h> #include <set> #include <list> @@ -38,6 +40,24 @@ typedef IceUtil::Handle<ThreadPoolWorkQueue> ThreadPoolWorkQueuePtr; class ThreadPool : public IceUtil::Shared, public IceUtil::Monitor<IceUtil::Mutex> { + class EventHandlerThread : public IceUtil::Thread + { + public: + + EventHandlerThread(const ThreadPoolPtr&, const std::string&); + virtual void run(); + + void updateObserver(); + void setState(Ice::Instrumentation::ThreadState); + + private: + + ThreadPoolPtr _pool; + ObserverHelperT<Ice::Instrumentation::ThreadObserver> _observer; + Ice::Instrumentation::ThreadState _state; + }; + typedef IceUtil::Handle<EventHandlerThread> EventHandlerThreadPtr; + public: ThreadPool(const InstancePtr&, const std::string&, int); @@ -45,6 +65,8 @@ public: void destroy(); + void updateObservers(); + void initialize(const EventHandlerPtr&); void _register(const EventHandlerPtr& handler, SocketOperation status) { @@ -64,7 +86,7 @@ public: private: - void run(const IceUtil::ThreadPtr&); + void run(const EventHandlerThreadPtr&); bool ioCompleted(ThreadPoolCurrent&); @@ -73,26 +95,17 @@ private: void finishMessage(ThreadPoolCurrent&); #else void promoteFollower(ThreadPoolCurrent&); - bool followerWait(const IceUtil::ThreadPtr&, ThreadPoolCurrent&); + bool followerWait(ThreadPoolCurrent&); #endif + std::string nextThreadId(); + const InstancePtr _instance; ThreadPoolWorkQueuePtr _workQueue; bool _destroyed; const std::string _prefix; Selector _selector; - - class EventHandlerThread : public IceUtil::Thread - { - public: - - EventHandlerThread(const ThreadPoolPtr&); - virtual void run(); - - private: - - ThreadPoolPtr _pool; - }; + int _nextThreadId; friend class EventHandlerThread; friend class ThreadPoolCurrent; @@ -108,7 +121,7 @@ private: const int _threadIdleTime; const size_t _stackSize; - std::set<IceUtil::ThreadPtr> _threads; // All threads, running or not. + std::set<EventHandlerThreadPtr> _threads; // All threads, running or not. int _inUse; // Number of threads that are currently in use. #if !defined(ICE_USE_IOCP) && !defined(ICE_OS_WINRT) int _inUseIO; // Number of threads that are currently performing IO. @@ -123,7 +136,7 @@ class ThreadPoolCurrent { public: - ThreadPoolCurrent(const InstancePtr&, const ThreadPoolPtr&); + ThreadPoolCurrent(const InstancePtr&, const ThreadPoolPtr&, const ThreadPool::EventHandlerThreadPtr&); SocketOperation operation; BasicStream stream; // A per-thread stream to be used by event handlers for optimization. @@ -148,6 +161,7 @@ public: private: ThreadPool* _threadPool; + ThreadPool::EventHandlerThreadPtr _thread; EventHandlerPtr _handler; bool _ioCompleted; #if !defined(ICE_USE_IOCP) && !defined(ICE_OS_WINRT) |