Skip to content

Commit

Permalink
[XrdCl/XrdSys] use custom semaphores only for glibc<2.21
Browse files Browse the repository at this point in the history
- reorder pthread cleanap and setcanceltype statements in order to avoid
  a race condition
- use custom semaphores only for glibc<2.21 (in glibc>=2.21 the
  semaphore problem has been fixed)
  • Loading branch information
simonmichal committed Feb 2, 2016
1 parent 37f6a05 commit e3da2c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/XrdCl/XrdClUglyHacks.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
#include "XrdSys/XrdSysLinuxSemaphore.hh"
#include "XrdSys/XrdSysPthread.hh"

#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
#define USE_LIBC_SEMAPHORE (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 21) // in libc >= 2.21 the semaphore problem has been fixed
#else
#define USE_LIBC_SEMAPHORE 0
#endif

namespace XrdCl
{
#if defined(__linux__) && defined(HAVE_ATOMICS)
#if defined(__linux__) && defined(HAVE_ATOMICS) && !USE_LIBC_SEMAPHORE
typedef XrdSys::LinuxSemaphore Semaphore;
#else
typedef XrdSysSemaphore Semaphore;
Expand Down
4 changes: 2 additions & 2 deletions src/XrdSys/XrdSysLinuxSemaphore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ namespace XrdSys
{
int r = 0;

pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );
pthread_cleanup_push( Cleanup, pValue );
pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, 0 );

r = syscall( SYS_futex, pValue, FUTEX_WAIT, newVal, 0, 0, 0 );

pthread_cleanup_pop( 0 );
pthread_setcanceltype( PTHREAD_CANCEL_DEFERRED, 0 );
pthread_cleanup_pop( 0 );

if( r == 0 ) // we've been woken up
break;
Expand Down

0 comments on commit e3da2c2

Please sign in to comment.