Back to index

glibc  2.9
Functions
barrier.c File Reference
#include <errno.h>
#include "pthread.h"
#include "internals.h"
#include "spinlock.h"
#include "queue.h"
#include "restart.h"

Go to the source code of this file.

Functions

int pthread_barrier_wait (pthread_barrier_t *barrier)
int pthread_barrier_init (pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
int pthread_barrier_destroy (pthread_barrier_t *barrier)
int pthread_barrierattr_init (pthread_barrierattr_t *attr)
int pthread_barrierattr_destroy (pthread_barrierattr_t *attr)
int __pthread_barrierattr_getpshared (const pthread_barrierattr_t *attr, int *pshared)
int pthread_barrierattr_setpshared (pthread_barrierattr_t *attr, int pshared)

Function Documentation

int __pthread_barrierattr_getpshared ( const pthread_barrierattr_t *  attr,
int pshared 
)

Definition at line 110 of file barrier.c.

{
  *pshared = PTHREAD_PROCESS_PRIVATE;
  return 0;
}
int pthread_barrier_destroy ( pthread_barrier_t *  barrier)

Definition at line 90 of file barrier.c.

{
  if (barrier->__ba_waiting != NULL) return EBUSY;
  return 0;
}

Here is the caller graph for this function:

int pthread_barrier_init ( pthread_barrier_t *  barrier,
const pthread_barrierattr_t *  attr,
unsigned int  count 
)

Definition at line 75 of file barrier.c.

{
  if (count == 0)
     return EINVAL;

  __pthread_init_lock(&barrier->__ba_lock);
  barrier->__ba_required = count;
  barrier->__ba_present = 0;
  barrier->__ba_waiting = NULL;
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pthread_barrier_wait ( pthread_barrier_t *  barrier)

Definition at line 29 of file barrier.c.

{
  pthread_descr self = thread_self();
  pthread_descr temp_wake_queue, th;
  int result = 0;

  __pthread_lock(&barrier->__ba_lock, self);

  /* If the required number of threads have achieved rendezvous... */
  if (barrier->__ba_present >= barrier->__ba_required - 1)
    {
      /* ... then this last caller shall be the serial thread */
      result = PTHREAD_BARRIER_SERIAL_THREAD;
      /* Copy and clear wait queue and reset barrier. */
      temp_wake_queue = barrier->__ba_waiting;
      barrier->__ba_waiting = NULL;
      barrier->__ba_present = 0;
    }
  else
    {
      result = 0;
      barrier->__ba_present++;
      enqueue(&barrier->__ba_waiting, self);
    }

  __pthread_unlock(&barrier->__ba_lock);

  if (result == 0)
    {
      /* Non-serial threads have to suspend */
      suspend(self);
      /* We don't bother dealing with cancellation because the POSIX
         spec for barriers doesn't mention that pthread_barrier_wait
         is a cancellation point. */
    }
  else
    {
      /* Serial thread wakes up all others. */
      while ((th = dequeue(&temp_wake_queue)) != NULL)
       restart(th);
    }

  return result;
}

Here is the call graph for this function:

int pthread_barrierattr_destroy ( pthread_barrierattr_t *  attr)

Definition at line 104 of file barrier.c.

{
  return 0;
}

Here is the caller graph for this function:

int pthread_barrierattr_init ( pthread_barrierattr_t *  attr)

Definition at line 97 of file barrier.c.

{
  attr->__pshared = PTHREAD_PROCESS_PRIVATE;
  return 0;
}

Here is the caller graph for this function:

int pthread_barrierattr_setpshared ( pthread_barrierattr_t *  attr,
int  pshared 
)

Definition at line 118 of file barrier.c.

{
  if (pshared != PTHREAD_PROCESS_PRIVATE && pshared != PTHREAD_PROCESS_SHARED)
    return EINVAL;

  /* For now it is not possible to shared a conditional variable.  */
  if (pshared != PTHREAD_PROCESS_PRIVATE)
    return ENOSYS;

  return 0;
}

Here is the caller graph for this function: