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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [posix/] [src/] [condwaitsupp.c] - Blame information for rev 1779

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  condwaitsupp.c,v 1.2 2001/01/24 14:17:28 joel Exp
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
 *  _POSIX_Condition_variables_Wait_support
23
 *
24
 *  A support routine which implements guts of the blocking, non-blocking, and
25
 *  timed wait version of condition variable wait routines.
26
 */
27
 
28
int _POSIX_Condition_variables_Wait_support(
29
  pthread_cond_t            *cond,
30
  pthread_mutex_t           *mutex,
31
  Watchdog_Interval          timeout,
32
  boolean                    already_timedout
33
)
34
{
35
  register POSIX_Condition_variables_Control *the_cond;
36
  Objects_Locations                           location;
37
  int                                         status;
38
  int                                         mutex_status;
39
 
40
  if ( !_POSIX_Mutex_Get( mutex, &location ) ) {
41
     return EINVAL;
42
  }
43
 
44
  _Thread_Unnest_dispatch();
45
 
46
  the_cond = _POSIX_Condition_variables_Get( cond, &location );
47
  switch ( location ) {
48
    case OBJECTS_REMOTE:
49
#if defined(RTEMS_MULTIPROCESSING)
50
      _Thread_Dispatch();
51
      return POSIX_MP_NOT_IMPLEMENTED();
52
      return EINVAL;
53
#endif
54
    case OBJECTS_ERROR:
55
      return EINVAL;
56
    case OBJECTS_LOCAL:
57
 
58
      if ( the_cond->Mutex && ( the_cond->Mutex != *mutex ) ) {
59
        _Thread_Enable_dispatch();
60
        return EINVAL;
61
      }
62
 
63
      (void) pthread_mutex_unlock( mutex );
64
/* XXX ignore this for now  since behavior is undefined
65
      if ( mutex_status ) {
66
        _Thread_Enable_dispatch();
67
        return EINVAL;
68
      }
69
*/
70
 
71
      if ( !already_timedout ) {
72
        the_cond->Mutex = *mutex;
73
 
74
        _Thread_queue_Enter_critical_section( &the_cond->Wait_queue );
75
        _Thread_Executing->Wait.return_code = 0;
76
        _Thread_Executing->Wait.queue       = &the_cond->Wait_queue;
77
        _Thread_Executing->Wait.id          = *cond;
78
 
79
        _Thread_queue_Enqueue( &the_cond->Wait_queue, timeout );
80
 
81
        _Thread_Enable_dispatch();
82
 
83
        /*
84
         *  Switch ourself out because we blocked as a result of the
85
         *  _Thread_queue_Enqueue.
86
         */
87
 
88
        status = _Thread_Executing->Wait.return_code;
89
        if ( status && status != ETIMEDOUT )
90
          return status;
91
 
92
      } else {
93
        _Thread_Enable_dispatch();
94
        status = ETIMEDOUT;
95
      }
96
 
97
      /*
98
       *  When we get here the dispatch disable level is 0.
99
       */
100
 
101
      mutex_status = pthread_mutex_lock( mutex );
102
      if ( mutex_status )
103
        return EINVAL;
104
 
105
      return status;
106
  }
107
  return POSIX_BOTTOM_REACHED();
108
}

powered by: WebSVN 2.1.0

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