//////////////////////////////////////////////////////////////////////////// // CThread クラスのインプリメンテーション // //////////////////////////////////////////////////////////////////////////// #include #include "Thread.h" // スレッド生成用の関数のプロトタイプ宣言 #if defined( _WIN32 ) extern "C" DWORD WINAPI CThread_ThreadEntry( void* ); #else extern "C" void* CThread_ThreadEntry( void* ); #endif //////////////////////////////////////////////////////////////////////////// // 構築/破棄 //////////////////////////////////////////////////////////////////////////// CThread::CThread() { } CThread::~CThread() { } //////////////////////////////////////////////////////////////////////////// // メソッド //////////////////////////////////////////////////////////////////////////// // スレッドの開始 bool CThread::start() { #if defined( _WIN32 ) // Windowsの場合 DWORD id = 0; m_ThreadID = CreateThread( NULL, 0, CThread_ThreadEntry, this, 0, &id ); return ( m_ThreadID != NULL ); #else // POSIXの場合 pthread_attr_t att; int r; pthread_attr_init( &att ); pthread_attr_setdetachstate( &att, PTHREAD_CREATE_DETACHED ); r = pthread_create( &m_ThreadID, &att, CThread_ThreadEntry, this ); return ( r == 0 ); #endif } // スレッドのエントリポイント void CThread::run() { } //////////////////////////////////////////////////////////////////////////// // その他 //////////////////////////////////////////////////////////////////////////// // スレッド生成用 #if defined( _WIN32 ) DWORD WINAPI CThread_ThreadEntry( void* pArg ) #else void* CThread_ThreadEntry( void* pArg ) #endif { CThread *p = reinterpret_cast< CThread* >( pArg ); p->run(); return NULL; }