#define __SFJP_ROAST__thread__thread_HPP__
//#include "roast/_common.hpp"
-#include <windows.h>
#include <string>
typedef int (*roast_thread_func_t)(int);
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>
///////////////////////////////////////
#ifdef WIN32
- typedef thread_< _thread_impl_win32> thread;
+ #include "roast/windows/thread_impl.hpp"
#endif//WIN32
}
#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__