OSDN Git Service

thread: Windows版の実装を windows 内に移動
authorMyun2 <myun2@nwhite.info>
Tue, 15 May 2012 17:24:16 +0000 (02:24 +0900)
committerMyun2 <myun2@nwhite.info>
Tue, 15 May 2012 17:24:16 +0000 (02:24 +0900)
roast/include/roast/net/server_socket.hpp
roast/include/roast/thread/thread.hpp
roast/include/roast/windows/thread_impl.hpp

index 7d9f0aa..2217bb8 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef __SFJP_ROAST__net__server_socket_HPP__
 #define __SFJP_ROAST__net__server_socket_HPP__
 
+#include "roast/thread.hpp"
+
 //#include "roast/net/socket.hpp"
 //#include "roast/net/socket_base.hpp"
 
@@ -17,7 +19,7 @@ namespace roast
                int m_port_no;
 
        public:
-               socket_server_(int listen_port_no) : m_port_no(listen_port_no) {}
+               server_socket_(int listen_port_no) : m_port_no(listen_port_no) {}
 
                /////////////////////////////////////////////////////
                
@@ -31,7 +33,7 @@ namespace roast
                                        m_setup_info.listen_port_no, ai, false,
                                        m_setup_info.socktype, m_setup_info.family);
 
-                               thread th;
+                               ::roast::thread th;
                                th.start();
                        }
                }
index e407ba2..367ac9e 100644 (file)
@@ -6,7 +6,6 @@
 #define __SFJP_ROAST__thread__thread_HPP__
 
 //#include "roast/_common.hpp"
-#include <windows.h>
 #include <string>
 
 typedef int (*roast_thread_func_t)(int);
@@ -28,89 +27,6 @@ namespace roast
                thread_exception(const ::std::string &s) : ::std::string(s) {}
        };
        
-       ///////////////////////////////////////////////////////
-       
-       class _thread_impl_win32
-       {
-       public:
-               struct start_option
-               {
-                       LPSECURITY_ATTRIBUTES lpThreadAttributes;
-                       DWORD dwStackSize;
-                       DWORD dwCreationFlags;
-               };
-       protected:
-               DWORD m_dwId;
-       public:
-               roast_thread_handle_t
-                       start(roast_thread_func_t func, int param, void* opt_)
-               {
-                       start_option opt_default;
-                       start_option* opt;
-                       if ( opt_ )
-                       {
-                               opt = (start_option*)opt_;
-                       }
-                       else
-                       {
-                               opt_default.lpThreadAttributes = NULL;
-                               opt_default.dwStackSize = 0;
-                               opt_default.dwCreationFlags = 0;
-                               opt = &opt_default;
-                       }
-
-                       return (roast_thread_handle_t)
-                               ::CreateThread(
-                                       opt->lpThreadAttributes,
-                                       opt->dwStackSize,
-                                       (LPTHREAD_START_ROUTINE)func,
-                                       (LPVOID)param,
-                                       opt->dwCreationFlags,
-                                       &m_dwId );
-               }
-               
-               bool release(roast_thread_handle_t h)
-               {
-                       return ( ::CloseHandle((HANDLE)h) == TRUE ? true : false );
-               }
-               
-               bool join(roast_thread_handle_t h, unsigned int timeout_ms)
-               {
-                       if ( ::WaitForSingleObject((HANDLE)h, timeout_ms) != WAIT_OBJECT_0 )
-                               return false;
-                       return true;
-               }
-               
-               bool is_alive(roast_thread_handle_t h)
-               {
-                       if ( ::WaitForSingleObject((HANDLE)h,0) == WAIT_TIMEOUT )
-                               return true;
-                       else
-                               return false;
-                               
-                       /*
-                       DWORD dwExitCode; 
-                       if ( GetExitCodeThread( m_hThread, &dwExitCode ) == 0 )
-                               return FALSE;
-
-                       if ( dwExitCode == STILL_ACTIVE )
-                               return TRUE;
-                       else{
-                               Close();
-                               return FALSE;
-                       }
-                       */
-               }
-               
-               int get_result(roast_thread_handle_t h)
-               {
-                       join(h,0xffffffff);
-                       DWORD dwExitCode = 0;
-                       ::GetExitCodeThread((HANDLE)h, &dwExitCode);
-                       return dwExitCode;
-               }
-       };
-       
        /////////////////////////////////////////////////////////////////
        
        template <typename T, typename _Param, typename _Ret>
@@ -321,7 +237,7 @@ namespace roast
        ///////////////////////////////////////
        
 #ifdef WIN32
-       typedef thread_< _thread_impl_win32> thread;
+       #include "roast/windows/thread_impl.hpp"
 #endif//WIN32
 }
 
index d34548e..a9af9c9 100644 (file)
 #include <windows.h>
 #include <string>
 
-typedef int (*roast_thread_func_t)(int);
-typedef int (*roast_thread_callback_t)(int);
-typedef void* roast_thread_handle_t;
-
 namespace roast
 {
-       typedef int (*thread_func_t)(int);
-       typedef int (*thread_callback_t)(int);
-       typedef void* thread_handle_t;
-       
-       ///////////////////////////////////////////////////////
-       
-       class thread_exception : public ::std::string
-       {
-       public:
-               thread_exception(const char* msg) : ::std::string(msg) {}
-               thread_exception(const ::std::string &s) : ::std::string(s) {}
-       };
-       
-       ///////////////////////////////////////////////////////
-       
-       class _thread_impl_win32
+       namespace windows
        {
-       public:
-               struct start_option
+               class thread_impl
                {
-                       LPSECURITY_ATTRIBUTES lpThreadAttributes;
-                       DWORD dwStackSize;
-                       DWORD dwCreationFlags;
-               };
-       protected:
-               DWORD m_dwId;
-       public:
-               roast_thread_handle_t
-                       start(roast_thread_func_t func, int param, void* opt_)
-               {
-                       start_option opt_default;
-                       start_option* opt;
-                       if ( opt_ )
+               public:
+                       struct start_option
+                       {
+                               LPSECURITY_ATTRIBUTES lpThreadAttributes;
+                               DWORD dwStackSize;
+                               DWORD dwCreationFlags;
+                       };
+               protected:
+                       DWORD m_dwId;
+               public:
+                       roast_thread_handle_t
+                               start(roast_thread_func_t func, int param, void* opt_)
                        {
-                               opt = (start_option*)opt_;
+                               start_option opt_default;
+                               start_option* opt;
+                               if ( opt_ )
+                               {
+                                       opt = (start_option*)opt_;
+                               }
+                               else
+                               {
+                                       opt_default.lpThreadAttributes = NULL;
+                                       opt_default.dwStackSize = 0;
+                                       opt_default.dwCreationFlags = 0;
+                                       opt = &opt_default;
+                               }
+       
+                               return (roast_thread_handle_t)
+                                       ::CreateThread(
+                                               opt->lpThreadAttributes,
+                                               opt->dwStackSize,
+                                               (LPTHREAD_START_ROUTINE)func,
+                                               (LPVOID)param,
+                                               opt->dwCreationFlags,
+                                               &m_dwId );
                        }
-                       else
+                       
+                       bool release(roast_thread_handle_t h)
                        {
-                               opt_default.lpThreadAttributes = NULL;
-                               opt_default.dwStackSize = 0;
-                               opt_default.dwCreationFlags = 0;
-                               opt = &opt_default;
+                               return ( ::CloseHandle((HANDLE)h) == TRUE ? true : false );
                        }
-
-                       return (roast_thread_handle_t)
-                               ::CreateThread(
-                                       opt->lpThreadAttributes,
-                                       opt->dwStackSize,
-                                       (LPTHREAD_START_ROUTINE)func,
-                                       (LPVOID)param,
-                                       opt->dwCreationFlags,
-                                       &m_dwId );
-               }
-               
-               bool release(roast_thread_handle_t h)
-               {
-                       return ( ::CloseHandle((HANDLE)h) == TRUE ? true : false );
-               }
-               
-               bool join(roast_thread_handle_t h, unsigned int timeout_ms)
-               {
-                       if ( ::WaitForSingleObject((HANDLE)h, timeout_ms) != WAIT_OBJECT_0 )
-                               return false;
-                       return true;
-               }
-               
-               bool is_alive(roast_thread_handle_t h)
-               {
-                       if ( ::WaitForSingleObject((HANDLE)h,0) == WAIT_TIMEOUT )
+                       
+                       bool join(roast_thread_handle_t h, unsigned int timeout_ms)
+                       {
+                               if ( ::WaitForSingleObject((HANDLE)h, timeout_ms) != WAIT_OBJECT_0 )
+                                       return false;
                                return true;
-                       else
-                               return false;
-                               
-                       /*
-                       DWORD dwExitCode; 
-                       if ( GetExitCodeThread( m_hThread, &dwExitCode ) == 0 )
-                               return FALSE;
-
-                       if ( dwExitCode == STILL_ACTIVE )
-                               return TRUE;
-                       else{
-                               Close();
-                               return FALSE;
                        }
-                       */
-               }
-               
-               int get_result(roast_thread_handle_t h)
-               {
-                       join(h,0xffffffff);
-                       DWORD dwExitCode = 0;
-                       ::GetExitCodeThread((HANDLE)h, &dwExitCode);
-                       return dwExitCode;
-               }
-       };
+                       
+                       bool is_alive(roast_thread_handle_t h)
+                       {
+                               if ( ::WaitForSingleObject((HANDLE)h,0) == WAIT_TIMEOUT )
+                                       return true;
+                               else
+                                       return false;
+                                       
+                               /*
+                               DWORD dwExitCode; 
+                               if ( GetExitCodeThread( m_hThread, &dwExitCode ) == 0 )
+                                       return FALSE;
+       
+                               if ( dwExitCode == STILL_ACTIVE )
+                                       return TRUE;
+                               else{
+                                       Close();
+                                       return FALSE;
+                               }
+                               */
+                       }
+                       
+                       int get_result(roast_thread_handle_t h)
+                       {
+                               join(h,0xffffffff);
+                               DWORD dwExitCode = 0;
+                               ::GetExitCodeThread((HANDLE)h, &dwExitCode);
+                               return dwExitCode;
+                       }
+               };
+       }
+       
+       typedef thread_<windows::thread_impl> thread;
 }
 
 #endif//__SFJP_ROAST__windows__thread_impl_HPP__