summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pbarrierdestroy.c
blob: 90e59d6bea2ed6d3bdaf6d5fd51b3bebf820ade0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 *  @file
 *
 *  @brief Destroy a Barrier Object 
 *  @ingroup POSIXAPI
 */

/*
 *  COPYRIGHT (c) 1989-2007.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  Copyright (c) 2017 embedded brains GmbH
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/posix/barrierimpl.h>

int pthread_barrier_destroy( pthread_barrier_t *_barrier )
{
  POSIX_Barrier_Control *barrier;
  Thread_queue_Context   queue_context;

  POSIX_BARRIER_VALIDATE_OBJECT( _barrier );

  barrier = _POSIX_Barrier_Get( _barrier );

  _POSIX_Barrier_Queue_acquire( barrier, &queue_context );

  if ( barrier->waiting_threads != 0 ) {
    _POSIX_Barrier_Queue_release( barrier, &queue_context );
    return EBUSY;
  }

  barrier->flags = 0;
  _POSIX_Barrier_Queue_release( barrier, &queue_context );
  return 0;
}