source: rtems/cpukit/score/src/coremutex.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.4 KB
Line 
1/*
2 *  Mutex Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the Mutex Handler.
7 *  This handler provides synchronization and mutual exclusion capabilities.
8 *
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#include <rtems/system.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/coremutex.h>
22#include <rtems/score/states.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25
26/*PAGE
27 *
28 *  _CORE_mutex_Initialize
29 *
30 *  This routine initializes a mutex at create time and set the control
31 *  structure according to the values passed.
32 *
33 *  Input parameters:
34 *    the_mutex             - the mutex control block to initialize
35 *    the_mutex_attributes  - the mutex attributes specified at create time
36 *    initial_lock          - mutex initial lock or unlocked status
37 *
38 *  Output parameters:  NONE
39 */
40
41void _CORE_mutex_Initialize(
42  CORE_mutex_Control           *the_mutex,
43  CORE_mutex_Attributes        *the_mutex_attributes,
44  unsigned32                    initial_lock
45)
46{
47
48/* Add this to the RTEMS environment later ?????????
49  rtems_assert( initial_lock == CORE_MUTEX_LOCKED ||
50                initial_lock == CORE_MUTEX_UNLOCKED );
51 */
52
53  the_mutex->Attributes    = *the_mutex_attributes;
54  the_mutex->lock          = initial_lock;
55  the_mutex->blocked_count = 0;
56
57#if 0
58  if ( !the_mutex_attributes->only_owner_release &&
59       the_mutex_attributes->nesting_allowed ) {
60    _Internal_error_Occurred(
61      INTERNAL_ERROR_CORE,
62      TRUE,
63      INTERNAL_ERROR_BAD_ATTRIBUTES
64    );
65  }
66#endif
67
68  if ( initial_lock == CORE_MUTEX_LOCKED ) {
69    the_mutex->nest_count = 1;
70    the_mutex->holder     = _Thread_Executing;
71    the_mutex->holder_id  = _Thread_Executing->Object.id;
72    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
73         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
74      _Thread_Executing->resource_count++;
75  } else {
76    the_mutex->nest_count = 0;
77    the_mutex->holder     = NULL;
78    the_mutex->holder_id  = 0;
79  }
80
81  _Thread_queue_Initialize(
82    &the_mutex->Wait_queue,
83    _CORE_mutex_Is_fifo( the_mutex_attributes ) ?
84      THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY,
85    STATES_WAITING_FOR_MUTEX,
86    CORE_MUTEX_TIMEOUT
87  );
88}
89
Note: See TracBrowser for help on using the repository browser.