source: rtems/cpukit/posix/src/condinit.c @ c838e2f4

4.115
Last change on this file since c838e2f4 was c838e2f4, checked in by Joel Sherrill <joel.sherrill@…>, on 07/28/10 at 20:39:48

2010-07-28 Vinu Rajashekhar <vinutheraj@…>

  • posix/src/condinit.c, posix/src/condwaitsupp.c, posix/src/psignalunblockthread.c: Clean up some signal interruption code.
  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2007.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <pthread.h>
17#include <errno.h>
18
19#include <rtems/system.h>
20#include <rtems/score/object.h>
21#include <rtems/score/states.h>
22#include <rtems/score/watchdog.h>
23#include <rtems/posix/cond.h>
24#include <rtems/posix/time.h>
25#include <rtems/posix/mutex.h>
26
27/*PAGE
28 *
29 *  11.4.2 Initializing and Destroying a Condition Variable,
30 *         P1003.1c/Draft 10, p. 87
31 */
32
33int pthread_cond_init(
34  pthread_cond_t           *cond,
35  const pthread_condattr_t *attr
36)
37{
38  POSIX_Condition_variables_Control   *the_cond;
39  const pthread_condattr_t            *the_attr;
40
41  if ( attr ) the_attr = attr;
42  else        the_attr = &_POSIX_Condition_variables_Default_attributes;
43
44  /*
45   *  Be careful about attributes when global!!!
46   */
47  if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED )
48    return EINVAL;
49
50  if ( !the_attr->is_initialized )
51    return EINVAL;
52
53  _Thread_Disable_dispatch();
54
55  the_cond = _POSIX_Condition_variables_Allocate();
56
57  if ( !the_cond ) {
58    _Thread_Enable_dispatch();
59    return ENOMEM;
60  }
61
62  the_cond->process_shared  = the_attr->process_shared;
63
64  the_cond->Mutex = POSIX_CONDITION_VARIABLES_NO_MUTEX;
65
66  _Thread_queue_Initialize(
67    &the_cond->Wait_queue,
68    THREAD_QUEUE_DISCIPLINE_FIFO,
69    STATES_WAITING_FOR_CONDITION_VARIABLE | STATES_INTERRUPTIBLE_BY_SIGNAL,
70    ETIMEDOUT
71  );
72
73  _Objects_Open_u32(
74    &_POSIX_Condition_variables_Information,
75    &the_cond->Object,
76    0
77  );
78
79  *cond = the_cond->Object.id;
80
81  _Thread_Enable_dispatch();
82
83  return 0;
84}
Note: See TracBrowser for help on using the repository browser.