source: rtems/cpukit/score/src/coresemseize.c @ 7fa97181

Last change on this file since 7fa97181 was a6eef8b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:52:48

2003-09-04 Joel Sherrill <joel@…>

  • apiext.c, chain.c, coremsg.c, coremsgbroadcast.c, coremsgclose.c, coremsgflush.c, coremsgflushsupp.c, coremsgflushwait.c, coremsginsert.c, coremsgseize.c, coremsgsubmit.c, coremutex.c, coremutexflush.c, coremutexseize.c, coremutexsurrender.c, coresem.c, coresemflush.c, coresemseize.c, coresemsurrender.c, coretod.c, coretodset.c, coretodtickle.c, coretodtoseconds.c, coretodvalidate.c, heap.c, heapallocate.c, heapextend.c, heapfree.c, heapgetinfo.c, heapsizeofuserarea.c, heapwalk.c, interr.c, isr.c, mpci.c, object.c, objectallocate.c, objectallocatebyindex.c, objectclearname.c, objectcomparenameraw.c, objectcomparenamestring.c, objectcopynameraw.c, objectcopynamestring.c, objectextendinformation.c, objectfree.c, objectget.c, objectgetbyindex.c, objectgetisr.c, objectgetnext.c, objectgetnoprotection.c, objectinitializeinformation.c, objectmp.c, objectnametoid.c, objectshrinkinformation.c, thread.c, threadchangepriority.c, threadclearstate.c, threadclose.c, threadcreateidle.c, threaddelayended.c, threaddispatch.c, threadevaluatemode.c, threadget.c, threadhandler.c, threadidlebody.c, threadinitialize.c, threadloadenv.c, threadmp.c, threadq.c, threadqdequeue.c, threadqdequeuefifo.c, threadqdequeuepriority.c, threadqenqueue.c, threadqenqueuefifo.c, threadqenqueuepriority.c, threadqextract.c, threadqextractfifo.c, threadqextractpriority.c, threadqextractwithproxy.c, threadqfirst.c, threadqfirstfifo.c, threadqfirstpriority.c, threadqflush.c, threadqtimeout.c, threadready.c, threadreset.c, threadresettimeslice.c, threadrestart.c, threadresume.c, threadrotatequeue.c, threadsetpriority.c, threadsetstate.c, threadsettransient.c, threadstackallocate.c, threadstackfree.c, threadstart.c, threadstartmultitasking.c, threadsuspend.c, threadtickletimeslice.c, threadyieldprocessor.c, userext.c, watchdog.c, watchdogadjust.c, watchdoginsert.c, watchdogremove.c, watchdogtickle.c, wkspace.c: URL for license changed.
  • 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.rtems.com/license/LICENSE.
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.