source: rtems/cpukit/rtems/src/semobtain.c @ 3507c6df

4.104.115
Last change on this file since 3507c6df was f773c012, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/08 at 13:32:39

2008-08-04 Sebastian Huber <sebastian.huber@…>

  • rtems/include/rtems/rtems/sem.h, rtems/src/semobtain.c: Changed option set type to rtems_option.
  • score/src/objectgetinfo.c: Check return value of _Objects_API_maximum_class().
  • libmisc/monitor/mon-mpci.c, libmisc/monitor/monitor.h, rtems/include/rtems/rtems/message.h, rtems/src/msgmp.c, rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, score/include/rtems/score/coremsg.h, score/include/rtems/score/mpci.h, score/include/rtems/score/thread.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c: Removed parameters of _Message_queue_Allocate(). Changed option set type to rtems_option. Changed type of maximum message and packet size to size_t. Changed the input buffer type for message send functions to "const void *". Changed the pointer to the second return argument in the thread wait information to a union. This union can contain a pointer to an immutable or a mutable object. This is somewhat fragile. An alternative would be to add a third pointer for immutable objects, but this would increase the structure size.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  Semaphore Manager
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the Semaphore Manager.
7 *  This manager utilizes standard Dijkstra counting semaphores to provide
8 *  synchronization and mutual exclusion capabilities.
9 *
10 *  Directives provided are:
11 *
12 *     + create a semaphore
13 *     + get an ID of a semaphore
14 *     + delete a semaphore
15 *     + acquire a semaphore
16 *     + release a semaphore
17 *
18 *  COPYRIGHT (c) 1989-2008.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 */
27
28#if HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <rtems/system.h>
33#include <rtems/rtems/status.h>
34#include <rtems/rtems/support.h>
35#include <rtems/rtems/attr.h>
36#include <rtems/score/isr.h>
37#include <rtems/score/object.h>
38#include <rtems/rtems/options.h>
39#include <rtems/rtems/sem.h>
40#include <rtems/score/coremutex.h>
41#include <rtems/score/coresem.h>
42#include <rtems/score/states.h>
43#include <rtems/score/thread.h>
44#include <rtems/score/threadq.h>
45#if defined(RTEMS_MULTIPROCESSING)
46#include <rtems/score/mpci.h>
47#endif
48#include <rtems/score/sysstate.h>
49
50#include <rtems/score/interr.h>
51
52/*PAGE
53 *
54 *  rtems_semaphore_obtain
55 *
56 *  This directive allows a thread to acquire a semaphore.
57 *
58 *  Input parameters:
59 *    id         - semaphore id
60 *    option_set - wait option
61 *    timeout    - number of ticks to wait (0 means wait forever)
62 *
63 *  Output parameters:
64 *    RTEMS_SUCCESSFUL - if successful
65 *    error code        - if unsuccessful
66 */
67
68rtems_status_code rtems_semaphore_obtain(
69  rtems_id        id,
70  rtems_option    option_set,
71  rtems_interval  timeout
72)
73{
74  register Semaphore_Control     *the_semaphore;
75  Objects_Locations               location;
76  ISR_Level                       level;
77
78  the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
79  switch ( location ) {
80
81    case OBJECTS_LOCAL:
82      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
83        _CORE_mutex_Seize(
84          &the_semaphore->Core_control.mutex,
85          id,
86          ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE),
87          timeout,
88          level
89        );
90        return _Semaphore_Translate_core_mutex_return_code(
91                  _Thread_Executing->Wait.return_code );
92      }
93
94      /* must be a counting semaphore */
95      _CORE_semaphore_Seize_isr_disable(
96        &the_semaphore->Core_control.semaphore,
97        id,
98        ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE),
99        timeout,
100        &level
101      );
102      return _Semaphore_Translate_core_semaphore_return_code(
103                  _Thread_Executing->Wait.return_code );
104
105#if defined(RTEMS_MULTIPROCESSING)
106    case OBJECTS_REMOTE:
107      return _Semaphore_MP_Send_request_packet(
108          SEMAPHORE_MP_OBTAIN_REQUEST,
109          id,
110          option_set,
111          timeout
112      );
113#endif
114
115    case OBJECTS_ERROR:
116      break;
117
118  }
119
120  return RTEMS_INVALID_ID;
121}
Note: See TracBrowser for help on using the repository browser.