source: rtems/cpukit/posix/src/condinit.c @ 8230a329

5
Last change on this file since 8230a329 was b5bfaaf9, checked in by Gedare Bloom <gedare@…>, on 06/23/16 at 20:55:38

posix: cond_timedwait remember and use clock from condattr

updates #2745

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Initialize a Condition Variable
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 <rtems/posix/condimpl.h>
22
23/**
24 *  11.4.2 Initializing and Destroying a Condition Variable,
25 *         P1003.1c/Draft 10, p. 87
26 */
27int pthread_cond_init(
28  pthread_cond_t           *cond,
29  const pthread_condattr_t *attr
30)
31{
32  POSIX_Condition_variables_Control   *the_cond;
33  const pthread_condattr_t            *the_attr;
34
35  if ( attr ) the_attr = attr;
36  else        the_attr = &_POSIX_Condition_variables_Default_attributes;
37
38  /*
39   *  Be careful about attributes when global!!!
40   */
41  if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
42    return EINVAL;
43
44  if ( !the_attr->is_initialized )
45    return EINVAL;
46
47  the_cond = _POSIX_Condition_variables_Allocate();
48
49  if ( !the_cond ) {
50    _Objects_Allocator_unlock();
51    return ENOMEM;
52  }
53
54  _POSIX_Condition_variables_Initialize( the_cond, the_attr );
55
56  _Objects_Open_u32(
57    &_POSIX_Condition_variables_Information,
58    &the_cond->Object,
59    0
60  );
61
62  *cond = the_cond->Object.id;
63
64  _Objects_Allocator_unlock();
65
66  return 0;
67}
Note: See TracBrowser for help on using the repository browser.