source: rtems/c/src/lib/libbsp/a29k/portsw/shmsupp/lock.c @ 03f2154e

4.104.114.84.95
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:20:27 PM

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  Shared Memory Lock Routines
2 *
3 *  This shared memory locked queue support routine need to be
4 *  able to lock the specified locked queue.  Interrupts are
5 *  disabled while the queue is locked to prevent preemption
6 *  and deadlock when two tasks poll for the same lock.
7 *  previous level.
8 *
9 *  COPYRIGHT (c) 1989-1997.
10 *  On-Line Applications Research Corporation (OAR).
11 *  Copyright assigned to U.S. Government, 1994.
12 *
13 *  The license and distribution terms for this file may in
14 *  the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#include <rtems.h>
21#include <bsp.h>
22#include <shm.h>
23
24#ifndef lint
25static char _sccsid[] = "@(#)lock.c 04/08/96     1.1\n";
26#endif
27
28/*
29 *  Shm_Initialize_lock
30 *
31 *  Initialize the lock for the specified locked queue.
32 */
33
34void Shm_Initialize_lock(
35  Shm_Locked_queue_Control *lq_cb
36)
37{
38  lq_cb->lock = LQ_UNLOCKED;
39}
40
41/*  void _Shm_Lock( &lq_cb )
42 *
43 *  This shared memory locked queue support routine locks the
44 *  specified locked queue.  It disables interrupts to prevent
45 *  a deadlock condition.
46 */
47
48void Shm_Lock(
49  Shm_Locked_queue_Control *lq_cb
50)
51{
52  rtems_unsigned32 isr_level;
53  rtems_unsigned32 *lockptr = &lq_cb->lock;
54  rtems_unsigned32 lock_value;
55
56  lock_value = 0x80000000;
57  rtems_interrupt_disable( isr_level );
58
59    Shm_isrstat = isr_level;
60    while ( lock_value ) {
61      asm volatile( ""
62                         : "=r" (lockptr), "=r" (lock_value)
63                         : "0" (lockptr),  "1" (lock_value)
64                  );
65      /*
66       *  If not available, then may want to delay to reduce load on lock.
67       */
68
69      if ( lock_value )
70        delay( 10 );   /* approximately 10 microseconds */
71   }
72}
73
74/*
75 *  Shm_Unlock
76 *
77 *  Unlock the lock for the specified locked queue.
78 */
79
80void Shm_Unlock(
81  Shm_Locked_queue_Control *lq_cb
82)
83{
84  rtems_unsigned32 isr_level;
85
86  lq_cb->lock = SHM_UNLOCK_VALUE;
87  isr_level = Shm_isrstat;
88  rtems_interrupt_enable( isr_level );
89}
90
Note: See TracBrowser for help on using the repository browser.