source: rtems/c/src/exec/posix/src/condinit.c @ 3c465878

4.104.114.84.95
Last change on this file since 3c465878 was 3c465878, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:33:47

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/rtems/posix/key.h, src/cond.c, src/condinit.c, src/intr.c, src/key.c, src/keycreate.c, src/keydelete.c, src/killinfo.c, src/mqueue.c, src/mqueuecreatesupp.c, src/mutex.c, src/mutexinit.c, src/psignal.c, src/pthread.c, src/semaphore.c, src/semaphorecreatesupp.c: Modified as part of above.
  • Property mode set to 100644
File size: 2.3 KB
Line 
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 
26int 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}
Note: See TracBrowser for help on using the repository browser.