1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #if HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <pthread.h> |
---|
10 | #include <errno.h> |
---|
11 | |
---|
12 | #include <rtems/system.h> |
---|
13 | #include <rtems/score/object.h> |
---|
14 | #include <rtems/score/states.h> |
---|
15 | #include <rtems/score/watchdog.h> |
---|
16 | #include <rtems/posix/cond.h> |
---|
17 | #include <rtems/posix/time.h> |
---|
18 | #include <rtems/posix/mutex.h> |
---|
19 | |
---|
20 | /*PAGE |
---|
21 | * |
---|
22 | * 11.4.2 Initializing and Destroying a Condition Variable, |
---|
23 | * P1003.1c/Draft 10, p. 87 |
---|
24 | */ |
---|
25 | |
---|
26 | int pthread_cond_init( |
---|
27 | pthread_cond_t *cond, |
---|
28 | const pthread_condattr_t *attr |
---|
29 | ) |
---|
30 | { |
---|
31 | POSIX_Condition_variables_Control *the_cond; |
---|
32 | const pthread_condattr_t *the_attr; |
---|
33 | |
---|
34 | if ( attr ) the_attr = attr; |
---|
35 | else the_attr = &_POSIX_Condition_variables_Default_attributes; |
---|
36 | |
---|
37 | /* |
---|
38 | * XXX: Be careful about attributes when global!!! |
---|
39 | */ |
---|
40 | |
---|
41 | if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) |
---|
42 | return POSIX_MP_NOT_IMPLEMENTED(); |
---|
43 | |
---|
44 | if ( !the_attr->is_initialized ) |
---|
45 | return EINVAL; |
---|
46 | |
---|
47 | _Thread_Disable_dispatch(); |
---|
48 | |
---|
49 | the_cond = _POSIX_Condition_variables_Allocate(); |
---|
50 | |
---|
51 | if ( !the_cond ) { |
---|
52 | _Thread_Enable_dispatch(); |
---|
53 | return ENOMEM; |
---|
54 | } |
---|
55 | |
---|
56 | #if defined(RTEMS_MULTIPROCESSING) |
---|
57 | if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED && |
---|
58 | !( _Objects_MP_Allocate_and_open( &_POSIX_Condition_variables_Information, |
---|
59 | 0, the_cond->Object.id, FALSE ) ) ) { |
---|
60 | _POSIX_Condition_variables_Free( the_cond ); |
---|
61 | _Thread_Enable_dispatch(); |
---|
62 | return EAGAIN; |
---|
63 | } |
---|
64 | #endif |
---|
65 | |
---|
66 | the_cond->process_shared = the_attr->process_shared; |
---|
67 | |
---|
68 | the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX; |
---|
69 | |
---|
70 | /* XXX some more initialization might need to go here */ |
---|
71 | _Thread_queue_Initialize( |
---|
72 | &the_cond->Wait_queue, |
---|
73 | THREAD_QUEUE_DISCIPLINE_FIFO, |
---|
74 | STATES_WAITING_FOR_CONDITION_VARIABLE, |
---|
75 | ETIMEDOUT |
---|
76 | ); |
---|
77 | |
---|
78 | _Objects_Open( |
---|
79 | &_POSIX_Condition_variables_Information, |
---|
80 | &the_cond->Object, |
---|
81 | 0 |
---|
82 | ); |
---|
83 | |
---|
84 | *cond = the_cond->Object.id; |
---|
85 | |
---|
86 | #if defined(RTEMS_MULTIPROCESSING) |
---|
87 | if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) |
---|
88 | _POSIX_Condition_variables_MP_Send_process_packet( |
---|
89 | POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_CREATE, |
---|
90 | the_cond->Object.id, |
---|
91 | 0, /* Name not used */ |
---|
92 | 0 /* Not used */ |
---|
93 | ); |
---|
94 | #endif |
---|
95 | |
---|
96 | _Thread_Enable_dispatch(); |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|