simplify; use SemaImpl_Pthreads instead of using low-level semaphores in two places
This commit is contained in:
@@ -96,7 +96,7 @@ static void *StartThread( void *pData )
|
|||||||
*pThis->m_piThreadID = pThis->GetThreadId();
|
*pThis->m_piThreadID = pThis->GetThreadId();
|
||||||
|
|
||||||
/* Tell MakeThread that we've set m_piThreadID, so it's safe to return. */
|
/* Tell MakeThread that we've set m_piThreadID, so it's safe to return. */
|
||||||
sem_post( &pThis->m_StartFinishedSem );
|
pThis->m_StartFinishedSem->Post();
|
||||||
|
|
||||||
return (void *) pThis->m_pFunc( pThis->m_pData );
|
return (void *) pThis->m_pFunc( pThis->m_pData );
|
||||||
}
|
}
|
||||||
@@ -107,17 +107,16 @@ ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThre
|
|||||||
thread->m_pFunc = pFunc;
|
thread->m_pFunc = pFunc;
|
||||||
thread->m_pData = pData;
|
thread->m_pData = pData;
|
||||||
thread->m_piThreadID = piThreadID;
|
thread->m_piThreadID = piThreadID;
|
||||||
sem_init( &thread->m_StartFinishedSem, 0, 0 );
|
|
||||||
|
thread->m_StartFinishedSem = new SemaImpl_Pthreads( 0 );
|
||||||
|
|
||||||
int ret = pthread_create( &thread->thread, NULL, StartThread, thread );
|
int ret = pthread_create( &thread->thread, NULL, StartThread, thread );
|
||||||
if( ret )
|
if( ret )
|
||||||
FAIL_M( ssprintf( "MakeThread: pthread_create: %s", strerror(errno)) );
|
FAIL_M( ssprintf( "MakeThread: pthread_create: %s", strerror(errno)) );
|
||||||
|
|
||||||
/* Don't return until StartThread sets m_piThreadID. */
|
/* Don't return until StartThread sets m_piThreadID. */
|
||||||
ret = sem_wait( &thread->m_StartFinishedSem );
|
thread->m_StartFinishedSem->Wait();
|
||||||
if( ret )
|
delete thread->m_StartFinishedSem;
|
||||||
FAIL_M( ssprintf( "MakeThread: sem_wait: %s", strerror(errno)) );
|
|
||||||
sem_destroy( &thread->m_StartFinishedSem );
|
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
int (*m_pFunc)( void *pData );
|
int (*m_pFunc)( void *pData );
|
||||||
void *m_pData;
|
void *m_pData;
|
||||||
uint64_t *m_piThreadID;
|
uint64_t *m_piThreadID;
|
||||||
sem_t m_StartFinishedSem;
|
SemaImpl *m_StartFinishedSem;
|
||||||
|
|
||||||
void Halt( bool Kill );
|
void Halt( bool Kill );
|
||||||
void Resume();
|
void Resume();
|
||||||
|
|||||||
Reference in New Issue
Block a user