source: rtems/cpukit/score/src/coresemseize.c @ 6af81435

4.104.114.84.95
Last change on this file since 6af81435 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.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-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_Seize
34 *
35 *  This routine attempts to allocate a core semaphore to the calling thread.
36 *
37 *  Input parameters:
38 *    the_semaphore - pointer to semaphore control block
39 *    id            - id of object to wait on
40 *    wait          - TRUE if wait is allowed, FALSE otherwise
41 *    timeout       - number of ticks to wait (0 means forever)
42 *
43 *  Output parameters:  NONE
44 *
45 *  INTERRUPT LATENCY:
46 *    available
47 *    wait
48 */
49
50void _CORE_semaphore_Seize(
51  CORE_semaphore_Control  *the_semaphore,
52  Objects_Id               id,
53  boolean                  wait,
54  Watchdog_Interval        timeout
55)
56{
57  Thread_Control *executing;
58  ISR_Level       level;
59
60  executing = _Thread_Executing;
61  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
62  _ISR_Disable( level );
63  if ( the_semaphore->count != 0 ) {
64    the_semaphore->count -= 1;
65    _ISR_Enable( level );
66    return;
67  }
68
69  if ( !wait ) {
70    _ISR_Enable( level );
71    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
72    return;
73  }
74
75  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
76  executing->Wait.queue          = &the_semaphore->Wait_queue;
77  executing->Wait.id             = id;
78  _ISR_Enable( level );
79
80  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
81}
Note: See TracBrowser for help on using the repository browser.