Ejemplo n.º 1
0
/* A busy mutex can't be destroyed */
static __attribute__((noinline)) int
mutex_ref(pthread_mutex_t *m )
{
    int r = 0;

    _spin_lite_lock(&mutex_global);
    if (!m || !*m)
    {
        _spin_lite_unlock(&mutex_global);
        return EINVAL;
    }
    if (STATIC_INITIALIZER(*m))
    {
        _spin_lite_unlock(&mutex_global);
        r = mutex_static_init(m);
        _spin_lite_lock(&mutex_global);
        if (r != 0 && r != EBUSY)
        {
            _spin_lite_unlock(&mutex_global);
            return r;
        }
    }
    r = 0;
    if (!m || !*m || ((mutex_t *)*m)->valid != LIFE_MUTEX) r = EINVAL;
    else {
        ((mutex_t *)*m)->busy ++;
    }

    _spin_lite_unlock(&mutex_global);

    return r;
}
Ejemplo n.º 2
0
/* A busy mutex can't be destroyed */
static WINPTHREADS_ATTRIBUTE((noinline)) int
mutex_ref (pthread_mutex_t *m)
{
  int r = 0;

  pthread_spin_lock (&mutex_global);

  if (!m || !*m)
  {
    pthread_spin_unlock (&mutex_global);
    return EINVAL;
  }

  if (STATIC_INITIALIZER(*m))
  {
    pthread_spin_unlock (&mutex_global);
    r = mutex_static_init (m);
    pthread_spin_lock (&mutex_global);

    if (r != 0 && r != EBUSY)
    {
      pthread_spin_unlock (&mutex_global);
      return r;
    }
  }
  
  r = 0;
  
  if (!m || !*m || ((mutex_t *)*m)->valid != LIFE_MUTEX) 
    r = EINVAL;
  else
    ((mutex_t *)*m)->busy += 1;

  pthread_spin_unlock (&mutex_global);

  return r;
}