[ac7d5ef0] | 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 | * |
---|
[03f2154e] | 9 | * COPYRIGHT (c) 1989-1997. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 11 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 12 | * |
---|
[03f2154e] | 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. |
---|
[ac7d5ef0] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <rtems.h> |
---|
[88d594a] | 21 | #include <bsp.h> |
---|
| 22 | #include <shm.h> |
---|
[ac7d5ef0] | 23 | |
---|
| 24 | /* |
---|
| 25 | * Shm_Initialize_lock |
---|
| 26 | * |
---|
| 27 | * Initialize the lock for the specified locked queue. |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | void 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 | |
---|
| 44 | void Shm_Lock( |
---|
| 45 | Shm_Locked_queue_Control *lq_cb |
---|
| 46 | ) |
---|
| 47 | { |
---|
| 48 | rtems_unsigned32 isr_level, oldlock; |
---|
| 49 | |
---|
| 50 | rtems_interrupt_disable( isr_level ); |
---|
| 51 | Shm_isrstat = isr_level; |
---|
| 52 | while ( 1 ) { |
---|
| 53 | atomic_modify( SHM_LOCK_VALUE, &lq_cb->lock, oldlock ); |
---|
| 54 | if ( !(oldlock & SHM_LOCK_VALUE) ) |
---|
| 55 | return; |
---|
| 56 | delay( 28 ); /* delay 28 microseconds */ |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /* |
---|
| 61 | * Shm_Unlock |
---|
| 62 | * |
---|
| 63 | * Unlock the lock for the specified locked queue. |
---|
| 64 | */ |
---|
| 65 | |
---|
| 66 | void Shm_Unlock( |
---|
| 67 | Shm_Locked_queue_Control *lq_cb |
---|
| 68 | ) |
---|
| 69 | { |
---|
| 70 | rtems_unsigned32 isr_level; |
---|
| 71 | |
---|
| 72 | lq_cb->lock = SHM_UNLOCK_VALUE; |
---|
| 73 | isr_level = Shm_isrstat; |
---|
| 74 | rtems_interrupt_enable( isr_level ); |
---|
| 75 | } |
---|
| 76 | |
---|