Skip to content

Commit 511e95f

Browse files
committed
CSemaphore::waitForSignal() : Fixed error when thread got an external signal
1 parent 793a2ed commit 511e95f

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

doc/doxygen-pages/changeLog_doc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
- mrpt::topography::geodeticToENU_WGS84() and related functions used a local +Z axis aligned to the line towards the Earth center; now the Z axis points normally to the ellipsoid surface. The difference with the previous behavior is small but may be of a few millimeters for each meter from the reference point. [(commit)](http://code.google.com/p/mrpt/source/detail?r=3473)
9090
- Potential crash when setting mpPolygon::setPoints() with empty vectors - [(commit)](http://code.google.com/p/mrpt/source/detail?r=3478)
9191
- mrpt::reactivenav::CReactiveNavigationSystem and mrpt::reactivenav::CReactiveNavigationSystem3D didn't obey the "enableConsoleOutput" constructor flag - [(commit)](https://github.com/jlblancoc/mrpt/commit/db7b0e76506af2c24f119a28443a1e8f1a217861)
92-
92+
- mrpt::synch::CSemaphore::waitForSignal() : Fixed error when thread got an external signal [(commit)]()
9393
9494
<hr>
9595
<a name="1.0.2">

libs/base/src/synch/CSemaphore_LIN.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,22 @@ bool CSemaphore::waitForSignal( unsigned int timelimit )
163163
}
164164

165165
#else
166-
rc = timelimit==0 ?
166+
if (timelimit==0)
167+
{
167168
// No timeout
168-
sem_wait( token->semid )
169-
:
169+
rc = sem_wait( token->semid );
170+
}
171+
else
172+
{
170173
// We have a timeout:
171-
sem_timedwait( token->semid, &tm );
172-
#endif
173-
174+
while ((rc = sem_timedwait( token->semid, &tm )) == -1 && errno == EINTR)
175+
continue; // Restart if interrupted by handler
176+
}
177+
174178
// If there's an error != than a timeout, dump to stderr:
175179
if (rc!=0 && errno!=ETIMEDOUT)
176180
std::cerr << format("[CSemaphore::waitForSignal] In semaphore named '%s', error: %s\n", m_name.c_str(),strerror(errno) );
181+
#endif
177182

178183
return rc==0; // true: all ok.
179184

0 commit comments

Comments
 (0)