source: rtems/cpukit/score/src/coresemsurrender.c @ 59d1127

4.104.114.84.95
Last change on this file since 59d1127 was 7cc8d6c, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 21:48:15

Split core mutex and semaphore handlers into separate files.

  • Property mode set to 100644
File size: 2.0 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-1998.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#include <rtems/system.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/coresem.h>
24#include <rtems/score/states.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#if defined(RTEMS_MULTIPROCESSING)
28#include <rtems/score/mpci.h>
29#endif
30
31/*PAGE
32 *
33 *  _CORE_semaphore_Surrender
34 *
35 *  Input parameters:
36 *    the_semaphore            - the semaphore to be flushed
37 *    id                       - id of parent semaphore
38 *    api_semaphore_mp_support - api dependent MP support actions
39 *
40 *  Output parameters:
41 *    CORE_SEMAPHORE_STATUS_SUCCESSFUL - if successful
42 *    core error code                  - if unsuccessful
43 *
44 *  Output parameters:
45 */
46
47CORE_semaphore_Status _CORE_semaphore_Surrender(
48  CORE_semaphore_Control                *the_semaphore,
49  Objects_Id                             id,
50  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support
51)
52{
53  Thread_Control *the_thread;
54  ISR_Level       level;
55  CORE_semaphore_Status status;
56
57  status = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
58
59  if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) {
60
61    if ( !_Objects_Is_local_id( the_thread->Object.id ) )
62      (*api_semaphore_mp_support) ( the_thread, id );
63
64  } else {
65    _ISR_Disable( level );
66      if ( the_semaphore->count <= the_semaphore->Attributes.maximum_count )
67        the_semaphore->count += 1;
68      else
69        status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
70    _ISR_Enable( level );
71  }
72
73  return status;
74}
75
Note: See TracBrowser for help on using the repository browser.