xref: /haiku/src/add-ons/kernel/bus_managers/scsi/scsi_lock.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*
2 ** Copyright 2002/03, Thomas Kurschel. All rights reserved.
3 ** Distributed under the terms of the OpenBeOS License.
4 */
5 
6 /*
7 	Part of Open SCSI bus manager
8 
9 	Special locks
10 
11 	The only one defined herein is a spinlock that automatically
12 	disabled IRQs on enter and restores them on leave. Probably,
13 	this should be made public as it's quite basic.
14 */
15 
16 #ifndef __SCSI_LOCK_H__
17 #define __SCSI_LOCK_H__
18 
19 #include <KernelExport.h>
20 
21 
22 // enhanced spinlock that automatically disables irqs when lock is hold
23 typedef struct spinlock_irq {
24 	spinlock	lock;				// normal spinlock
25 	cpu_status	prev_irq_state;		// irq state before spinlock was entered
26 } spinlock_irq;
27 
28 
29 static inline void
30 spinlock_irq_init(spinlock_irq *lock)
31 {
32 	B_INITIALIZE_SPINLOCK(&lock->lock);
33 }
34 
35 static inline void
36 acquire_spinlock_irq(spinlock_irq *lock)
37 {
38 	cpu_status prev_irq_state = disable_interrupts();
39 
40 	acquire_spinlock(&lock->lock);
41 	lock->prev_irq_state = prev_irq_state;
42 }
43 
44 static inline void
45 release_spinlock_irq(spinlock_irq *lock)
46 {
47 	cpu_status prev_irq_state = lock->prev_irq_state;
48 
49 	release_spinlock(&lock->lock);
50 	restore_interrupts(prev_irq_state);
51 }
52 
53 #endif
54