Skip to content

Commit

Permalink
fix ios condition variable
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Nov 12, 2024
1 parent 750a783 commit c790a3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ namespace Mengine
for( ;; )
{
::pthread_mutex_lock( &m_conditionLock );
::pthread_cond_wait( &m_conditionVariable, &m_conditionLock );

struct timespec ts;
::clock_gettime(CLOCK_REALTIME, &ts);

ts.tv_sec += 1;

::pthread_cond_timedwait( &m_conditionVariable, &m_conditionLock, &ts );

::pthread_mutex_unlock( &m_conditionLock );

if( _condition() == true )
Expand Down
21 changes: 14 additions & 7 deletions src/Systems/POSIXThreadSystem/POSIXThreadProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ namespace Mengine
while( m_exit == false )
{
::pthread_mutex_lock( &m_conditionLock );
::pthread_cond_wait( &m_conditionVariable, &m_conditionLock );

struct timespec ts;
::clock_gettime(CLOCK_REALTIME, &ts);

ts.tv_sec += 1;

::pthread_cond_timedwait( &m_conditionVariable, &m_conditionLock, &ts );

::pthread_mutex_unlock( &m_conditionLock );

if( m_exit == true )
Expand All @@ -165,9 +172,7 @@ namespace Mengine
}

::pthread_mutex_lock( &m_taskLock );

m_task = nullptr;

::pthread_mutex_unlock( &m_taskLock );
}

Expand Down Expand Up @@ -207,15 +212,17 @@ namespace Mengine
if( _task->run( m_mutex ) == true )
{
::pthread_mutex_lock( &m_taskLock );

m_task = _task;

::pthread_mutex_unlock( &m_taskLock );

::pthread_cond_signal( &m_conditionVariable );

successful = true;
}
else
{
LOGGER_ASSERTION( "invalid run" );
}
}

::pthread_mutex_unlock( &m_processLock );
Expand Down

0 comments on commit c790a3a

Please sign in to comment.