[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 | * |
---|
[08311cc3] | 9 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[5626be2] | 14 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 15 | * |
---|
| 16 | * $Id$ |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <bsp.h> |
---|
[48bfd992] | 20 | #include <shm_driver.h> |
---|
[ac7d5ef0] | 21 | |
---|
| 22 | /* |
---|
| 23 | * Shm_Initialize_lock |
---|
| 24 | * |
---|
| 25 | * Initialize the lock for the specified locked queue. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | void Shm_Initialize_lock( |
---|
| 29 | Shm_Locked_queue_Control *lq_cb |
---|
| 30 | ) |
---|
| 31 | { |
---|
| 32 | lq_cb->lock = LQ_UNLOCKED; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | /* Shm_Lock( &lq_cb ) |
---|
| 36 | * |
---|
| 37 | * This shared memory locked queue support routine locks the |
---|
| 38 | * specified locked queue. It disables interrupts to prevent |
---|
| 39 | * a deadlock condition. |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | void Shm_Lock( |
---|
| 43 | Shm_Locked_queue_Control *lq_cb |
---|
| 44 | ) |
---|
| 45 | { |
---|
| 46 | rtems_unsigned32 isr_level; |
---|
| 47 | vol_u32 *lockptr = &lq_cb->lock; |
---|
| 48 | rtems_unsigned32 lock_value; |
---|
| 49 | |
---|
| 50 | rtems_interrupt_disable( isr_level ); |
---|
| 51 | |
---|
| 52 | Shm_isrstat = isr_level; |
---|
| 53 | |
---|
| 54 | do { |
---|
| 55 | HPPA_ASM_LDCWS( 0, 0, lockptr, lock_value ); |
---|
| 56 | } while (lock_value == SHM_LOCK_VALUE); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * Shm_Unlock |
---|
| 61 | * |
---|
| 62 | * Unlock the lock for the specified locked queue. |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | void Shm_Unlock( |
---|
| 66 | Shm_Locked_queue_Control *lq_cb |
---|
| 67 | ) |
---|
| 68 | { |
---|
| 69 | rtems_unsigned32 isr_level; |
---|
| 70 | |
---|
| 71 | lq_cb->lock = SHM_UNLOCK_VALUE; |
---|
| 72 | isr_level = Shm_isrstat; |
---|
| 73 | rtems_interrupt_enable( isr_level ); |
---|
| 74 | } |
---|