source: rtems/cpukit/score/src/coresemseize.c @ 2728d9cf

4.104.114.84.95
Last change on this file since 2728d9cf was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.1 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-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#include <rtems/system.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/coresem.h>
23#include <rtems/score/states.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#if defined(RTEMS_MULTIPROCESSING)
27#include <rtems/score/mpci.h>
28#endif
29
30/*PAGE
31 *
32 *  _CORE_semaphore_Seize
33 *
34 *  This routine attempts to allocate a core semaphore to the calling thread.
35 *
36 *  Input parameters:
37 *    the_semaphore - pointer to semaphore control block
38 *    id            - id of object to wait on
39 *    wait          - TRUE if wait is allowed, FALSE otherwise
40 *    timeout       - number of ticks to wait (0 means forever)
41 *
42 *  Output parameters:  NONE
43 *
44 *  INTERRUPT LATENCY:
45 *    available
46 *    wait
47 */
48
49void _CORE_semaphore_Seize(
50  CORE_semaphore_Control  *the_semaphore,
51  Objects_Id               id,
52  boolean                  wait,
53  Watchdog_Interval        timeout
54)
55{
56  Thread_Control *executing;
57  ISR_Level       level;
58
59  executing = _Thread_Executing;
60  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
61  _ISR_Disable( level );
62  if ( the_semaphore->count != 0 ) {
63    the_semaphore->count -= 1;
64    _ISR_Enable( level );
65    return;
66  }
67
68  if ( !wait ) {
69    _ISR_Enable( level );
70    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
71    return;
72  }
73
74  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
75  executing->Wait.queue          = &the_semaphore->Wait_queue;
76  executing->Wait.id             = id;
77  _ISR_Enable( level );
78
79  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
80}
Note: See TracBrowser for help on using the repository browser.