Back to index

glibc  2.9
Functions
pthread_barrier_init.c File Reference
#include <errno.h>
#include "pthreadP.h"
#include <lowlevellock.h>

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 25 of file pthread_barrier_init.c.

{
  union sparc_pthread_barrier *ibarrier;

  if (__builtin_expect (count == 0, 0))
    return EINVAL;

  struct pthread_barrierattr *iattr = (struct pthread_barrierattr *) attr;
  if (iattr != NULL)
    {
      if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
         && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
       /* Invalid attribute.  */
       return EINVAL;
    }

  ibarrier = (union sparc_pthread_barrier *) barrier;

  /* Initialize the individual fields.  */
  ibarrier->b.lock = LLL_LOCK_INITIALIZER;
  ibarrier->b.left = count;
  ibarrier->b.init_count = count;
  ibarrier->b.curr_event = 0;
  ibarrier->s.left_lock = 0;
  ibarrier->s.pshared = (iattr && iattr->pshared == PTHREAD_PROCESS_SHARED);

  return 0;
}