source: rtems/cpukit/posix/src/condinit.c @ 43ed935

4.104.114.84.95
Last change on this file since 43ed935 was 43ed935, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 18:46:30

Missed these in the initial split up.

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