Show
Ignore:
Timestamp:
01/29/10 13:00:29 (6 months ago)
Author:
mgray
Message:

Added getCurrentThreadId() and getThreadId() method implementations to Zen::Threading::I_Thread and associated concrete implementations.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Core/branches/0075_TR_SCRIPTING/Threading/I_Thread.hpp

    r298 r3327  
    3131#include <boost/noncopyable.hpp> 
    3232 
     33#include <string> 
     34 
    3335//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    3436namespace Zen { 
     
    4244    /// @{ 
    4345public: 
     46    struct ThreadId; 
    4447    /// @} 
    4548 
     
    5659        /// Block until this I_Thread has terminated. 
    5760        virtual void join() = 0; 
     61 
     62    /// Returns a copy of running (kernel-)thread's id, rendered in this  
     63    /// object's id format (so that you can safely compare it to  
     64    /// getThreadId()).  Always valid. 
     65    virtual ThreadId getCurrentThreadId() const = 0; 
     66 
     67    /// Returns a copy of this object's id. Not valid until after start(). 
     68    virtual const ThreadId& getThreadId() const = 0;  
    5869    /// @} 
    5970 
     
    6273public: 
    6374    static void sleepForMilliseconds(unsigned const _milliseconds); // current thread will sleep 
     75    /// @} 
     76 
     77    /// @name Inner Classes 
     78    /// @{ 
     79public: 
     80    struct ThreadId 
     81    { 
     82        /// @name Inner Interfaces 
     83        /// @{ 
     84    public: 
     85        class I_NativeThreadId 
     86        { 
     87            /// @name Types 
     88            /// @{ 
     89        public: 
     90            /// @} 
     91 
     92            /// @name I_NativeThreadId interface 
     93            /// @{ 
     94        public: 
     95            virtual bool operator==(const I_NativeThreadId& _otherId) const = 0; 
     96            virtual bool operator!=(const I_NativeThreadId& _otherId) const = 0; 
     97            virtual I_NativeThreadId* clone() const = 0; 
     98            virtual std::string toString() const = 0; 
     99            /// @} 
     100 
     101            /// @name 'Structors 
     102            /// @{ 
     103        public: 
     104                     I_NativeThreadId() {} 
     105            virtual ~I_NativeThreadId() {} 
     106            /// @} 
     107 
     108        };  // class I_NativeThreadId 
     109        /// @} 
     110 
     111        /// @name ThreadId implementation 
     112        /// @{ 
     113    public: 
     114        ThreadId& operator=  (const ThreadId& _otherId)       {delete m_pNativeThreadId; m_pNativeThreadId = _otherId.m_pNativeThreadId->clone(); return *this;} 
     115        bool      operator== (const ThreadId& _otherId) const {return (m_pNativeThreadId == _otherId.m_pNativeThreadId) || ( m_pNativeThreadId &&  _otherId.m_pNativeThreadId && (*m_pNativeThreadId == *_otherId.m_pNativeThreadId));} 
     116        bool      operator!= (const ThreadId& _otherId) const {return (m_pNativeThreadId != _otherId.m_pNativeThreadId) && (!m_pNativeThreadId || !_otherId.m_pNativeThreadId || (*m_pNativeThreadId != *_otherId.m_pNativeThreadId));} 
     117                  operator std::string ()               const {return m_pNativeThreadId ? m_pNativeThreadId->toString() : "";} 
     118        std::string toString()                          const {return m_pNativeThreadId ? m_pNativeThreadId->toString() : "";} 
     119        /// @} 
     120 
     121        /// @name 'Structors 
     122        /// @{ 
     123    public: 
     124         ThreadId(I_NativeThreadId* const _pId = NULL) : m_pNativeThreadId(_pId)                                {} 
     125         ThreadId(const ThreadId& _otherId)            : m_pNativeThreadId(_otherId.m_pNativeThreadId->clone()) {} 
     126        ~ThreadId()                                                                                             {delete m_pNativeThreadId;} 
     127        /// @} 
     128 
     129        /// @name Member variables 
     130        /// @{ 
     131    public: 
     132        I_NativeThreadId* m_pNativeThreadId; 
     133        /// @} 
     134 
     135    };  // struct ThreadId 
    64136    /// @} 
    65137