source: rtems/cpukit/score/src/coresemseize.c @ d7c3883

4.115
Last change on this file since d7c3883 was 28352fae, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 13:51:53

Whitespace removal.

  • Property mode set to 100644
File size: 2.4 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-2008.
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.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/system.h>
25#include <rtems/score/isr.h>
26#include <rtems/score/coresem.h>
27#include <rtems/score/states.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30
31#if defined(RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY)
32/*
33 *  This routine attempts to allocate a core semaphore to the calling thread.
34 *
35 *  Input parameters:
36 *    the_semaphore - pointer to semaphore control block
37 *    id            - id of object to wait on
38 *    wait          - true if wait is allowed, false otherwise
39 *    timeout       - number of ticks to wait (0 means forever)
40 *
41 *  Output parameters:  NONE
42 *
43 *  INTERRUPT LATENCY:
44 *    available
45 *    wait
46 */
47
48void _CORE_semaphore_Seize(
49  CORE_semaphore_Control *the_semaphore,
50  Objects_Id              id,
51  bool                    wait,
52  Watchdog_Interval       timeout
53)
54{
55  Thread_Control *executing;
56  ISR_Level       level;
57
58  executing = _Thread_Executing;
59  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
60  _ISR_Disable( level );
61  if ( the_semaphore->count != 0 ) {
62    the_semaphore->count -= 1;
63    _ISR_Enable( level );
64    return;
65  }
66
67  /*
68   *  If the semaphore was not available and the caller was not willing
69   *  to block, then return immediately with a status indicating that
70   *  the semaphore was not available and the caller never blocked.
71   */
72  if ( !wait ) {
73    _ISR_Enable( level );
74    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
75    return;
76  }
77
78  /*
79   *  If the semaphore is not available and the caller is willing to
80   *  block, then we now block the caller with optional timeout.
81   */
82  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
83  executing->Wait.queue = &the_semaphore->Wait_queue;
84  executing->Wait.id    = id;
85  _ISR_Enable( level );
86  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
87}
88#endif
Note: See TracBrowser for help on using the repository browser.