/* Lock the spin lock object LOCK.  If the lock is held by another
   thread spin until it becomes available.  */
int
_pthread_spin_lock (__pthread_spinlock_t *lock)
{
  int i;

#ifdef USE_L4
  /* Start with a small timeout of 2 microseconds, then back off
     exponentially.  */
  l4_time_t timeout;
  timeout = l4_time_period (2);
#else
# warning Do not know how to sleep on this platform.
#endif

  while (1)
    {
      for (i = 0; i < __pthread_spin_count; i++)
	{
	  if (__pthread_spin_trylock (lock) == 0)
	    return 0;
	}

#ifdef USE_L4
      l4_sleep (timeout);

      timeout = l4_time_mul2 (timeout);
      if (timeout == L4_NEVER)
	timeout = L4_TIME_PERIOD_MAX;
#endif
    }
}
Exemple #2
0
/* Lock the spin lock object LOCK.  If the lock is held by another
   thread spin until it becomes available.  */
int
_pthread_spin_lock (__pthread_spinlock_t *lock)
{
  l4_time_t timeout;
  int i;

  /* Start with a small timeout of 2 microseconds, then back off
     exponentially.  */
  timeout = l4_time_period (2);

  while (1)
    {
      for (i = 0; i < __pthread_spin_count; i++)
	{
	  if (__pthread_spin_trylock (lock) == 0)
	    return 0;
	}
      l4_sleep (timeout);

      timeout = l4_time_mul2 (timeout);
      if (timeout == L4_NEVER)
	timeout = L4_TIME_PERIOD_MAX;
    }
}