OSDN Git Service

thread.hpp: handle_assert
authormyun2 <myun2@nwhite.info>
Sat, 14 Jul 2012 15:03:27 +0000 (00:03 +0900)
committermyun2 <myun2@nwhite.info>
Sat, 14 Jul 2012 15:03:27 +0000 (00:03 +0900)
roast/include/roast/multitask/thread/thread.hpp

index a826256..b70e9db 100644 (file)
@@ -65,10 +65,18 @@ namespace roast
        public:
                typedef int (*func_t)(int);
                typedef int (*callback_t)(int);
-               typedef void* handle_t;
+               //typedef void* handle_t;
+               typedef typename _Impl::handle_type handle_t;
        protected:
                _Impl m_impl;
                thread_handle_t m_handle;
+
+               //      Assert
+               void handle_assert(const char* method_name){
+                       if ( m_handle == _Impl::invalid_handle )
+                               throw io_exception(::std::string(method_name) + "(): Handler is Invalid.");
+               }
+               
        public:
                thread_(){
                        m_handle = NULL;
@@ -82,6 +90,7 @@ namespace roast
                template <typename _Func, typename _Param>
                thread_(_Func func, _Param param=0, void* opt=NULL)
                {
+                       m_handle = NULL;
                        if ( start(func,param,opt) != true )
                                thread_exception("thread start failed.");
                }
@@ -90,6 +99,7 @@ namespace roast
                template <typename _Class, typename _Param, typename _Ret>
                thread_(_Class* p_this, _Ret (_Class::*func)(_Param), _Param param=0, void* opt=NULL)
                {
+                       m_handle = NULL;
                        if ( start_class_ptr(p_this,func,param,opt) != true )
                                thread_exception("thread start failed.");
                }
@@ -121,7 +131,7 @@ namespace roast
                }*/
 
                template <typename _Class, typename _Param, typename _Ret>
-               bool start(_Ret (__thiscall _Class::*func)(_Param), _Param param=0, void* opt=NULL)
+               bool start(_Ret (_Class::*func)(_Param), _Param param=0, void* opt=NULL)
                {
                        //  The second parameter is a class pointer or the method should be static.
                        The_second_parameter_is_a_class_pointer_or_the_method_should_be_static.
@@ -211,11 +221,16 @@ namespace roast
 
                ////////////////////////////////////////////////////
 
-               bool release()
+               /*bool release()
                {
                        if ( m_handle != NULL )
                                return m_impl.release(m_handle);
                        return true;
+               }*/
+               void release()
+               {
+                       if ( m_handle != NULL )
+                               m_impl.release(m_handle);
                }
                bool join(unsigned int timeout_ms=-1)
                {
@@ -223,7 +238,7 @@ namespace roast
                                return false;
                        return m_impl.join(m_handle, timeout_ms);
                }
-               bool is_alive()
+               bool is_alive() const
                {
                        if ( m_handle == NULL )
                                return false;