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

4.104.114.95
Last change on this file since b3836ce was b3836ce, checked in by Joel Sherrill <joel.sherrill@…>, on 09/05/08 at 21:54:20

2008-09-05 Joel Sherrill <joel.sherrill@…>

  • score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/coremsg.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/corerwlock.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coresemseize.c, score/src/coresemsurrender.c, score/src/corespinlock.c, score/src/threadblockingoperationcancel.c, score/src/threadqenqueue.c: Remove unnecessary include of mpci.h.
  • 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/*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  bool                    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  /*
70   *  If the semaphore was not available and the caller was not willing
71   *  to block, then return immediately with a status indicating that
72   *  the semaphore was not available and the caller never blocked.
73   */
74  if ( !wait ) {
75    _ISR_Enable( level );
76    executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT;
77    return;
78  }
79
80  /*
81   *  If the semaphore is not available and the caller is willing to
82   *  block, then we now block the caller with optional timeout.
83   */
84  _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue );
85  executing->Wait.queue = &the_semaphore->Wait_queue;
86  executing->Wait.id    = id;
87  _ISR_Enable( level );
88  _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout );
89}
Note: See TracBrowser for help on using the repository browser.