kernel: Forbid implicit casts between spinlock and int32
This commit is contained in:
parent
7b4befcd47
commit
e736a456ba
@ -31,15 +31,19 @@ typedef ulong cpu_status;
|
||||
(spinlock)->count_low = 0; \
|
||||
(spinlock)->count_high = 0; \
|
||||
} while (false)
|
||||
# define B_SPINLOCK_IS_LOCKED(spinlock) ((spinlock)->lock > 0)
|
||||
#else
|
||||
typedef int32 spinlock;
|
||||
typedef struct {
|
||||
int32 lock;
|
||||
} spinlock;
|
||||
|
||||
# define B_SPINLOCK_INITIALIZER 0
|
||||
# define B_INITIALIZE_SPINLOCK(lock) do { *(lock) = 0; } while (false)
|
||||
# define B_SPINLOCK_IS_LOCKED(lock) (*(lock) > 0)
|
||||
# define B_SPINLOCK_INITIALIZER { 0 }
|
||||
# define B_INITIALIZE_SPINLOCK(spinlock) do { \
|
||||
(spinlock)->lock = 0; \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
#define B_SPINLOCK_IS_LOCKED(spinlock) (atomic_get(&(spinlock)->lock) > 0)
|
||||
|
||||
typedef struct {
|
||||
int32 lock;
|
||||
} rw_spinlock;
|
||||
|
@ -188,7 +188,7 @@ initialize_timer(void)
|
||||
{
|
||||
sTimerCount = 0;
|
||||
sTimerNextId = 1;
|
||||
sTimerSpinlock = 0;
|
||||
B_INITIALIZE_SPINLOCK(&sTimerSpinlock);
|
||||
|
||||
sTimerThread = spawn_kernel_thread(timer_thread, "firewire timer", 80, 0);
|
||||
sTimerSem = create_sem(0, "firewire timer");
|
||||
|
@ -22,13 +22,14 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
|
||||
fPCIInfo(PCIInfo),
|
||||
fInfo(DeviceInfo),
|
||||
fIOBase(0),
|
||||
fHWSpinlock(0),
|
||||
fInterruptsNest(0),
|
||||
fBuffersReadySem(-1),
|
||||
fMixer(this),
|
||||
fPlaybackStream(this, false),
|
||||
fRecordStream(this, true)
|
||||
{
|
||||
B_INITIALIZE_SPINLOCK(&fHWSpinlock);
|
||||
|
||||
fStatus = _ReserveDeviceOnBus(true);
|
||||
if (fStatus != B_OK)
|
||||
return; // InitCheck will handle the rest
|
||||
|
@ -88,7 +88,7 @@ private:
|
||||
pci_info fPCIInfo;
|
||||
Info& fInfo;
|
||||
int fIOBase;
|
||||
int32 fHWSpinlock;
|
||||
spinlock fHWSpinlock;
|
||||
int32 fInterruptsNest;
|
||||
sem_id fBuffersReadySem;
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
|
||||
spinlock slock = 0;
|
||||
spinlock slock = B_SPINLOCK_INITIALIZER;
|
||||
|
||||
uint32 round_to_pagesize(uint32 size);
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
|
||||
spinlock slock = 0;
|
||||
spinlock slock = B_SPINLOCK_INITIALIZER;
|
||||
|
||||
uint32 round_to_pagesize(uint32 size);
|
||||
|
||||
|
@ -222,7 +222,7 @@ init_driver(void)
|
||||
B_FULL_LOCK, B_READ_AREA|B_WRITE_AREA);
|
||||
if (master->buffer_area < B_OK)
|
||||
goto config_error2;
|
||||
master->slock = 0;
|
||||
B_INITIALIZE_SPINLOCK(&master->slock);
|
||||
master->isa = isa;
|
||||
if (install_io_interrupt_handler(master->irq, flo_intr, (void *)master, 0) < B_OK)
|
||||
goto config_error2;
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
bool fIsTx;
|
||||
status_t fStatus;
|
||||
area_id fArea;
|
||||
int32 fSpinlock;
|
||||
spinlock fSpinlock;
|
||||
sem_id fSemaphore;
|
||||
uint32 fHead;
|
||||
uint32 fTail;
|
||||
@ -61,12 +61,12 @@ DataRing<__type, __count>::DataRing(Device* device, bool isTx)
|
||||
fIsTx(isTx),
|
||||
fStatus(B_NO_INIT),
|
||||
fArea(-1),
|
||||
fSpinlock(0),
|
||||
fSemaphore(0),
|
||||
fHead(0),
|
||||
fTail(0),
|
||||
fDescriptors(NULL)
|
||||
{
|
||||
B_INITIALIZE_SPINLOCK(&fSpinlock);
|
||||
memset(fBuffers, 0, sizeof(fBuffers));
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
|
||||
fPCIInfo(PCIInfo),
|
||||
fInfo(DeviceInfo),
|
||||
fIOBase(0),
|
||||
fHWSpinlock(0),
|
||||
fInterruptsNest(0),
|
||||
fFrameSize(MaxFrameSize),
|
||||
fMII(this),
|
||||
@ -36,6 +35,8 @@ Device::Device(Device::Info &DeviceInfo, pci_info &PCIInfo)
|
||||
{
|
||||
memset((struct timer*)this, 0, sizeof(struct timer));
|
||||
|
||||
B_INITIALIZE_SPINLOCK(&fHWSpinlock);
|
||||
|
||||
uint32 cmdRegister = gPCIModule->read_pci_config(PCIInfo.bus,
|
||||
PCIInfo.device, PCIInfo.function, PCI_command, 2);
|
||||
TRACE_ALWAYS("cmdRegister:%#010x\n", cmdRegister);
|
||||
|
@ -97,7 +97,7 @@ static int32 _TimerHandler(struct timer* timer);
|
||||
pci_info fPCIInfo;
|
||||
Info& fInfo;
|
||||
int fIOBase;
|
||||
int32 fHWSpinlock;
|
||||
spinlock fHWSpinlock;
|
||||
int32 fInterruptsNest;
|
||||
|
||||
// interface and device infos
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
|
||||
* Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2002-2010, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
@ -26,6 +27,7 @@
|
||||
#include <int.h>
|
||||
#include <spinlock_contention.h>
|
||||
#include <thread.h>
|
||||
#include <util/atomic.h>
|
||||
#if DEBUG_SPINLOCK_LATENCIES
|
||||
# include <safemode.h>
|
||||
#endif
|
||||
@ -350,7 +352,7 @@ acquire_spinlock(spinlock* lock)
|
||||
#else
|
||||
while (1) {
|
||||
uint32 count = 0;
|
||||
while (atomic_get(lock) != 0) {
|
||||
while (atomic_get(&lock->lock) != 0) {
|
||||
if (++count == SPINLOCK_DEADLOCK_COUNT) {
|
||||
panic("acquire_spinlock(): Failed to acquire spinlock %p "
|
||||
"for a long time!", lock);
|
||||
@ -358,9 +360,9 @@ acquire_spinlock(spinlock* lock)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -371,7 +373,7 @@ acquire_spinlock(spinlock* lock)
|
||||
} else {
|
||||
#if DEBUG_SPINLOCKS
|
||||
int32 oldValue;
|
||||
oldValue = atomic_get_and_set((int32*)lock, 1);
|
||||
oldValue = atomic_get_and_set(&lock->lock, 1);
|
||||
if (oldValue != 0) {
|
||||
panic("acquire_spinlock: attempt to acquire lock %p twice on "
|
||||
"non-SMP system (last caller: %p, value %" B_PRId32 ")", lock,
|
||||
@ -404,23 +406,23 @@ acquire_spinlock_nocheck(spinlock *lock)
|
||||
#else
|
||||
while (1) {
|
||||
uint32 count = 0;
|
||||
while (atomic_get(lock) != 0) {
|
||||
while (atomic_get(&lock->lock) != 0) {
|
||||
if (++count == SPINLOCK_DEADLOCK_COUNT_NO_CHECK) {
|
||||
panic("acquire_spinlock(): Failed to acquire spinlock %p "
|
||||
"for a long time!", lock);
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
#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 "
|
||||
"on non-SMP system\n", lock);
|
||||
}
|
||||
@ -447,7 +449,7 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
|
||||
#else
|
||||
while (1) {
|
||||
uint32 count = 0;
|
||||
while (atomic_get(lock) != 0) {
|
||||
while (atomic_get(&lock->lock) != 0) {
|
||||
if (++count == SPINLOCK_DEADLOCK_COUNT) {
|
||||
panic("acquire_spinlock_cpu(): Failed to acquire spinlock "
|
||||
"%p for a long time!", lock);
|
||||
@ -455,9 +457,9 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -468,7 +470,7 @@ acquire_spinlock_cpu(int32 currentCPU, spinlock *lock)
|
||||
} else {
|
||||
#if DEBUG_SPINLOCKS
|
||||
int32 oldValue;
|
||||
oldValue = atomic_get_and_set((int32*)lock, 1);
|
||||
oldValue = atomic_get_and_set(&lock->lock, 1);
|
||||
if (oldValue != 0) {
|
||||
panic("acquire_spinlock_cpu(): attempt to acquire lock %p twice on "
|
||||
"non-SMP system (last caller: %p, value %" B_PRId32 ")", lock,
|
||||
@ -506,10 +508,10 @@ release_spinlock(spinlock *lock)
|
||||
}
|
||||
}
|
||||
#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);
|
||||
#else
|
||||
atomic_set((int32*)lock, 0);
|
||||
atomic_set(&lock->lock, 0);
|
||||
#endif
|
||||
} else {
|
||||
#if DEBUG_SPINLOCKS
|
||||
@ -517,7 +519,7 @@ release_spinlock(spinlock *lock)
|
||||
panic("release_spinlock: attempt to release lock %p with "
|
||||
"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);
|
||||
#endif
|
||||
#if DEBUG_SPINLOCK_LATENCIES
|
||||
|
Loading…
Reference in New Issue
Block a user