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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [condwaitsupp.c] - Blame information for rev 219

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

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

powered by: WebSVN 2.1.0

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