Back to index

glibc  2.9
Functions | Variables
pthread_barrier_init.c File Reference
#include <errno.h>
#include "pthreadP.h"
#include <lowlevellock.h>
#include <kernel-features.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)

Variables

static struct pthread_barrierattr

Function Documentation

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

Definition at line 33 of file pthread_barrier_init.c.

{
  struct pthread_barrier *ibarrier;

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

  const struct pthread_barrierattr *iattr
    = (attr != NULL
       ? iattr = (struct pthread_barrierattr *) attr
       : &default_attr);

  if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
      && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
    /* Invalid attribute.  */
    return EINVAL;

  ibarrier = (struct pthread_barrier *) barrier;

  /* Initialize the individual fields.  */
  ibarrier->lock = LLL_LOCK_INITIALIZER;
  ibarrier->left = count;
  ibarrier->init_count = count;
  ibarrier->curr_event = 0;

#ifdef __ASSUME_PRIVATE_FUTEX
  ibarrier->private = (iattr->pshared != PTHREAD_PROCESS_PRIVATE
                     ? 0 : FUTEX_PRIVATE_FLAG);
#else
  ibarrier->private = (iattr->pshared != PTHREAD_PROCESS_PRIVATE
                     ? 0 : THREAD_GETMEM (THREAD_SELF,
                                       header.private_futex));
#endif

  return 0;
}

Variable Documentation

struct pthread_barrierattr [static]
Initial value:
  {
    .pshared = PTHREAD_PROCESS_PRIVATE
  }

Definition at line 26 of file pthread_barrier_init.c.