source: rtems/cpukit/posix/src/pbarrierdestroy.c @ 23fec9f0

4.115
Last change on this file since 23fec9f0 was 23fec9f0, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 13:16:12

score: PR2152: Use allocator mutex for objects

Use allocator mutex for objects allocate/free. This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Destroy a Barrier Object
5 *  @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22#include <errno.h>
23
24#include <rtems/system.h>
25#include <rtems/posix/barrierimpl.h>
26
27/**
28 *  This directive allows a thread to delete a barrier specified by
29 *  the barrier id.  The barrier is freed back to the inactive
30 *  barrier chain.
31 *
32 *  @param[in] barrier is the barrier id
33 *
34 *  @return This method returns 0 if there was not an
35 *  error. Otherwise, a status code is returned indicating the
36 *  source of the error.
37 */
38int pthread_barrier_destroy(
39  pthread_barrier_t *barrier
40)
41{
42  POSIX_Barrier_Control *the_barrier = NULL;
43  Objects_Locations      location;
44
45  if ( !barrier )
46    return EINVAL;
47
48  _Objects_Allocator_lock();
49  the_barrier = _POSIX_Barrier_Get( barrier, &location );
50  switch ( location ) {
51
52    case OBJECTS_LOCAL:
53      if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) {
54        _Objects_Put( &the_barrier->Object );
55        return EBUSY;
56      }
57
58      _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
59      _Objects_Put( &the_barrier->Object );
60
61      _POSIX_Barrier_Free( the_barrier );
62      _Objects_Allocator_unlock();
63      return 0;
64
65#if defined(RTEMS_MULTIPROCESSING)
66    case OBJECTS_REMOTE:
67#endif
68    case OBJECTS_ERROR:
69      break;
70  }
71
72  _Objects_Allocator_unlock();
73
74  return EINVAL;
75}
Note: See TracBrowser for help on using the repository browser.