kernel: Forbid implicit casts between spinlock and int32

This commit is contained in:
Pawel Dziepak 2013-11-28 23:28:33 +01:00
parent 7b4befcd47
commit e736a456ba
11 changed files with 38 additions and 30 deletions

View File

@ -31,15 +31,19 @@ typedef ulong cpu_status;
(spinlock)->count_low = 0; \ (spinlock)->count_low = 0; \
(spinlock)->count_high = 0; \ (spinlock)->count_high = 0; \
} while (false) } while (false)
# define B_SPINLOCK_IS_LOCKED(spinlock) ((spinlock)->lock > 0)
#else #else
typedef int32 spinlock; typedef struct {
int32 lock;
} spinlock;
# define B_SPINLOCK_INITIALIZER 0 # define B_SPINLOCK_INITIALIZER { 0 }
# define B_INITIALIZE_SPINLOCK(lock) do { *(lock) = 0; } while (false) # define B_INITIALIZE_SPINLOCK(spinlock) do { \
# define B_SPINLOCK_IS_LOCKED(lock) (*(lock) > 0) (spinlock)->lock = 0; \
} while (false)
#endif #endif
#define B_SPINLOCK_IS_LOCKED(spinlock) (atomic_get(&(spinlock)->lock) > 0)
typedef struct { typedef struct {
int32 lock; int32 lock;
} rw_spinlock; } rw_spinlock;

View File

@ -188,7 +188,7 @@ initialize_timer(void)
{ {
sTimerCount = 0; sTimerCount = 0;
sTimerNextId = 1; sTimerNextId = 1;
sTimerSpinlock = 0; B_INITIALIZE_SPINLOCK(&sTimerSpinlock);
sTimerThread = spawn_kernel_thread(timer_thread, "firewire timer", 80, 0); sTimerThread = spawn_kernel_thread(timer_thread, "firewire timer", 80, 0);
sTimerSem = create_sem(0, "firewire timer"); sTimerSem = create_sem(0, "firewire timer");

View File

@ -22,13 +22,14 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
fPCIInfo(PCIInfo), fPCIInfo(PCIInfo),
fInfo(DeviceInfo), fInfo(DeviceInfo),
fIOBase(0), fIOBase(0),
fHWSpinlock(0),
fInterruptsNest(0), fInterruptsNest(0),
fBuffersReadySem(-1), fBuffersReadySem(-1),
fMixer(this), fMixer(this),
fPlaybackStream(this, false), fPlaybackStream(this, false),
fRecordStream(this, true) fRecordStream(this, true)
{ {
B_INITIALIZE_SPINLOCK(&fHWSpinlock);
fStatus = _ReserveDeviceOnBus(true); fStatus = _ReserveDeviceOnBus(true);
if (fStatus != B_OK) if (fStatus != B_OK)
return; // InitCheck will handle the rest return; // InitCheck will handle the rest

View File

@ -88,7 +88,7 @@ private:
pci_info fPCIInfo; pci_info fPCIInfo;
Info& fInfo; Info& fInfo;
int fIOBase; int fIOBase;
int32 fHWSpinlock; spinlock fHWSpinlock;
int32 fInterruptsNest; int32 fInterruptsNest;
sem_id fBuffersReadySem; sem_id fBuffersReadySem;

View File

@ -34,7 +34,7 @@
#include "debug.h" #include "debug.h"
#include "util.h" #include "util.h"
spinlock slock = 0; spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);

View File

@ -16,7 +16,7 @@
#include "debug.h" #include "debug.h"
#include "util.h" #include "util.h"
spinlock slock = 0; spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);

View File

@ -222,7 +222,7 @@ init_driver(void)
B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA); B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA);
if (master->buffer_area < B_OK) if (master->buffer_area < B_OK)
goto config_error2; goto config_error2;
master->slock = 0; B_INITIALIZE_SPINLOCK(&master->slock);
master->isa = isa; master->isa = isa;
if (install_io_interrupt_handler(master->irq, flo_intr, (void *)master, 0) < B_OK) if (install_io_interrupt_handler(master->irq, flo_intr, (void *)master, 0) < B_OK)
goto config_error2; goto config_error2;

View File

@ -43,7 +43,7 @@ private:
bool fIsTx; bool fIsTx;
status_t fStatus; status_t fStatus;
area_id fArea; area_id fArea;
int32 fSpinlock; spinlock fSpinlock;
sem_id fSemaphore; sem_id fSemaphore;
uint32 fHead; uint32 fHead;
uint32 fTail; uint32 fTail;
@ -61,12 +61,12 @@ DataRing<__type, __count>::DataRing(Device* device, bool isTx)
fIsTx(isTx), fIsTx(isTx),
fStatus(B_NO_INIT), fStatus(B_NO_INIT),
fArea(-1), fArea(-1),
fSpinlock(0),
fSemaphore(0), fSemaphore(0),
fHead(0), fHead(0),
fTail(0), fTail(0),
fDescriptors(NULL) fDescriptors(NULL)
{ {
B_INITIALIZE_SPINLOCK(&fSpinlock);
memset(fBuffers, 0, sizeof(fBuffers)); memset(fBuffers, 0, sizeof(fBuffers));
} }

View File

@ -23,7 +23,6 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
fPCIInfo(PCIInfo), fPCIInfo(PCIInfo),
fInfo(DeviceInfo), fInfo(DeviceInfo),
fIOBase(0), fIOBase(0),
fHWSpinlock(0),
fInterruptsNest(0), fInterruptsNest(0),
fFrameSize(MaxFrameSize), fFrameSize(MaxFrameSize),
fMII(this), fMII(this),
@ -36,6 +35,8 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
{ {
memset((struct timer*)this, 0, sizeof(struct timer)); memset((struct timer*)this, 0, sizeof(struct timer));
B_INITIALIZE_SPINLOCK(&fHWSpinlock);
uint32 cmdRegister = gPCIModule->read_pci_config(PCIInfo.bus, uint32 cmdRegister = gPCIModule->read_pci_config(PCIInfo.bus,
PCIInfo.device, PCIInfo.function, PCI_command, 2); PCIInfo.device, PCIInfo.function, PCI_command, 2);
TRACE_ALWAYS("cmdRegister:%#010x\n", cmdRegister); TRACE_ALWAYS("cmdRegister:%#010x\n", cmdRegister);

View File

@ -97,7 +97,7 @@ static int32 _TimerHandler(struct timer* timer);
pci_info fPCIInfo; pci_info fPCIInfo;
Info& fInfo; Info& fInfo;
int fIOBase; int fIOBase;
int32 fHWSpinlock; spinlock fHWSpinlock;
int32 fInterruptsNest; int32 fInterruptsNest;
// interface and device infos // interface and device infos

View File

@ -1,4 +1,5 @@
/* /*
* Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
* Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2002-2010, Axel Dörfler, axeld@pinc-software.de. * Copyright 2002-2010, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@ -26,6 +27,7 @@
#include <int.h> #include <int.h>
#include <spinlock_contention.h> #include <spinlock_contention.h>
#include <thread.h> #include <thread.h>
#include <util/atomic.h>
#if DEBUG_SPINLOCK_LATENCIES #if DEBUG_SPINLOCK_LATENCIES
# include <safemode.h> # include <safemode.h>
#endif #endif
@ -350,7 +352,7 @@ acquire_spinlock(spinlock* lock)
#else #else
while (1) { while (1) {
uint32 count = 0; uint32 count = 0;
while (atomic_get(lock) != 0) { while (atomic_get(&lock->lock) != 0) {
if (++count == SPINLOCK_DEADLOCK_COUNT) { if (++count == SPINLOCK_DEADLOCK_COUNT) {
panic("acquire_spinlock(): Failed to acquire spinlock %p " panic("acquire_spinlock(): Failed to acquire spinlock %p "
"for a long time!", lock); "for a long time!", lock);
@ -358,9 +360,9 @@ acquire_spinlock(spinlock* lock)
} }
process_all_pending_ici(currentCPU); process_all_pending_ici(currentCPU);
cpu_wait(lock, 0); cpu_wait(&lock->lock, 0);
} }
if (atomic_get_and_set((int32*)lock, 1) == 0) if (atomic_get_and_set(&lock->lock, 1) == 0)
break; break;
} }
@ -371,7 +373,7 @@ acquire_spinlock(spinlock* lock)
} else { } else {
#if DEBUG_SPINLOCKS #if DEBUG_SPINLOCKS
int32 oldValue; int32 oldValue;
oldValue = atomic_get_and_set((int32*)lock, 1); oldValue = atomic_get_and_set(&lock->lock, 1);
if (oldValue != 0) { if (oldValue != 0) {
panic("acquire_spinlock: attempt to acquire lock %p twice on " panic("acquire_spinlock: attempt to acquire lock %p twice on "
"non-SMP system (last caller: %p, value %" B_PRId32 ")", lock, "non-SMP system (last caller: %p, value %" B_PRId32 ")", lock,
@ -404,23 +406,23 @@ acquire_spinlock_nocheck(spinlock *lock)
#else #else
while (1) { while (1) {
uint32 count = 0; uint32 count = 0;
while (atomic_get(lock) != 0) { while (atomic_get(&lock->lock) != 0) {
if (++count == SPINLOCK_DEADLOCK_COUNT_NO_CHECK) { if (++count == SPINLOCK_DEADLOCK_COUNT_NO_CHECK) {
panic("acquire_spinlock(): Failed to acquire spinlock %p " panic("acquire_spinlock(): Failed to acquire spinlock %p "
"for a long time!", lock); "for a long time!", lock);
count = 0; count = 0;
} }
cpu_wait(lock, 0); cpu_wait(&lock->lock, 0);
} }
if (atomic_get_and_set((int32*)lock, 1) == 0) if (atomic_get_and_set(&lock->lock, 1) == 0)
break; break;
} }
#endif #endif
} else { } else {
#if DEBUG_SPINLOCKS #if DEBUG_SPINLOCKS
if (atomic_get_and_set((int32*)lock, 1) != 0) { if (atomic_get_and_set(&lock->lock, 1) != 0) {
panic("acquire_spinlock_nocheck: attempt to acquire lock %p twice " panic("acquire_spinlock_nocheck: attempt to acquire lock %p twice "
"on non-SMP system\n", lock); "on non-SMP system\n", lock);
} }
@ -447,7 +449,7 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
#else #else
while (1) { while (1) {
uint32 count = 0; uint32 count = 0;
while (atomic_get(lock) != 0) { while (atomic_get(&lock->lock) != 0) {
if (++count == SPINLOCK_DEADLOCK_COUNT) { if (++count == SPINLOCK_DEADLOCK_COUNT) {
panic("acquire_spinlock_cpu(): Failed to acquire spinlock " panic("acquire_spinlock_cpu(): Failed to acquire spinlock "
"%p for a long time!", lock); "%p for a long time!", lock);
@ -455,9 +457,9 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
} }
process_all_pending_ici(currentCPU); process_all_pending_ici(currentCPU);
cpu_wait(lock, 0); cpu_wait(&lock->lock, 0);
} }
if (atomic_get_and_set((int32*)lock, 1) == 0) if (atomic_get_and_set(&lock->lock, 1) == 0)
break; break;
} }
@ -468,7 +470,7 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
} else { } else {
#if DEBUG_SPINLOCKS #if DEBUG_SPINLOCKS
int32 oldValue; int32 oldValue;
oldValue = atomic_get_and_set((int32*)lock, 1); oldValue = atomic_get_and_set(&lock->lock, 1);
if (oldValue != 0) { if (oldValue != 0) {
panic("acquire_spinlock_cpu(): attempt to acquire lock %p twice on " panic("acquire_spinlock_cpu(): attempt to acquire lock %p twice on "
"non-SMP system (last caller: %p, value %" B_PRId32 ")", lock, "non-SMP system (last caller: %p, value %" B_PRId32 ")", lock,
@ -506,10 +508,10 @@ release_spinlock(spinlock *lock)
} }
} }
#elif DEBUG_SPINLOCKS #elif DEBUG_SPINLOCKS
if (atomic_get_and_set((int32*)lock, 0) != 1) if (atomic_get_and_set(&lock->lock, 0) != 1)
panic("release_spinlock: lock %p was already released\n", lock); panic("release_spinlock: lock %p was already released\n", lock);
#else #else
atomic_set((int32*)lock, 0); atomic_set(&lock->lock, 0);
#endif #endif
} else { } else {
#if DEBUG_SPINLOCKS #if DEBUG_SPINLOCKS
@ -517,7 +519,7 @@ release_spinlock(spinlock *lock)
panic("release_spinlock: attempt to release lock %p with " panic("release_spinlock: attempt to release lock %p with "
"interrupts enabled\n", lock); "interrupts enabled\n", lock);
} }
if (atomic_get_and_set((int32*)lock, 0) != 1) if (atomic_get_and_set(&lock->lock, 0) != 1)
panic("release_spinlock: lock %p was already released\n", lock); panic("release_spinlock: lock %p was already released\n", lock);
#endif #endif
#if DEBUG_SPINLOCK_LATENCIES #if DEBUG_SPINLOCK_LATENCIES