Replace usleep call by nanosleep
Also improve behavior in case signals are delivered to the sleeping thread. This fixes a potential security weakness reported by codacy (interaction of usleep with SIGALRM and other timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is unspecified).
This commit is contained in:
@@ -48,8 +48,10 @@ void epicsAtomicLock ( EpicsAtomicLockKey * )
|
||||
status = pthread_mutex_lock ( & mutex );
|
||||
if ( status == 0 ) return;
|
||||
assert ( status == EINTR );
|
||||
static const useconds_t retryDelayUSec = 100000;
|
||||
usleep ( retryDelayUSec );
|
||||
struct timespec retryDelay = { 0, 100000000 };
|
||||
struct timespec remainingDelay;
|
||||
while (nanosleep(&retryDelay, &remainingDelay) == -1 && errno == EINTR)
|
||||
retryDelay = remainingDelay;
|
||||
countDown--;
|
||||
assert ( countDown );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user