source: rtems/cpukit/posix/src/condinit.c @ 77fbbd6

5
Last change on this file since 77fbbd6 was 5222488, checked in by Sebastian Huber <sebastian.huber@…>, on 09/26/17 at 05:49:17

posix: Implement self-contained POSIX condvar

POSIX condition variables are now available in all configurations and no
longer depend on --enable-posix.

Update #2514.
Update #3113.

  • Property mode set to 100644
File size: 1.7 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#include <rtems/posix/posixapi.h>
23
24RTEMS_STATIC_ASSERT(
25  offsetof( POSIX_Condition_variables_Control, flags )
26    == offsetof( pthread_cond_t, _flags ),
27  POSIX_CONDITION_VARIABLES_CONTROL_FLAGS
28);
29
30RTEMS_STATIC_ASSERT(
31  offsetof( POSIX_Condition_variables_Control, mutex )
32    == offsetof( pthread_cond_t, _mutex ),
33  POSIX_CONDITION_VARIABLES_CONTROL_COUNT
34);
35
36RTEMS_STATIC_ASSERT(
37  offsetof( POSIX_Condition_variables_Control, Queue )
38    == offsetof( pthread_cond_t, _Queue ),
39  POSIX_CONDITION_VARIABLES_CONTROL_QUEUE
40);
41
42RTEMS_STATIC_ASSERT(
43  sizeof( POSIX_Condition_variables_Control ) == sizeof( pthread_cond_t ),
44  POSIX_CONDITION_VARIABLES_CONTROL_SIZE
45);
46
47/**
48 *  11.4.2 Initializing and Destroying a Condition Variable,
49 *         P1003.1c/Draft 10, p. 87
50 */
51int pthread_cond_init(
52  pthread_cond_t           *cond,
53  const pthread_condattr_t *attr
54)
55{
56  POSIX_Condition_variables_Control *the_cond;
57
58  the_cond = _POSIX_Condition_variables_Get( cond );
59
60  if ( the_cond == NULL ) {
61    return EINVAL;
62  }
63
64  if ( attr == NULL ) {
65    attr = &_POSIX_Condition_variables_Default_attributes;
66  }
67
68  if ( !attr->is_initialized ) {
69    return EINVAL;
70  }
71
72  if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) {
73    return EINVAL;
74  }
75
76  _POSIX_Condition_variables_Initialize( the_cond, attr );
77  return 0;
78}
Note: See TracBrowser for help on using the repository browser.