source: rtems/cpukit/score/src/coresem.c @ 3a4ae6c

4.104.114.84.9
Last change on this file since 3a4ae6c was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 11, 1995 at 7:35:39 PM

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  CORE Semaphore Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the CORE Semaphore Handler.
7 *  This core object utilizes standard Dijkstra counting semaphores to provide
8 *  synchronization and mutual exclusion capabilities.
9 *
10 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
11 *  On-Line Applications Research Corporation (OAR).
12 *  All rights assigned to U.S. Government, 1994.
13 *
14 *  This material may be reproduced by or for the U.S. Government pursuant
15 *  to the copyright license under the clause at DFARS 252.227-7013.  This
16 *  notice must appear in all copies of this file and its derivatives.
17 *
18 *  $Id$
19 */
20
21#include <rtems/system.h>
22#include <rtems/core/isr.h>
23#include <rtems/core/coresem.h>
24#include <rtems/core/states.h>
25#include <rtems/core/thread.h>
26#include <rtems/core/threadq.h>
27#include <rtems/core/mpci.h>
28
29/*PAGE
30 *
31 *  CORE_semaphore_Initialize
32 *
33 *  This function initialize a semaphore and sets the initial value based
34 *  on the given count.
35 *
36 *  Input parameters:
37 *    the_semaphore            - the semaphore control block to initialize
38 *    the_class                - the API class of the object
39 *    the_semaphore_attributes - the attributes specified at create time
40 *    initial_value            - semaphore's initial value
41 *    proxy_extract_callout    - MP specific extract callout
42 *
43 *  Output parameters:  NONE
44 */
45
46void _CORE_semaphore_Initialize(
47  CORE_semaphore_Control       *the_semaphore,
48  Objects_Classes               the_class,
49  CORE_semaphore_Attributes    *the_semaphore_attributes,
50  unsigned32                    initial_value,
51  Thread_queue_Extract_callout  proxy_extract_callout
52)
53{
54
55  the_semaphore->Attributes = *the_semaphore_attributes;
56  the_semaphore->count      = initial_value;
57
58  _Thread_queue_Initialize(
59    &the_semaphore->Wait_queue,
60    the_class,
61    _CORE_semaphore_Is_priority( the_semaphore_attributes ) ?
62              THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
63    STATES_WAITING_FOR_SEMAPHORE,
64    proxy_extract_callout,
65    CORE_SEMAPHORE_TIMEOUT
66  );
67}
68
69/*PAGE
70 *
71 *  _CORE_semaphore_Surrender
72 *
73 *  Input parameters:
74 *    the_semaphore            - the semaphore to be flushed
75 *    id                       - id of parent semaphore
76 *    api_semaphore_mp_support - api dependent MP support actions
77 *
78 *  Output parameters:
79 *    CORE_SEMAPHORE_STATUS_SUCCESSFUL - if successful
80 *    core error code                  - if unsuccessful
81 *
82 *  Output parameters:
83 */
84
85CORE_semaphore_Status _CORE_semaphore_Surrender(
86  CORE_semaphore_Control                *the_semaphore,
87  Objects_Id                             id,
88  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support
89)
90{
91  Thread_Control *the_thread;
92
93  if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) {
94
95    if ( !_Objects_Is_local_id( the_thread->Object.id ) )
96      (*api_semaphore_mp_support) ( the_thread, id );
97
98  } else
99    the_semaphore->count += 1;
100
101  return( CORE_SEMAPHORE_STATUS_SUCCESSFUL );
102}
103
104/*PAGE
105 *
106 *  _CORE_semaphore_Seize
107 *
108 *  This routine attempts to allocate a core semaphore to the calling thread.
109 *
110 *  Input parameters:
111 *    the_semaphore - pointer to semaphore control block
112 *    id            - id of object to wait on
113 *    wait          - TRUE if wait is allowed, FALSE otherwise
114 *    timeout       - number of ticks to wait (0 means forever)
115 *
116 *  Output parameters:  NONE
117 *
118 *  INTERRUPT LATENCY:
119 *    available
120 *    wait
121 */
122
123void _CORE_semaphore_Seize(
124  CORE_semaphore_Control  *the_semaphore,
125  Objects_Id               id,
126  boolean                  wait,
127  Watchdog_Interval        timeout
128)
129{
130  Thread_Control *executing;
131  ISR_Level       level;
132
133  executing = _Thread_Executing;
134  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
135  _ISR_Disable( level );
136  if ( the_semaphore->count != 0 ) {
137    the_semaphore->count -= 1;
138    executing->resource_count++;
139    _ISR_Enable( level );
140    return;
141  }
142
143  if ( !wait ) {
144    _ISR_Enable( level );
145    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
146    return;
147  }
148
149  the_semaphore->Wait_queue.sync = TRUE;
150  executing->Wait.queue          = &the_semaphore->Wait_queue;
151  executing->Wait.id             = id;
152  _ISR_Enable( level );
153
154  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
155}
156
157
158/*PAGE
159 *
160 *  _CORE_semaphore_Flush
161 *
162 *  This function a flushes the semaphore's task wait queue.
163 *
164 *  Input parameters:
165 *    the_semaphore          - the semaphore to be flushed
166 *    remote_extract_callout - function to invoke remotely
167 *    status                 - status to pass to thread
168 *
169 *  Output parameters:  NONE
170 */
171 
172void _CORE_semaphore_Flush(
173  CORE_semaphore_Control     *the_semaphore,
174  Thread_queue_Flush_callout  remote_extract_callout,
175  unsigned32                  status
176)
177{
178 
179  _Thread_queue_Flush(
180    &the_semaphore->Wait_queue,
181    remote_extract_callout,
182    status
183  );
184 
185}
Note: See TracBrowser for help on using the repository browser.