source: rtems/cpukit/score/src/coresemseize.c @ 25f5730f

4.11
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Core Semaphore Seize
5 *
6 * @ingroup ScoreSemaphore
7 */
8
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.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/system.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/coresemimpl.h>
25#include <rtems/score/thread.h>
26
27#if defined(RTEMS_SCORE_CORESEM_ENABLE_SEIZE_BODY)
28
29void _CORE_semaphore_Seize(
30  CORE_semaphore_Control *the_semaphore,
31  Thread_Control         *executing,
32  Objects_Id              id,
33  bool                    wait,
34  Watchdog_Interval       timeout
35)
36{
37  ISR_Level       level;
38
39  executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
40  _ISR_Disable( level );
41  if ( the_semaphore->count != 0 ) {
42    the_semaphore->count -= 1;
43    _ISR_Enable( level );
44    return;
45  }
46
47  /*
48   *  If the semaphore was not available and the caller was not willing
49   *  to block, then return immediately with a status indicating that
50   *  the semaphore was not available and the caller never blocked.
51   */
52  if ( !wait ) {
53    _ISR_Enable( level );
54    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
55    return;
56  }
57
58  /*
59   *  If the semaphore is not available and the caller is willing to
60   *  block, then we now block the caller with optional timeout.
61   */
62  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
63  executing->Wait.queue = &the_semaphore->Wait_queue;
64  executing->Wait.id    = id;
65  _ISR_Enable( level );
66  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, executing, timeout );
67}
68#endif
Note: See TracBrowser for help on using the repository browser.