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 | |
---|
24 | RTEMS_STATIC_ASSERT( |
---|
25 | offsetof( POSIX_Condition_variables_Control, flags ) |
---|
26 | == offsetof( pthread_cond_t, _flags ), |
---|
27 | POSIX_CONDITION_VARIABLES_CONTROL_FLAGS |
---|
28 | ); |
---|
29 | |
---|
30 | RTEMS_STATIC_ASSERT( |
---|
31 | offsetof( POSIX_Condition_variables_Control, mutex ) |
---|
32 | == offsetof( pthread_cond_t, _mutex ), |
---|
33 | POSIX_CONDITION_VARIABLES_CONTROL_COUNT |
---|
34 | ); |
---|
35 | |
---|
36 | RTEMS_STATIC_ASSERT( |
---|
37 | offsetof( POSIX_Condition_variables_Control, Queue ) |
---|
38 | == offsetof( pthread_cond_t, _Queue ), |
---|
39 | POSIX_CONDITION_VARIABLES_CONTROL_QUEUE |
---|
40 | ); |
---|
41 | |
---|
42 | RTEMS_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 | */ |
---|
51 | int 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 | } |
---|