OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [condinit.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
2 208 chris
 *  $Id: condinit.c,v 1.2 2001-09-27 11:59:17 chris Exp $
3 158 chris
 */
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
 
22
int 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
 
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
 
95
    );
96
#endif
97
 
98
  _Thread_Enable_dispatch();
99
 
100
  return 0;
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.