source: rtems/c/src/lib/libbsp/i386/force386/shmsupp/lock.c @ d637822

4.104.114.84.95
Last change on this file since d637822 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 1.9 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 be
14 *  found in 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/*
25 *  Shm_Initialize_lock
26 *
27 *  Initialize the lock for the specified locked queue.
28 */
29
30void Shm_Initialize_lock(
31  Shm_Locked_queue_Control *lq_cb
32)
33{
34  lq_cb->lock = LQ_UNLOCKED;
35}
36
37/*  void _Shm_Lock( &lq_cb )
38 *
39 *  This shared memory locked queue support routine locks the
40 *  specified locked queue.  It disables interrupts to prevent
41 *  a deadlock condition.
42 */
43
44void Shm_Lock(
45  Shm_Locked_queue_Control *lq_cb
46)
47{
48  rtems_unsigned32 isr_level;
49  volatile rtems_unsigned32 *lockptr = &lq_cb->lock;
50  rtems_unsigned32 lock_value;
51
52  lock_value = SHM_LOCK_VALUE;
53  rtems_interrupt_disable( isr_level );
54
55    Shm_isrstat = isr_level;
56    while ( 1 ) {
57      asm volatile( "lock ; xchg (%0),%1"
58                         : "=r" (lockptr), "=r" (lock_value)
59                         : "0" (lockptr),  "1" (lock_value)
60                  );
61      if ( lock_value == SHM_UNLOCK_VALUE )
62        break;
63      delay( 10 );   /* approximately 10 microseconds */
64   }
65}
66
67/*
68 *  Shm_Unlock
69 *
70 *  Unlock the lock for the specified locked queue.
71 */
72
73void Shm_Unlock(
74  Shm_Locked_queue_Control *lq_cb
75)
76{
77  rtems_unsigned32 isr_level;
78
79  lq_cb->lock = SHM_UNLOCK_VALUE;
80  isr_level = Shm_isrstat;
81  rtems_interrupt_enable( isr_level );
82}
83
Note: See TracBrowser for help on using the repository browser.