コード例 #1
0
ファイル: pspinlock.c プロジェクト: dotrees/tools
int
__pthread_spin_lock (pthread_spinlock_t *lock)
{
  while (! __compare_and_swap ((long int *)lock, 0, 1))
    ;
  return 0;
}
コード例 #2
0
inline int atomic_conditional_increment( int *pw )
{
   // if( *pw != 0 ) ++*pw;
   // return *pw;

   __lwsync();
   int v = *const_cast<volatile int*>(pw);
   for (;;)
   // loop until state is known
   {
      if (v == 0) return 0;
      if (__compare_and_swap(pw, &v, v + 1))
      {
         __isync(); return (v + 1);
      }
   }
}
コード例 #3
0
ファイル: pspinlock.c プロジェクト: dotrees/tools
int
__pthread_spin_trylock (pthread_spinlock_t *lock)
{
  return __compare_and_swap ((long int *)lock, 0, 1) ? 0 : EBUSY;
}