* Replaced all instances of benaphores in the kernel code by mutexes.
* Removed kernel benaphores. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25690 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -38,12 +38,6 @@ typedef struct recursive_lock {
|
||||
} recursive_lock;
|
||||
|
||||
|
||||
typedef struct benaphore {
|
||||
sem_id sem;
|
||||
int32 count;
|
||||
} benaphore;
|
||||
|
||||
|
||||
struct rw_lock_waiter;
|
||||
|
||||
typedef struct rw_lock {
|
||||
@@ -81,37 +75,6 @@ extern status_t recursive_lock_lock(recursive_lock *lock);
|
||||
extern void recursive_lock_unlock(recursive_lock *lock);
|
||||
extern int32 recursive_lock_get_recursion(recursive_lock *lock);
|
||||
|
||||
extern status_t benaphore_init(benaphore *ben, const char *name);
|
||||
extern void benaphore_destroy(benaphore *ben);
|
||||
|
||||
|
||||
static inline status_t
|
||||
benaphore_lock(benaphore *ben)
|
||||
{
|
||||
#ifdef KDEBUG
|
||||
return acquire_sem(ben->sem);
|
||||
#else
|
||||
if (atomic_add(&ben->count, -1) <= 0)
|
||||
return acquire_sem(ben->sem);
|
||||
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline status_t
|
||||
benaphore_unlock(benaphore *ben)
|
||||
{
|
||||
#ifdef KDEBUG
|
||||
return release_sem(ben->sem);
|
||||
#else
|
||||
if (atomic_add(&ben->count, 1) < 0)
|
||||
return release_sem(ben->sem);
|
||||
|
||||
return B_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void rw_lock_init(rw_lock* lock, const char* name);
|
||||
// name is *not* cloned nor freed in rw_lock_destroy()
|
||||
extern void rw_lock_init_etc(rw_lock* lock, const char* name, uint32 flags);
|
||||
|
||||
@@ -50,23 +50,6 @@ public:
|
||||
// RecursiveLocker
|
||||
typedef AutoLocker<recursive_lock, RecursiveLockLocking> RecursiveLocker;
|
||||
|
||||
// BenaphoreLocking
|
||||
class BenaphoreLocking {
|
||||
public:
|
||||
inline bool Lock(benaphore *lockable)
|
||||
{
|
||||
return benaphore_lock(lockable) == B_OK;
|
||||
}
|
||||
|
||||
inline void Unlock(benaphore *lockable)
|
||||
{
|
||||
benaphore_unlock(lockable);
|
||||
}
|
||||
};
|
||||
|
||||
// BenaphoreLocker
|
||||
typedef AutoLocker<benaphore, BenaphoreLocking> BenaphoreLocker;
|
||||
|
||||
// InterruptsLocking
|
||||
class InterruptsLocking {
|
||||
public:
|
||||
@@ -152,7 +135,6 @@ typedef AutoLocker<spinlock, InterruptsSpinLocking> InterruptsSpinLocker;
|
||||
using BPrivate::AutoLocker;
|
||||
using BPrivate::MutexLocker;
|
||||
using BPrivate::RecursiveLocker;
|
||||
using BPrivate::BenaphoreLocker;
|
||||
using BPrivate::InterruptsLocker;
|
||||
using BPrivate::SpinLocker;
|
||||
using BPrivate::InterruptsSpinLocker;
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
#include <net_stack.h>
|
||||
|
||||
|
||||
class BenaphoreLocking {
|
||||
class MutexLocking {
|
||||
public:
|
||||
typedef benaphore Type;
|
||||
typedef BenaphoreLocker AutoLocker;
|
||||
typedef mutex Type;
|
||||
typedef MutexLocker AutoLocker;
|
||||
|
||||
static status_t Init(benaphore *lock, const char *name)
|
||||
{ return benaphore_init(lock, name); }
|
||||
static void Destroy(benaphore *lock) { benaphore_destroy(lock); }
|
||||
static status_t Lock(benaphore *lock) { return benaphore_lock(lock); }
|
||||
static status_t Unlock(benaphore *lock) { return benaphore_unlock(lock); }
|
||||
static status_t Init(mutex *lock, const char *name)
|
||||
{ mutex_init_etc(lock, name, MUTEX_FLAG_CLONE_NAME); return B_OK; }
|
||||
static void Destroy(mutex *lock) { mutex_destroy(lock); }
|
||||
static status_t Lock(mutex *lock) { return mutex_lock(lock); }
|
||||
static status_t Unlock(mutex *lock) { mutex_unlock(lock); return B_OK; }
|
||||
};
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ ProtocolSocket::Open()
|
||||
}
|
||||
|
||||
|
||||
template<typename LockingBase = BenaphoreLocking,
|
||||
template<typename LockingBase = MutexLocking,
|
||||
typename ModuleBundle = NetModuleBundleGetter>
|
||||
class DatagramSocket : public ProtocolSocket {
|
||||
public:
|
||||
|
||||
@@ -27,7 +27,7 @@ struct net_timer;
|
||||
typedef struct ancillary_data_container ancillary_data_container;
|
||||
|
||||
struct net_fifo {
|
||||
benaphore lock;
|
||||
mutex lock;
|
||||
sem_id notify;
|
||||
int32 waiting;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ struct ide_bus_info {
|
||||
|
||||
ata_bus_state state; // current state of bus
|
||||
|
||||
benaphore status_report_ben; // to lock when you report XPT about bus state
|
||||
mutex status_report_ben; // to lock when you report XPT about bus state
|
||||
// i.e. during requeue, resubmit or finished
|
||||
|
||||
bool disconnected; // true, if controller is lost
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ void
|
||||
fw_xferwake(struct fw_xfer *xfer)
|
||||
{
|
||||
// struct mtx *lock = &xfer->fc->wait_lock;
|
||||
benaphore *lock = &xfer->fc->wait_lock;
|
||||
mutex *lock = &xfer->fc->wait_lock;
|
||||
|
||||
mtx_lock(lock);
|
||||
xfer->flag |= FWXF_WAKE;
|
||||
@@ -240,7 +240,7 @@ int
|
||||
fw_xferwait(struct fw_xfer *xfer)
|
||||
{
|
||||
// struct mtx *lock = &xfer->fc->wait_lock;
|
||||
benaphore *lock = &xfer->fc->wait_lock;
|
||||
mutex *lock = &xfer->fc->wait_lock;
|
||||
int err = 0;
|
||||
|
||||
mtx_lock(lock);
|
||||
|
||||
@@ -176,7 +176,7 @@ struct ide_bus_info {
|
||||
|
||||
ide_bus_state state; // current state of bus
|
||||
|
||||
benaphore status_report_ben; // to lock when you report XPT about bus state
|
||||
mutex status_report_ben; // to lock when you report XPT about bus state
|
||||
// i.e. during requeue, resubmit or finished
|
||||
|
||||
bool disconnected; // true, if controller is lost
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ typedef struct scsi_bus_info {
|
||||
sem_id start_service; // released whenever service thread has work to do
|
||||
bool shutting_down; // set to true to tell service thread to shut down
|
||||
|
||||
benaphore mutex; // used to synchronize changes in queueing and blocking
|
||||
struct mutex mutex; // used to synchronize changes in queueing and blocking
|
||||
|
||||
sem_id scan_lun_lock; // allocated whenever a lun is scanned
|
||||
|
||||
@@ -174,7 +174,7 @@ typedef struct scsi_device_info {
|
||||
scsi_res_inquiry inquiry_data;
|
||||
device_node *node; // device node
|
||||
|
||||
benaphore dma_buffer_lock; // lock between DMA buffer user and clean-up daemon
|
||||
struct mutex dma_buffer_lock; // lock between DMA buffer user and clean-up daemon
|
||||
sem_id dma_buffer_owner; // to be acquired before using DMA buffer
|
||||
dma_buffer dma_buffer; // DMA buffer
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ enum {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct benaphore {
|
||||
typedef struct mutex {
|
||||
sem_id sem;
|
||||
int32 count;
|
||||
} benaphore;
|
||||
} mutex;
|
||||
|
||||
|
||||
inline status_t
|
||||
benaphore_init(benaphore *ben, const char *name)
|
||||
mutex_init(mutex *ben, const char *name)
|
||||
{
|
||||
if (ben == NULL || name == NULL)
|
||||
return B_BAD_VALUE;
|
||||
@@ -52,7 +52,7 @@ benaphore_init(benaphore *ben, const char *name)
|
||||
|
||||
|
||||
inline void
|
||||
benaphore_destroy(benaphore *ben)
|
||||
mutex_destroy(mutex *ben)
|
||||
{
|
||||
delete_sem(ben->sem);
|
||||
ben->sem = -1;
|
||||
@@ -60,7 +60,7 @@ benaphore_destroy(benaphore *ben)
|
||||
|
||||
|
||||
inline status_t
|
||||
benaphore_lock(benaphore *ben)
|
||||
mutex_lock(mutex *ben)
|
||||
{
|
||||
if (atomic_add(&ben->count, -1) <= 0)
|
||||
return acquire_sem(ben->sem);
|
||||
@@ -69,7 +69,7 @@ benaphore_lock(benaphore *ben)
|
||||
|
||||
|
||||
inline status_t
|
||||
benaphore_unlock(benaphore *ben)
|
||||
mutex_unlock(mutex *ben)
|
||||
{
|
||||
if (atomic_add(&ben->count, 1) < 0)
|
||||
return release_sem(ben->sem);
|
||||
|
||||
@@ -14,10 +14,7 @@ BusManager::BusManager(Stack *stack)
|
||||
: fInitOK(false),
|
||||
fRootHub(NULL)
|
||||
{
|
||||
if (benaphore_init(&fLock, "usb busmanager lock") < B_OK) {
|
||||
TRACE_ERROR(("USB BusManager: failed to create busmanager lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init(&fLock, "usb busmanager lock");
|
||||
|
||||
fRootObject = new(std::nothrow) Object(stack, this);
|
||||
if (!fRootObject)
|
||||
@@ -39,7 +36,7 @@ BusManager::BusManager(Stack *stack)
|
||||
BusManager::~BusManager()
|
||||
{
|
||||
Lock();
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
for (int32 i = 0; i <= USB_SPEED_MAX; i++)
|
||||
delete fDefaultPipes[i];
|
||||
delete fRootObject;
|
||||
@@ -59,14 +56,14 @@ BusManager::InitCheck()
|
||||
bool
|
||||
BusManager::Lock()
|
||||
{
|
||||
return (benaphore_lock(&fLock) == B_OK);
|
||||
return (mutex_lock(&fLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BusManager::Unlock()
|
||||
{
|
||||
benaphore_unlock(&fLock);
|
||||
mutex_unlock(&fLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ PhysicalMemoryAllocator::PhysicalMemoryAllocator(const char *name,
|
||||
fStatus(B_NO_INIT)
|
||||
{
|
||||
fName = strdup(name);
|
||||
if (benaphore_init(&fLock, fName) < B_OK) {
|
||||
TRACE_ERROR(("PMA: failed to create benaphore lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init_etc(&fLock, fName, MUTEX_FLAG_CLONE_NAME);
|
||||
|
||||
fArrayCount = 1;
|
||||
size_t biggestSize = minSize;
|
||||
@@ -103,21 +100,21 @@ PhysicalMemoryAllocator::~PhysicalMemoryAllocator()
|
||||
free(fName);
|
||||
|
||||
delete_area(fArea);
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PhysicalMemoryAllocator::_Lock()
|
||||
{
|
||||
return (benaphore_lock(&fLock) == B_OK);
|
||||
return (mutex_lock(&fLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PhysicalMemoryAllocator::_Unlock()
|
||||
{
|
||||
benaphore_unlock(&fLock);
|
||||
mutex_unlock(&fLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
size_t fManagedMemory;
|
||||
status_t fStatus;
|
||||
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
area_id fArea;
|
||||
void *fLogicalBase;
|
||||
void *fPhysicalBase;
|
||||
|
||||
@@ -28,15 +28,8 @@ Stack::Stack()
|
||||
{
|
||||
TRACE(("USB Stack: stack init\n"));
|
||||
|
||||
if (benaphore_init(&fStackLock, "usb stack lock") < B_OK) {
|
||||
TRACE_ERROR(("USB Stack: failed to create stack lock\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (benaphore_init(&fExploreLock, "usb explore lock") < B_OK) {
|
||||
TRACE_ERROR(("USB Stack: failed to create explore lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init(&fStackLock, "usb stack lock");
|
||||
mutex_init(&fExploreLock, "usb explore lock");
|
||||
|
||||
size_t objectArraySize = fObjectMaxCount * sizeof(Object *);
|
||||
fObjectArray = (Object **)malloc(objectArraySize);
|
||||
@@ -106,10 +99,10 @@ Stack::~Stack()
|
||||
fStopThreads = true;
|
||||
wait_for_thread(fExploreThread, &result);
|
||||
|
||||
benaphore_lock(&fStackLock);
|
||||
benaphore_destroy(&fStackLock);
|
||||
benaphore_lock(&fExploreLock);
|
||||
benaphore_destroy(&fExploreLock);
|
||||
mutex_lock(&fStackLock);
|
||||
mutex_destroy(&fStackLock);
|
||||
mutex_lock(&fExploreLock);
|
||||
mutex_destroy(&fExploreLock);
|
||||
|
||||
//Release the bus modules
|
||||
for (Vector<BusManager *>::Iterator i = fBusManagers.Begin();
|
||||
@@ -133,14 +126,14 @@ Stack::InitCheck()
|
||||
bool
|
||||
Stack::Lock()
|
||||
{
|
||||
return (benaphore_lock(&fStackLock) == B_OK);
|
||||
return (mutex_lock(&fStackLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Stack::Unlock()
|
||||
{
|
||||
benaphore_unlock(&fStackLock);
|
||||
mutex_unlock(&fStackLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +204,7 @@ Stack::ExploreThread(void *data)
|
||||
Stack *stack = (Stack *)data;
|
||||
|
||||
while (!stack->fStopThreads) {
|
||||
if (benaphore_lock(&stack->fExploreLock) != B_OK)
|
||||
if (mutex_lock(&stack->fExploreLock) != B_OK)
|
||||
break;
|
||||
|
||||
rescan_item *rescanList = NULL;
|
||||
@@ -236,7 +229,7 @@ Stack::ExploreThread(void *data)
|
||||
}
|
||||
|
||||
stack->fFirstExploreDone = true;
|
||||
benaphore_unlock(&stack->fExploreLock);
|
||||
mutex_unlock(&stack->fExploreLock);
|
||||
stack->RescanDrivers(rescanList);
|
||||
snooze(USB_DELAY_HUB_EXPLORE);
|
||||
}
|
||||
@@ -461,7 +454,7 @@ Stack::InstallNotify(const char *driverName, const usb_notify_hooks *hooks)
|
||||
usb_driver_info *element = fDriverList;
|
||||
while (element) {
|
||||
if (strcmp(element->driver_name, driverName) == 0) {
|
||||
if (benaphore_lock(&fExploreLock) != B_OK)
|
||||
if (mutex_lock(&fExploreLock) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
// inform driver about any already present devices
|
||||
@@ -477,7 +470,7 @@ Stack::InstallNotify(const char *driverName, const usb_notify_hooks *hooks)
|
||||
|
||||
element->notify_hooks.device_added = hooks->device_added;
|
||||
element->notify_hooks.device_removed = hooks->device_removed;
|
||||
benaphore_unlock(&fExploreLock);
|
||||
mutex_unlock(&fExploreLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -496,7 +489,7 @@ Stack::UninstallNotify(const char *driverName)
|
||||
usb_driver_info *element = fDriverList;
|
||||
while (element) {
|
||||
if (strcmp(element->driver_name, driverName) == 0) {
|
||||
if (benaphore_lock(&fExploreLock) != B_OK)
|
||||
if (mutex_lock(&fExploreLock) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
// trigger the device removed hook
|
||||
@@ -510,7 +503,7 @@ Stack::UninstallNotify(const char *driverName)
|
||||
|
||||
element->notify_hooks.device_added = NULL;
|
||||
element->notify_hooks.device_removed = NULL;
|
||||
benaphore_unlock(&fExploreLock);
|
||||
mutex_unlock(&fExploreLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,8 +149,8 @@ static int32 ExploreThread(void *data);
|
||||
bool fFirstExploreDone;
|
||||
bool fStopThreads;
|
||||
|
||||
benaphore fStackLock;
|
||||
benaphore fExploreLock;
|
||||
mutex fStackLock;
|
||||
mutex fExploreLock;
|
||||
PhysicalMemoryAllocator *fAllocator;
|
||||
|
||||
uint32 fObjectIndex;
|
||||
@@ -204,7 +204,7 @@ protected:
|
||||
private:
|
||||
ControlPipe *_GetDefaultPipe(usb_speed);
|
||||
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
|
||||
bool fDeviceMap[128];
|
||||
int8 fDeviceIndex;
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -80,10 +80,7 @@ OHCI::OHCI(pci_info *info, Stack *stack)
|
||||
TRACE(("usb_ohci: constructing new OHCI Host Controller Driver\n"));
|
||||
fInitOK = false;
|
||||
|
||||
if (benaphore_init(&fEndpointLock, "ohci endpoint lock") < B_OK) {
|
||||
TRACE_ERROR(("usb_ohci: failed to create endpoint lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init(&fEndpointLock, "ohci endpoint lock");
|
||||
|
||||
// enable busmaster and memory mapped access
|
||||
uint16 command = sPCIModule->read_pci_config(fPCIInfo->bus,
|
||||
@@ -335,7 +332,7 @@ OHCI::~OHCI()
|
||||
wait_for_thread(fFinishThread, &result);
|
||||
|
||||
_LockEndpoints();
|
||||
benaphore_destroy(&fEndpointLock);
|
||||
mutex_destroy(&fEndpointLock);
|
||||
|
||||
if (fHccaArea >= B_OK)
|
||||
delete_area(fHccaArea);
|
||||
@@ -1718,14 +1715,14 @@ OHCI::_FreeIsochronousDescriptor(ohci_isochronous_td *descriptor)
|
||||
bool
|
||||
OHCI::_LockEndpoints()
|
||||
{
|
||||
return (benaphore_lock(&fEndpointLock) == B_OK);
|
||||
return (mutex_lock(&fEndpointLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OHCI::_UnlockEndpoints()
|
||||
{
|
||||
benaphore_unlock(&fEndpointLock);
|
||||
mutex_unlock(&fEndpointLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ static pci_module_info *sPCIModule;
|
||||
ohci_endpoint_descriptor **fInterruptEndpoints;
|
||||
|
||||
// Endpoint management
|
||||
benaphore fEndpointLock;
|
||||
mutex fEndpointLock;
|
||||
ohci_endpoint_descriptor *fDummyControl;
|
||||
ohci_endpoint_descriptor *fDummyBulk;
|
||||
ohci_endpoint_descriptor *fDummyIsochronous;
|
||||
|
||||
@@ -90,10 +90,7 @@ Queue::Queue(Stack *stack)
|
||||
{
|
||||
fStack = stack;
|
||||
|
||||
if (benaphore_init(&fLock, "uhci queue lock") < B_OK) {
|
||||
TRACE_ERROR(("usb_uhci: failed to create queue lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init(&fLock, "uhci queue lock");
|
||||
|
||||
void *physicalAddress;
|
||||
fStatus = fStack->AllocateChunk((void **)&fQueueHead, &physicalAddress,
|
||||
@@ -112,7 +109,7 @@ Queue::Queue(Stack *stack)
|
||||
Queue::~Queue()
|
||||
{
|
||||
Lock();
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
|
||||
fStack->FreeChunk(fQueueHead, (void *)fQueueHead->this_phy, sizeof(uhci_qh));
|
||||
|
||||
@@ -132,14 +129,14 @@ Queue::InitCheck()
|
||||
bool
|
||||
Queue::Lock()
|
||||
{
|
||||
return (benaphore_lock(&fLock) == B_OK);
|
||||
return (mutex_lock(&fLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Queue::Unlock()
|
||||
{
|
||||
benaphore_unlock(&fLock);
|
||||
mutex_unlock(&fLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -434,10 +431,7 @@ UHCI::UHCI(pci_info *info, Stack *stack)
|
||||
resume_thread(fFinishThread);
|
||||
|
||||
// Create a lock for the isochronous transfer list
|
||||
if (benaphore_init(&fIsochronousLock, "UHCI isochronous lock") < B_OK) {
|
||||
TRACE_ERROR(("usb_uhci: failed to create isochronous lock\n"));
|
||||
return;
|
||||
}
|
||||
mutex_init(&fIsochronousLock, "UHCI isochronous lock");
|
||||
|
||||
// Create semaphore the isochronous finisher thread will wait for
|
||||
fFinishIsochronousTransfersSem = create_sem(0,
|
||||
@@ -484,7 +478,7 @@ UHCI::~UHCI()
|
||||
delete isoTransfer;
|
||||
isoTransfer = next;
|
||||
}
|
||||
benaphore_destroy(&fIsochronousLock);
|
||||
mutex_destroy(&fIsochronousLock);
|
||||
|
||||
Lock();
|
||||
transfer_data *transfer = fFirstTransfer;
|
||||
@@ -2070,14 +2064,14 @@ UHCI::ReadIsochronousDescriptorChain(isochronous_transfer_data *transfer,
|
||||
bool
|
||||
UHCI::LockIsochronous()
|
||||
{
|
||||
return (benaphore_lock(&fIsochronousLock) == B_OK);
|
||||
return (mutex_lock(&fIsochronousLock) == B_OK);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
UHCI::UnlockIsochronous()
|
||||
{
|
||||
benaphore_unlock(&fIsochronousLock);
|
||||
mutex_unlock(&fIsochronousLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ private:
|
||||
uhci_qh *fQueueHead;
|
||||
uhci_td *fStrayDescriptor;
|
||||
uhci_qh *fQueueTop;
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
};
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ static pci_module_info *sPCIModule;
|
||||
isochronous_transfer_data *fLastIsochronousTransfer;
|
||||
sem_id fFinishIsochronousTransfersSem;
|
||||
thread_id fFinishIsochronousThread;
|
||||
benaphore fIsochronousLock;
|
||||
mutex fIsochronousLock;
|
||||
bool fStopFinishIsochronousThread;
|
||||
|
||||
// Root hub
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
typedef struct {
|
||||
usb_device device;
|
||||
benaphore lock;
|
||||
mutex lock;
|
||||
uint32 reference_count;
|
||||
|
||||
char name[32];
|
||||
@@ -43,7 +43,7 @@ int32 api_version = B_CUR_DRIVER_API_VERSION;
|
||||
static usb_module_info *gUSBModule = NULL;
|
||||
static raw_device *gDeviceList = NULL;
|
||||
static uint32 gDeviceCount = 0;
|
||||
static benaphore gDeviceListLock;
|
||||
static mutex gDeviceListLock;
|
||||
static char **gDeviceNames = NULL;
|
||||
|
||||
static status_t
|
||||
@@ -52,15 +52,11 @@ usb_raw_device_added(usb_device newDevice, void **cookie)
|
||||
TRACE((DRIVER_NAME": device_added(0x%08lx)\n", newDevice));
|
||||
raw_device *device = (raw_device *)malloc(sizeof(raw_device));
|
||||
|
||||
status_t result = benaphore_init(&device->lock, "usb_raw device lock");
|
||||
if (result < B_OK) {
|
||||
free(device);
|
||||
return result;
|
||||
}
|
||||
mutex_init(&device->lock, "usb_raw device lock");
|
||||
|
||||
device->notify = create_sem(0, "usb_raw callback notify");
|
||||
if (device->notify < B_OK) {
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
free(device);
|
||||
return B_NO_MORE_SEMS;
|
||||
}
|
||||
@@ -76,11 +72,11 @@ usb_raw_device_added(usb_device newDevice, void **cookie)
|
||||
device->device = newDevice;
|
||||
device->reference_count = 0;
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
device->link = (void *)gDeviceList;
|
||||
gDeviceList = device;
|
||||
gDeviceCount++;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
|
||||
TRACE((DRIVER_NAME": new device: 0x%08lx\n", (uint32)device));
|
||||
*cookie = (void *)device;
|
||||
@@ -94,7 +90,7 @@ usb_raw_device_removed(void *cookie)
|
||||
TRACE((DRIVER_NAME": device_removed(0x%08lx)\n", (uint32)cookie));
|
||||
raw_device *device = (raw_device *)cookie;
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
if (gDeviceList == device) {
|
||||
gDeviceList = (raw_device *)device->link;
|
||||
} else {
|
||||
@@ -109,12 +105,12 @@ usb_raw_device_removed(void *cookie)
|
||||
}
|
||||
}
|
||||
gDeviceCount--;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
|
||||
device->device = 0;
|
||||
if (device->reference_count == 0) {
|
||||
benaphore_lock(&device->lock);
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
delete_sem(device->notify);
|
||||
free(device);
|
||||
}
|
||||
@@ -132,20 +128,20 @@ static status_t
|
||||
usb_raw_open(const char *name, uint32 flags, void **cookie)
|
||||
{
|
||||
TRACE((DRIVER_NAME": open()\n"));
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
raw_device *element = gDeviceList;
|
||||
while (element) {
|
||||
if (strcmp(name, element->name) == 0) {
|
||||
element->reference_count++;
|
||||
*cookie = element;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
element = (raw_device *)element->link;
|
||||
}
|
||||
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -162,18 +158,18 @@ static status_t
|
||||
usb_raw_free(void *cookie)
|
||||
{
|
||||
TRACE((DRIVER_NAME": free()\n"));
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
|
||||
raw_device *device = (raw_device *)cookie;
|
||||
device->reference_count--;
|
||||
if (device->device == 0) {
|
||||
benaphore_lock(&device->lock);
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
delete_sem(device->notify);
|
||||
free(device);
|
||||
}
|
||||
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -538,7 +534,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
}
|
||||
|
||||
case B_USB_RAW_COMMAND_CONTROL_TRANSFER: {
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
if (gUSBModule->queue_request(device->device,
|
||||
command->control.request_type, command->control.request,
|
||||
command->control.value, command->control.index,
|
||||
@@ -546,14 +542,14 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
usb_raw_callback, device) < B_OK) {
|
||||
command->control.status = B_USB_RAW_STATUS_FAILED;
|
||||
command->control.length = 0;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
acquire_sem(device->notify);
|
||||
command->control.status = device->status;
|
||||
command->control.length = device->actual_length;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -609,7 +605,7 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
}
|
||||
|
||||
status_t status;
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
if (op == B_USB_RAW_COMMAND_INTERRUPT_TRANSFER) {
|
||||
status = gUSBModule->queue_interrupt(endpointInfo->handle,
|
||||
command->transfer.data, command->transfer.length,
|
||||
@@ -629,14 +625,14 @@ usb_raw_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
command->transfer.status = B_USB_RAW_STATUS_FAILED;
|
||||
command->transfer.length = 0;
|
||||
free(packetDescriptors);
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
acquire_sem(device->notify);
|
||||
command->transfer.status = device->status;
|
||||
command->transfer.length = device->actual_length;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
|
||||
if (op == B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER) {
|
||||
memcpy(command->isochronous.packet_descriptors,
|
||||
@@ -694,17 +690,14 @@ init_driver()
|
||||
|
||||
gDeviceList = NULL;
|
||||
gDeviceCount = 0;
|
||||
status_t result = benaphore_init(&gDeviceListLock, "usb_raw device list lock");
|
||||
if (result < B_OK) {
|
||||
TRACE((DRIVER_NAME": failed to create device list lock\n"));
|
||||
return result;
|
||||
}
|
||||
mutex_init(&gDeviceListLock, "usb_raw device list lock");
|
||||
|
||||
TRACE((DRIVER_NAME": trying module %s\n", B_USB_MODULE_NAME));
|
||||
result = get_module(B_USB_MODULE_NAME, (module_info **)&gUSBModule);
|
||||
status_t result = get_module(B_USB_MODULE_NAME,
|
||||
(module_info **)&gUSBModule);
|
||||
if (result < B_OK) {
|
||||
TRACE((DRIVER_NAME": getting module failed 0x%08lx\n", result));
|
||||
benaphore_destroy(&gDeviceListLock);
|
||||
mutex_destroy(&gDeviceListLock);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -719,7 +712,7 @@ uninit_driver()
|
||||
{
|
||||
TRACE((DRIVER_NAME": uninit_driver()\n"));
|
||||
gUSBModule->uninstall_notify(DRIVER_NAME);
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
|
||||
if (gDeviceNames) {
|
||||
for (int32 i = 1; gDeviceNames[i]; i++)
|
||||
@@ -728,7 +721,7 @@ uninit_driver()
|
||||
gDeviceNames = NULL;
|
||||
}
|
||||
|
||||
benaphore_destroy(&gDeviceListLock);
|
||||
mutex_destroy(&gDeviceListLock);
|
||||
put_module(B_USB_MODULE_NAME);
|
||||
}
|
||||
|
||||
@@ -751,7 +744,7 @@ publish_devices()
|
||||
|
||||
gDeviceNames[index++] = DEVICE_NAME;
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
raw_device *element = gDeviceList;
|
||||
while (element) {
|
||||
gDeviceNames[index++] = strdup(element->name);
|
||||
@@ -759,7 +752,7 @@ publish_devices()
|
||||
}
|
||||
|
||||
gDeviceNames[index++] = NULL;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return (const char **)gDeviceNames;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ static usb_module_info *gUSBModule = NULL;
|
||||
static disk_device *gDeviceList = NULL;
|
||||
static uint32 gDeviceCount = 0;
|
||||
static uint32 gLunCount = 0;
|
||||
static benaphore gDeviceListLock;
|
||||
static mutex gDeviceListLock;
|
||||
static char **gDeviceNames = NULL;
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ status_t usb_disk_synchronize(device_lun *lun, bool force);
|
||||
void
|
||||
usb_disk_free_device_and_luns(disk_device *device)
|
||||
{
|
||||
benaphore_lock(&device->lock);
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
delete_sem(device->notify);
|
||||
for (uint8 i = 0; i < device->lun_count; i++)
|
||||
free(device->luns[i]);
|
||||
@@ -540,15 +540,11 @@ usb_disk_device_added(usb_device newDevice, void **cookie)
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t result = benaphore_init(&device->lock, "usb_disk device lock");
|
||||
if (result < B_OK) {
|
||||
free(device);
|
||||
return result;
|
||||
}
|
||||
mutex_init(&device->lock, "usb_disk device lock");
|
||||
|
||||
device->notify = create_sem(0, "usb_disk callback notify");
|
||||
if (device->notify < B_OK) {
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
free(device);
|
||||
return device->notify;
|
||||
}
|
||||
@@ -559,6 +555,8 @@ usb_disk_device_added(usb_device newDevice, void **cookie)
|
||||
for (uint8 i = 0; i < device->lun_count; i++)
|
||||
device->luns[i] = NULL;
|
||||
|
||||
status_t result = B_OK;
|
||||
|
||||
TRACE_ALWAYS("device reports a lun count of %d\n", device->lun_count);
|
||||
for (uint8 i = 0; i < device->lun_count; i++) {
|
||||
// create the individual luns present on this device
|
||||
@@ -595,14 +593,14 @@ usb_disk_device_added(usb_device newDevice, void **cookie)
|
||||
return result;
|
||||
}
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
device->link = (void *)gDeviceList;
|
||||
gDeviceList = device;
|
||||
uint32 deviceNumber = gDeviceCount++;
|
||||
gLunCount += device->lun_count;
|
||||
for (uint8 i = 0; i < device->lun_count; i++)
|
||||
sprintf(device->luns[i]->name, DEVICE_NAME, deviceNumber, i);
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
|
||||
TRACE("new device: 0x%08lx\n", (uint32)device);
|
||||
*cookie = (void *)device;
|
||||
@@ -616,7 +614,7 @@ usb_disk_device_removed(void *cookie)
|
||||
TRACE("device_removed(0x%08lx)\n", (uint32)cookie);
|
||||
disk_device *device = (disk_device *)cookie;
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
if (gDeviceList == device) {
|
||||
gDeviceList = (disk_device *)device->link;
|
||||
} else {
|
||||
@@ -633,13 +631,13 @@ usb_disk_device_removed(void *cookie)
|
||||
gLunCount -= device->lun_count;
|
||||
gDeviceCount--;
|
||||
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
device->removed = true;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
if (device->open_count == 0)
|
||||
usb_disk_free_device_and_luns(device);
|
||||
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -741,7 +739,7 @@ usb_disk_open(const char *name, uint32 flags, void **cookie)
|
||||
strcat(rawName, "raw");
|
||||
TRACE("opening raw device %s for %s\n", rawName, name);
|
||||
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
disk_device *device = gDeviceList;
|
||||
while (device) {
|
||||
for (uint8 i = 0; i < device->lun_count; i++) {
|
||||
@@ -753,7 +751,7 @@ usb_disk_open(const char *name, uint32 flags, void **cookie)
|
||||
|
||||
device->open_count++;
|
||||
*cookie = lun;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
@@ -761,7 +759,7 @@ usb_disk_open(const char *name, uint32 flags, void **cookie)
|
||||
device = (disk_device *)device->link;
|
||||
}
|
||||
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -780,7 +778,7 @@ static status_t
|
||||
usb_disk_free(void *cookie)
|
||||
{
|
||||
TRACE("free()\n");
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
|
||||
device_lun *lun = (device_lun *)cookie;
|
||||
disk_device *device = lun->device;
|
||||
@@ -791,7 +789,7 @@ usb_disk_free(void *cookie)
|
||||
usb_disk_free_device_and_luns(device);
|
||||
}
|
||||
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -801,9 +799,9 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
{
|
||||
device_lun *lun = (device_lun *)cookie;
|
||||
disk_device *device = lun->device;
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
if (device->removed) {
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_DEV_NOT_READY;
|
||||
}
|
||||
|
||||
@@ -847,7 +845,7 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
break;
|
||||
}
|
||||
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -861,10 +859,10 @@ usb_disk_read(void *cookie, off_t position, void *buffer, size_t *length)
|
||||
TRACE("read(%lld, %ld)\n", position, *length);
|
||||
device_lun *lun = (device_lun *)cookie;
|
||||
disk_device *device = lun->device;
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
if (device->removed) {
|
||||
*length = 0;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_DEV_NOT_READY;
|
||||
}
|
||||
|
||||
@@ -887,7 +885,7 @@ usb_disk_read(void *cookie, off_t position, void *buffer, size_t *length)
|
||||
length);
|
||||
}
|
||||
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
if (result == B_OK) {
|
||||
TRACE("read successful with %ld bytes\n", *length);
|
||||
return B_OK;
|
||||
@@ -909,10 +907,10 @@ usb_disk_write(void *cookie, off_t position, const void *buffer,
|
||||
TRACE("write(%lld, %ld)\n", position, *length);
|
||||
device_lun *lun = (device_lun *)cookie;
|
||||
disk_device *device = lun->device;
|
||||
benaphore_lock(&device->lock);
|
||||
mutex_lock(&device->lock);
|
||||
if (device->removed) {
|
||||
*length = 0;
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
return B_DEV_NOT_READY;
|
||||
}
|
||||
|
||||
@@ -938,7 +936,7 @@ usb_disk_write(void *cookie, off_t position, const void *buffer,
|
||||
(void *)buffer, length);
|
||||
}
|
||||
|
||||
benaphore_unlock(&device->lock);
|
||||
mutex_unlock(&device->lock);
|
||||
if (result == B_OK) {
|
||||
TRACE("write successful with %ld bytes\n", *length);
|
||||
return B_OK;
|
||||
@@ -979,17 +977,14 @@ init_driver()
|
||||
gDeviceList = NULL;
|
||||
gDeviceCount = 0;
|
||||
gLunCount = 0;
|
||||
status_t result = benaphore_init(&gDeviceListLock, "usb_disk device list lock");
|
||||
if (result < B_OK) {
|
||||
TRACE("failed to create device list lock\n");
|
||||
return result;
|
||||
}
|
||||
mutex_init(&gDeviceListLock, "usb_disk device list lock");
|
||||
|
||||
TRACE("trying module %s\n", B_USB_MODULE_NAME);
|
||||
result = get_module(B_USB_MODULE_NAME, (module_info **)&gUSBModule);
|
||||
status_t result = get_module(B_USB_MODULE_NAME,
|
||||
(module_info **)&gUSBModule);
|
||||
if (result < B_OK) {
|
||||
TRACE_ALWAYS("getting module failed 0x%08lx\n", result);
|
||||
benaphore_destroy(&gDeviceListLock);
|
||||
mutex_destroy(&gDeviceListLock);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1004,7 +999,7 @@ uninit_driver()
|
||||
{
|
||||
TRACE("uninit_driver()\n");
|
||||
gUSBModule->uninstall_notify(DRIVER_NAME);
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
|
||||
if (gDeviceNames) {
|
||||
for (int32 i = 0; gDeviceNames[i]; i++)
|
||||
@@ -1013,7 +1008,7 @@ uninit_driver()
|
||||
gDeviceNames = NULL;
|
||||
}
|
||||
|
||||
benaphore_destroy(&gDeviceListLock);
|
||||
mutex_destroy(&gDeviceListLock);
|
||||
put_module(B_USB_MODULE_NAME);
|
||||
}
|
||||
|
||||
@@ -1034,7 +1029,7 @@ publish_devices()
|
||||
return NULL;
|
||||
|
||||
int32 index = 0;
|
||||
benaphore_lock(&gDeviceListLock);
|
||||
mutex_lock(&gDeviceListLock);
|
||||
disk_device *device = gDeviceList;
|
||||
while (device) {
|
||||
for (uint8 i = 0; i < device->lun_count; i++)
|
||||
@@ -1044,7 +1039,7 @@ publish_devices()
|
||||
}
|
||||
|
||||
gDeviceNames[index++] = NULL;
|
||||
benaphore_unlock(&gDeviceListLock);
|
||||
mutex_unlock(&gDeviceListLock);
|
||||
return (const char **)gDeviceNames;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ typedef struct disk_device_s {
|
||||
usb_device device;
|
||||
bool removed;
|
||||
uint32 open_count;
|
||||
benaphore lock;
|
||||
mutex lock;
|
||||
void * link;
|
||||
|
||||
// device state
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
#define _IMPEXP_KERNEL
|
||||
#endif
|
||||
#include "lock.h"
|
||||
#define benaphore lock
|
||||
#define benaphore_init new_lock
|
||||
#define benaphore_destroy free_lock
|
||||
#define benaphore_lock LOCK
|
||||
#define benaphore_unlock UNLOCK
|
||||
#define mutex lock
|
||||
#define mutex_init new_lock
|
||||
#define mutex_destroy free_lock
|
||||
#define mutex_lock LOCK
|
||||
#define mutex_unlock UNLOCK
|
||||
#endif
|
||||
|
||||
#define DEBUG 1
|
||||
@@ -91,7 +91,7 @@ struct nbd_device {
|
||||
bool valid;
|
||||
bool readonly;
|
||||
struct sockaddr_in server;
|
||||
benaphore ben;
|
||||
mutex ben;
|
||||
vint32 refcnt;
|
||||
uint64 req; /* next ID for requests */
|
||||
int sock;
|
||||
@@ -181,7 +181,7 @@ status_t nbd_alloc_request(struct nbd_device *dev, struct nbd_request_entry **re
|
||||
return err;
|
||||
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -190,7 +190,7 @@ status_t nbd_alloc_request(struct nbd_device *dev, struct nbd_request_entry **re
|
||||
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
err = ENOMEM;
|
||||
r = malloc(sizeof(struct nbd_request_entry) + (w ? 0 : len));
|
||||
@@ -298,7 +298,7 @@ int32 nbd_postoffice(void *arg)
|
||||
|
||||
reason = "lock";
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
@@ -306,7 +306,7 @@ int32 nbd_postoffice(void *arg)
|
||||
err = nbd_dequeue_request(dev, B_BENDIAN_TO_HOST_INT64(reply.handle), &req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
if (!err && !req) {
|
||||
dprintf(DP "nbd_dequeue_rquest found NULL!\n");
|
||||
@@ -331,7 +331,7 @@ int32 nbd_postoffice(void *arg)
|
||||
|
||||
reason = "lock";
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
@@ -342,7 +342,7 @@ int32 nbd_postoffice(void *arg)
|
||||
nbd_free_request(dev, req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -471,7 +471,7 @@ status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) {
|
||||
goto err0;
|
||||
memset(*cookie, 0, sizeof(cookie_t));
|
||||
(*cookie)->dev = dev;
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
goto err1;
|
||||
/* */
|
||||
@@ -484,7 +484,7 @@ status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) {
|
||||
kfd = dev->kludge;
|
||||
dev->kludge = -1;
|
||||
#endif
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
#ifdef MOUNT_KLUDGE
|
||||
if (refcnt == 0) {
|
||||
@@ -499,7 +499,7 @@ status_t nbd_open(const char *name, uint32 flags, cookie_t **cookie) {
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
err1:
|
||||
free(*cookie);
|
||||
err0:
|
||||
@@ -515,7 +515,7 @@ status_t nbd_close(cookie_t *cookie) {
|
||||
#endif
|
||||
PRINT((DP ">%s(%d)\n", __FUNCTION__, WHICH(cookie->dev)));
|
||||
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -525,7 +525,7 @@ status_t nbd_close(cookie_t *cookie) {
|
||||
dev->kludge = -1;
|
||||
#endif
|
||||
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
#ifdef MOUNT_KLUDGE
|
||||
if (kfd > -1) {
|
||||
@@ -540,7 +540,7 @@ status_t nbd_free(cookie_t *cookie) {
|
||||
status_t err;
|
||||
PRINT((DP ">%s(%d)\n", __FUNCTION__, WHICH(cookie->dev)));
|
||||
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
@@ -548,7 +548,7 @@ status_t nbd_free(cookie_t *cookie) {
|
||||
err = nbd_teardown(dev);
|
||||
}
|
||||
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
free(cookie);
|
||||
return err;
|
||||
@@ -625,14 +625,14 @@ status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes
|
||||
goto err0;
|
||||
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
goto err1;
|
||||
|
||||
err = nbd_post_request(dev, req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
if (err)
|
||||
goto err2;
|
||||
@@ -641,7 +641,7 @@ status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes
|
||||
semerr = acquire_sem(req->sem);
|
||||
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if(err)
|
||||
goto err3;
|
||||
|
||||
@@ -652,7 +652,7 @@ status_t nbd_read(cookie_t *cookie, off_t position, void *data, size_t *numbytes
|
||||
nbd_free_request(dev, req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
if (semerr == B_OK) {
|
||||
*numbytes = req->len;
|
||||
@@ -696,7 +696,7 @@ status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *n
|
||||
goto err0;
|
||||
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if (err)
|
||||
goto err1;
|
||||
|
||||
@@ -704,7 +704,7 @@ status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *n
|
||||
err = nbd_post_request(dev, req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
if (err)
|
||||
goto err2;
|
||||
@@ -713,7 +713,7 @@ status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *n
|
||||
semerr = acquire_sem(req->sem);
|
||||
|
||||
//LOCK
|
||||
err = benaphore_lock(&dev->ben);
|
||||
err = mutex_lock(&dev->ben);
|
||||
if(err)
|
||||
goto err3;
|
||||
|
||||
@@ -724,7 +724,7 @@ status_t nbd_write(cookie_t *cookie, off_t position, const void *data, size_t *n
|
||||
nbd_free_request(dev, req);
|
||||
|
||||
//UNLOCK
|
||||
benaphore_unlock(&dev->ben);
|
||||
mutex_unlock(&dev->ben);
|
||||
|
||||
if (semerr == B_OK) {
|
||||
*numbytes = req->len;
|
||||
@@ -801,9 +801,7 @@ init_driver (void)
|
||||
for (i = 0; i < MAX_NBDS; i++) {
|
||||
nbd_devices[i].valid = false;
|
||||
nbd_devices[i].readonly = false;
|
||||
err = benaphore_init(&nbd_devices[i].ben, "nbd lock");
|
||||
if (err < B_OK)
|
||||
return err; // XXX
|
||||
mutex_init(&nbd_devices[i].ben, "nbd lock");
|
||||
nbd_devices[i].refcnt = 0;
|
||||
nbd_devices[i].req = 0LL; /* next ID for requests */
|
||||
nbd_devices[i].sock = -1;
|
||||
@@ -859,7 +857,7 @@ uninit_driver (void)
|
||||
PRINT((DP ">%s()\n", __FUNCTION__));
|
||||
for (i = 0; i < MAX_NBDS; i++) {
|
||||
free(nbd_name[i]);
|
||||
benaphore_destroy(&nbd_devices[i].ben);
|
||||
mutex_destroy(&nbd_devices[i].ben);
|
||||
}
|
||||
err = ksocket_cleanup();
|
||||
/* HACK */
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#define _BEOS_COMPATIBILITY_H_
|
||||
#ifndef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
|
||||
typedef struct benaphore {
|
||||
typedef struct mutex {
|
||||
sem_id sem;
|
||||
int32 count;
|
||||
} benaphore;
|
||||
} mutex;
|
||||
|
||||
|
||||
static inline status_t
|
||||
benaphore_init(benaphore *ben, const char *name)
|
||||
mutex_init(mutex *ben, const char *name)
|
||||
{
|
||||
if (ben == NULL || name == NULL)
|
||||
return B_BAD_VALUE;
|
||||
@@ -24,7 +24,7 @@ benaphore_init(benaphore *ben, const char *name)
|
||||
|
||||
|
||||
static inline void
|
||||
benaphore_destroy(benaphore *ben)
|
||||
mutex_destroy(mutex *ben)
|
||||
{
|
||||
delete_sem(ben->sem);
|
||||
ben->sem = -1;
|
||||
@@ -32,7 +32,7 @@ benaphore_destroy(benaphore *ben)
|
||||
|
||||
|
||||
static inline status_t
|
||||
benaphore_lock(benaphore *ben)
|
||||
mutex_lock(mutex *ben)
|
||||
{
|
||||
if (atomic_add(&ben->count, -1) <= 0)
|
||||
return acquire_sem(ben->sem);
|
||||
@@ -42,7 +42,7 @@ benaphore_lock(benaphore *ben)
|
||||
|
||||
|
||||
static inline status_t
|
||||
benaphore_unlock(benaphore *ben)
|
||||
mutex_unlock(mutex *ben)
|
||||
{
|
||||
if (atomic_add(&ben->count, 1) < 0)
|
||||
return release_sem(ben->sem);
|
||||
|
||||
@@ -55,8 +55,8 @@ SerialDevice::~SerialDevice()
|
||||
if (fBufferArea >= B_OK)
|
||||
delete_area(fBufferArea);
|
||||
|
||||
benaphore_destroy(&fReadLock);
|
||||
benaphore_destroy(&fWriteLock);
|
||||
mutex_destroy(&fReadLock);
|
||||
mutex_destroy(&fWriteLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,8 @@ SerialDevice::Init()
|
||||
{
|
||||
fDoneRead = create_sem(0, "usb_serial:done_read");
|
||||
fDoneWrite = create_sem(0, "usb_serial:done_write");
|
||||
benaphore_init(&fReadLock, "usb_serial:read_lock");
|
||||
benaphore_init(&fWriteLock, "usb_serial:write_lock");
|
||||
mutex_init(&fReadLock, "usb_serial:read_lock");
|
||||
mutex_init(&fWriteLock, "usb_serial:write_lock");
|
||||
|
||||
fReadBufferSize = fWriteBufferSize = ROUNDUP(DEF_BUFFER_SIZE, 16);
|
||||
fInterruptBufferSize = 16;
|
||||
@@ -301,7 +301,7 @@ SerialDevice::Read(char *buffer, size_t *numBytes)
|
||||
return B_DEV_NOT_READY;
|
||||
}
|
||||
|
||||
status_t status = benaphore_lock(&fReadLock);
|
||||
status_t status = mutex_lock(&fReadLock);
|
||||
if (status != B_OK) {
|
||||
TRACE_ALWAYS("read: failed to get read lock\n");
|
||||
*numBytes = 0;
|
||||
@@ -311,14 +311,14 @@ SerialDevice::Read(char *buffer, size_t *numBytes)
|
||||
struct ddrover *ddr = gTTYModule->ddrstart(NULL);
|
||||
if (!ddr) {
|
||||
*numBytes = 0;
|
||||
benaphore_unlock(&fReadLock);
|
||||
mutex_unlock(&fReadLock);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = gTTYModule->ttyread(&fTTYFile, ddr, buffer, numBytes);
|
||||
gTTYModule->ddrdone(ddr);
|
||||
|
||||
benaphore_unlock(&fReadLock);
|
||||
mutex_unlock(&fReadLock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -329,14 +329,14 @@ SerialDevice::Write(const char *buffer, size_t *numBytes)
|
||||
size_t bytesLeft = *numBytes;
|
||||
*numBytes = 0;
|
||||
|
||||
status_t status = benaphore_lock(&fWriteLock);
|
||||
status_t status = mutex_lock(&fWriteLock);
|
||||
if (status != B_OK) {
|
||||
TRACE_ALWAYS("write: failed to get write lock\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
if (fDeviceRemoved) {
|
||||
benaphore_unlock(&fWriteLock);
|
||||
mutex_unlock(&fWriteLock);
|
||||
return B_DEV_NOT_READY;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ SerialDevice::Write(const char *buffer, size_t *numBytes)
|
||||
bytesLeft -= fActualLengthWrite;
|
||||
}
|
||||
|
||||
benaphore_unlock(&fWriteLock);
|
||||
mutex_unlock(&fWriteLock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -483,8 +483,8 @@ SerialDevice::Removed()
|
||||
wait_for_thread(fDeviceThread, &result);
|
||||
fDeviceThread = -1;
|
||||
|
||||
benaphore_lock(&fWriteLock);
|
||||
benaphore_unlock(&fWriteLock);
|
||||
mutex_lock(&fWriteLock);
|
||||
mutex_unlock(&fWriteLock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -130,8 +130,8 @@ static void InterruptCallbackFunction(void *cookie,
|
||||
bool fStopDeviceThread;
|
||||
|
||||
/* device locks to ensure no concurent reads/writes */
|
||||
benaphore fReadLock;
|
||||
benaphore fWriteLock;
|
||||
mutex fReadLock;
|
||||
mutex fWriteLock;
|
||||
};
|
||||
|
||||
#endif // _USB_DEVICE_H_
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include <kernel/lock.h>
|
||||
#include <fs_info.h>
|
||||
#include <NodeMonitor.h>
|
||||
#define lock benaphore
|
||||
#define new_lock benaphore_init
|
||||
#define free_lock benaphore_destroy
|
||||
#define LOCK benaphore_lock
|
||||
#define UNLOCK benaphore_unlock
|
||||
#define lock mutex
|
||||
#define new_lock mutex_init
|
||||
#define free_lock mutex_destroy
|
||||
#define LOCK mutex_lock
|
||||
#define UNLOCK mutex_unlock
|
||||
typedef dev_t nspace_id;
|
||||
|
||||
#else
|
||||
|
||||
@@ -413,9 +413,7 @@ block_io_init_device(void *_data, void **cookie)
|
||||
|
||||
device->node = data->node;
|
||||
|
||||
res = benaphore_init(&device->lock, "block_device_mutex");
|
||||
if (res < 0)
|
||||
goto err2;
|
||||
mutex_init(&device->lock, "block_device_mutex");
|
||||
|
||||
#if 0
|
||||
// construct a identifiable name for S/G pool
|
||||
@@ -458,8 +456,7 @@ block_io_init_device(void *_data, void **cookie)
|
||||
return B_OK;
|
||||
|
||||
err3:
|
||||
benaphore_destroy(&device->lock);
|
||||
err2:
|
||||
mutex_destroy(&device->lock);
|
||||
free(device);
|
||||
err1:
|
||||
return res;
|
||||
@@ -472,7 +469,7 @@ block_io_uninit_device(void *_cookie)
|
||||
block_io_device_info *device = _cookie;
|
||||
|
||||
locked_pool->destroy(device->phys_vecs_pool);
|
||||
benaphore_destroy(&device->lock);
|
||||
mutex_destroy(&device->lock);
|
||||
free(device);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct block_io_device_info {
|
||||
block_device_interface *interface;
|
||||
block_device_cookie *cookie;
|
||||
|
||||
benaphore lock; // used for access to following variables
|
||||
mutex lock; // used for access to following variables
|
||||
uint32 block_size;
|
||||
uint32 ld_block_size;
|
||||
uint64 capacity;
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
// info about pool
|
||||
typedef struct locked_pool {
|
||||
benaphore mutex; // to be used whenever some variable of the first
|
||||
struct mutex mutex; // to be used whenever some variable of the first
|
||||
// block of this structure is read or modified
|
||||
int free_blocks; // # free blocks
|
||||
int num_waiting; // # waiting allocations
|
||||
@@ -83,8 +83,8 @@ typedef struct chunk_header {
|
||||
|
||||
// global list of pools
|
||||
static locked_pool *sLockedPools;
|
||||
// benaphore to protect sLockedPools
|
||||
static benaphore sLockedPoolsLock;
|
||||
// mutex to protect sLockedPools
|
||||
static mutex sLockedPoolsLock;
|
||||
// true, if thread should shut down
|
||||
static bool sShuttingDown;
|
||||
// background thread to enlarge pools
|
||||
@@ -167,7 +167,7 @@ enlarge_pool(locked_pool *pool, int numBlocks)
|
||||
}
|
||||
|
||||
// add new blocks to pool
|
||||
benaphore_lock(&pool->mutex);
|
||||
mutex_lock(&pool->mutex);
|
||||
|
||||
// see remarks about initialising list within chunk
|
||||
*NEXT_PTR(pool, lastBlock) = pool->free_list;
|
||||
@@ -185,7 +185,7 @@ enlarge_pool(locked_pool *pool, int numBlocks)
|
||||
numWaiting = min_c(pool->num_waiting, numBlocks);
|
||||
pool->num_waiting -= numWaiting;
|
||||
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
|
||||
// release threads that wait for empty blocks
|
||||
release_sem_etc(pool->sem, numWaiting, 0);
|
||||
@@ -208,7 +208,7 @@ enlarger_thread(void *arg)
|
||||
|
||||
// protect traversing of global list and
|
||||
// block destroy_pool() to not clean up a pool we are enlarging
|
||||
benaphore_lock(&sLockedPoolsLock);
|
||||
mutex_lock(&sLockedPoolsLock);
|
||||
|
||||
for (pool = sLockedPools; pool; pool = pool->next) {
|
||||
int num_free;
|
||||
@@ -216,9 +216,9 @@ enlarger_thread(void *arg)
|
||||
// this mutex is probably not necessary (at least on 80x86)
|
||||
// but I'm not sure about atomicity of other architectures
|
||||
// (anyway - this routine is not performance critical)
|
||||
benaphore_lock(&pool->mutex);
|
||||
mutex_lock(&pool->mutex);
|
||||
num_free = pool->free_blocks;
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
|
||||
// perhaps blocks got freed meanwhile, i.e. pool is large enough
|
||||
if (num_free > pool->min_free_blocks)
|
||||
@@ -233,7 +233,7 @@ enlarger_thread(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
benaphore_unlock(&sLockedPoolsLock);
|
||||
mutex_unlock(&sLockedPoolsLock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -272,12 +272,12 @@ free_chunks(locked_pool *pool)
|
||||
static status_t
|
||||
init_locked_pool(void)
|
||||
{
|
||||
status_t status = benaphore_init(&sLockedPoolsLock,
|
||||
"locked_pool_global_list");
|
||||
if (status < B_OK)
|
||||
goto err;
|
||||
status_t status;
|
||||
|
||||
status = sEnlargerSemaphore = create_sem(0, "locked_pool_enlarger");
|
||||
mutex_init(&sLockedPoolsLock, "locked_pool_global_list");
|
||||
|
||||
status = sEnlargerSemaphore = create_sem(0,
|
||||
"locked_pool_enlarger");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
@@ -295,8 +295,7 @@ init_locked_pool(void)
|
||||
err3:
|
||||
delete_sem(sEnlargerSemaphore);
|
||||
err2:
|
||||
benaphore_destroy(&sLockedPoolsLock);
|
||||
err:
|
||||
mutex_destroy(&sLockedPoolsLock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -312,7 +311,7 @@ uninit_locked_pool(void)
|
||||
wait_for_thread(sEnlargerThread, NULL);
|
||||
|
||||
delete_sem(sEnlargerSemaphore);
|
||||
benaphore_destroy(&sLockedPoolsLock);
|
||||
mutex_destroy(&sLockedPoolsLock);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -329,7 +328,7 @@ pool_alloc(locked_pool *pool)
|
||||
|
||||
TRACE(("pool_alloc()\n"));
|
||||
|
||||
benaphore_lock(&pool->mutex);
|
||||
mutex_lock(&pool->mutex);
|
||||
|
||||
--pool->free_blocks;
|
||||
|
||||
@@ -344,7 +343,7 @@ pool_alloc(locked_pool *pool)
|
||||
|
||||
TRACE(("new free_list=%p\n", pool->free_list));
|
||||
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -361,21 +360,21 @@ pool_alloc(locked_pool *pool)
|
||||
|
||||
TRACE(("%d waiting allocs\n", pool->num_waiting));
|
||||
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
|
||||
// awake background thread
|
||||
release_sem_etc(sEnlargerSemaphore, 1, B_DO_NOT_RESCHEDULE);
|
||||
// make samphore up-to-date and wait until a block is available
|
||||
acquire_sem(pool->sem);
|
||||
|
||||
benaphore_lock(&pool->mutex);
|
||||
mutex_lock(&pool->mutex);
|
||||
|
||||
TRACE(("continuing alloc (%d free blocks)\n", pool->free_blocks));
|
||||
|
||||
block = pool->free_list;
|
||||
pool->free_list = *NEXT_PTR(pool, block);
|
||||
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -385,7 +384,7 @@ pool_free(locked_pool *pool, void *block)
|
||||
{
|
||||
TRACE(("pool_free()\n"));
|
||||
|
||||
benaphore_lock(&pool->mutex);
|
||||
mutex_lock(&pool->mutex);
|
||||
|
||||
// add to free list
|
||||
*NEXT_PTR(pool, block) = pool->free_list;
|
||||
@@ -398,7 +397,7 @@ pool_free(locked_pool *pool, void *block)
|
||||
|
||||
if (pool->num_waiting == 0) {
|
||||
// if no one is waiting, this is it
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -407,7 +406,7 @@ pool_free(locked_pool *pool, void *block)
|
||||
TRACE(("%d waiting allocs\n", pool->num_waiting));
|
||||
pool->num_waiting--;
|
||||
|
||||
benaphore_unlock(&pool->mutex);
|
||||
mutex_unlock(&pool->mutex);
|
||||
|
||||
// now it is up-to-date and waiting allocations can be continued
|
||||
release_sem(pool->sem);
|
||||
@@ -433,8 +432,7 @@ create_pool(int block_size, int alignment, int next_ofs,
|
||||
|
||||
memset(pool, sizeof(*pool), 0);
|
||||
|
||||
if ((status = benaphore_init(&pool->mutex, "locked_pool")) < 0)
|
||||
goto err;
|
||||
mutex_init(&pool->mutex, "locked_pool");
|
||||
|
||||
if ((status = pool->sem = create_sem(0, "locked_pool")) < 0)
|
||||
goto err1;
|
||||
@@ -480,9 +478,9 @@ create_pool(int block_size, int alignment, int next_ofs,
|
||||
}
|
||||
|
||||
// add to global list, so enlarger thread takes care of pool
|
||||
benaphore_lock(&sLockedPoolsLock);
|
||||
mutex_lock(&sLockedPoolsLock);
|
||||
ADD_DL_LIST_HEAD(pool, sLockedPools, );
|
||||
benaphore_unlock(&sLockedPoolsLock);
|
||||
mutex_unlock(&sLockedPoolsLock);
|
||||
|
||||
return pool;
|
||||
|
||||
@@ -491,8 +489,7 @@ err4:
|
||||
err3:
|
||||
delete_sem(pool->sem);
|
||||
err1:
|
||||
benaphore_destroy(&pool->mutex);
|
||||
err:
|
||||
mutex_destroy(&pool->mutex);
|
||||
free(pool);
|
||||
return NULL;
|
||||
}
|
||||
@@ -505,16 +502,16 @@ destroy_pool(locked_pool *pool)
|
||||
|
||||
// first, remove from global list, so enlarger thread
|
||||
// won't touch this pool anymore
|
||||
benaphore_lock(&sLockedPoolsLock);
|
||||
mutex_lock(&sLockedPoolsLock);
|
||||
REMOVE_DL_LIST(pool, sLockedPools, );
|
||||
benaphore_unlock(&sLockedPoolsLock);
|
||||
mutex_unlock(&sLockedPoolsLock);
|
||||
|
||||
// then cleanup pool
|
||||
free_chunks(pool);
|
||||
|
||||
free(pool->name);
|
||||
delete_sem(pool->sem);
|
||||
benaphore_destroy(&pool->mutex);
|
||||
mutex_destroy(&pool->mutex);
|
||||
|
||||
free(pool);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef struct scsi_periph_device_info {
|
||||
int32 rw10_enabled; // 10 byte r/w commands supported; access must be atomic
|
||||
int32 next_tag_action; // queuing flag for next r/w command; access must be atomic
|
||||
|
||||
benaphore mutex;
|
||||
mutex mutex;
|
||||
int std_timeout;
|
||||
|
||||
scsi_periph_callbacks *callbacks;
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) benaphore_init(x, prefix)
|
||||
#define DELETE_BEN(x) benaphore_destroy(x)
|
||||
#define ACQUIRE_BEN(x) benaphore_lock(x)
|
||||
#define RELEASE_BEN(x) benaphore_unlock(x)
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ static void arp_timer(struct net_timer *timer, void *data);
|
||||
net_buffer_module_info *gBufferModule;
|
||||
static net_stack_module_info *sStackModule;
|
||||
static hash_table *sCache;
|
||||
static benaphore sCacheLock;
|
||||
static mutex sCacheLock;
|
||||
static bool sIgnoreReplies;
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ arp_update_local(arp_protocol *protocol)
|
||||
static status_t
|
||||
handle_arp_request(net_buffer *buffer, arp_header &header)
|
||||
{
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
|
||||
if (!sIgnoreReplies) {
|
||||
arp_update_entry(header.protocol_sender,
|
||||
@@ -470,7 +470,7 @@ handle_arp_reply(net_buffer *buffer, arp_header &header)
|
||||
if (sIgnoreReplies)
|
||||
return;
|
||||
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
arp_update_entry(header.protocol_sender, (sockaddr_dl *)buffer->source, 0);
|
||||
}
|
||||
|
||||
@@ -562,9 +562,9 @@ arp_timer(struct net_timer *timer, void *data)
|
||||
// the entry has aged so much that we're going to remove it
|
||||
TRACE((" remove ARP entry %p!\n", entry));
|
||||
|
||||
benaphore_lock(&sCacheLock);
|
||||
mutex_lock(&sCacheLock);
|
||||
hash_remove(sCache, entry);
|
||||
benaphore_unlock(&sCacheLock);
|
||||
mutex_unlock(&sCacheLock);
|
||||
|
||||
delete entry;
|
||||
break;
|
||||
@@ -694,7 +694,7 @@ arp_control(const char *subsystem, uint32 function, void *buffer,
|
||||
if (user_memcpy(&control, buffer, sizeof(struct arp_control)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
|
||||
switch (function) {
|
||||
case ARP_SET_ENTRY:
|
||||
@@ -805,14 +805,12 @@ arp_control(const char *subsystem, uint32 function, void *buffer,
|
||||
static status_t
|
||||
arp_init()
|
||||
{
|
||||
status_t status = benaphore_init(&sCacheLock, "arp cache");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
mutex_init(&sCacheLock, "arp cache");
|
||||
|
||||
sCache = hash_init(64, offsetof(struct arp_entry, next),
|
||||
&arp_entry::Compare, &arp_entry::Hash);
|
||||
if (sCache == NULL) {
|
||||
benaphore_destroy(&sCacheLock);
|
||||
mutex_destroy(&sCacheLock);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
@@ -873,7 +871,7 @@ arp_send_data(net_datalink_protocol *_protocol, net_buffer *buffer)
|
||||
{
|
||||
arp_protocol *protocol = (arp_protocol *)_protocol;
|
||||
{
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
|
||||
// Set buffer target and destination address
|
||||
|
||||
@@ -942,7 +940,7 @@ arp_down(net_datalink_protocol *protocol)
|
||||
// remove local ARP entry from the cache
|
||||
|
||||
if (protocol->interface->address != NULL) {
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
|
||||
arp_entry *entry = arp_entry::Lookup(
|
||||
((sockaddr_in *)protocol->interface->address)->sin_addr.s_addr);
|
||||
@@ -988,7 +986,7 @@ arp_control(net_datalink_protocol *_protocol, int32 op, void *argument,
|
||||
// remove previous address from cache
|
||||
// TODO: we should be able to do this (add/remove) in one atomic operation!
|
||||
|
||||
BenaphoreLocker locker(sCacheLock);
|
||||
MutexLocker locker(sCacheLock);
|
||||
|
||||
arp_entry *entry = arp_entry::Lookup(oldAddress);
|
||||
if (entry != NULL) {
|
||||
|
||||
@@ -41,7 +41,7 @@ static const bigtime_t kLinkCheckInterval = 1000000;
|
||||
net_buffer_module_info *gBufferModule;
|
||||
static net_stack_module_info *sStackModule;
|
||||
|
||||
static benaphore sListLock;
|
||||
static mutex sListLock;
|
||||
static DoublyLinkedList<ethernet_device> sCheckList;
|
||||
static sem_id sLinkChangeSemaphore;
|
||||
static thread_id sLinkCheckerThread;
|
||||
@@ -94,7 +94,7 @@ ethernet_link_checker(void *)
|
||||
if (status == B_BAD_SEM_ID)
|
||||
break;
|
||||
|
||||
BenaphoreLocker _(sListLock);
|
||||
MutexLocker _(sListLock);
|
||||
|
||||
if (sCheckList.IsEmpty())
|
||||
break;
|
||||
@@ -188,7 +188,7 @@ ethernet_up(net_device *_device)
|
||||
ioctl(device->fd, ETHER_SET_LINK_STATE_SEM, &sLinkChangeSemaphore,
|
||||
sizeof(sem_id));
|
||||
|
||||
BenaphoreLocker _(&sListLock);
|
||||
MutexLocker _(&sListLock);
|
||||
|
||||
if (sCheckList.IsEmpty()) {
|
||||
// start thread
|
||||
@@ -217,7 +217,7 @@ ethernet_down(net_device *_device)
|
||||
{
|
||||
ethernet_device *device = (ethernet_device *)_device;
|
||||
|
||||
BenaphoreLocker _(sListLock);
|
||||
MutexLocker _(sListLock);
|
||||
|
||||
// if the device is still part of the list, remove it
|
||||
if (device->GetDoublyLinkedListLink()->next != NULL
|
||||
@@ -433,12 +433,7 @@ ethernet_std_ops(int32 op, ...)
|
||||
return sLinkChangeSemaphore;
|
||||
}
|
||||
|
||||
status = benaphore_init(&sListLock, "ethernet devices");
|
||||
if (status < B_OK) {
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
delete_sem(sLinkChangeSemaphore);
|
||||
return status;
|
||||
}
|
||||
mutex_init(&sListLock, "ethernet devices");
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -450,7 +445,7 @@ ethernet_std_ops(int32 op, ...)
|
||||
status_t status;
|
||||
wait_for_thread(sLinkCheckerThread, &status);
|
||||
|
||||
benaphore_destroy(&sListLock);
|
||||
mutex_destroy(&sListLock);
|
||||
put_module(NET_STACK_MODULE_NAME);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -181,16 +181,16 @@ static net_datalink_module_info *sDatalinkModule;
|
||||
static net_socket_module_info *sSocketModule;
|
||||
static int32 sPacketID;
|
||||
static RawSocketList sRawSockets;
|
||||
static benaphore sRawSocketsLock;
|
||||
static benaphore sFragmentLock;
|
||||
static mutex sRawSocketsLock;
|
||||
static mutex sFragmentLock;
|
||||
static hash_table *sFragmentHash;
|
||||
static benaphore sMulticastGroupsLock;
|
||||
static mutex sMulticastGroupsLock;
|
||||
|
||||
typedef MultiHashTable<MulticastStateHash> MulticastState;
|
||||
static MulticastState *sMulticastState;
|
||||
|
||||
static net_protocol_module_info *sReceivingProtocol[256];
|
||||
static benaphore sReceivingProtocolLock;
|
||||
static mutex sReceivingProtocolLock;
|
||||
|
||||
|
||||
static const char *
|
||||
@@ -436,7 +436,7 @@ FragmentPacket::StaleTimer(struct net_timer *timer, void *data)
|
||||
FragmentPacket *packet = (FragmentPacket *)data;
|
||||
TRACE("Assembling FragmentPacket %p timed out!", packet);
|
||||
|
||||
BenaphoreLocker locker(&sFragmentLock);
|
||||
MutexLocker locker(&sFragmentLock);
|
||||
|
||||
hash_remove(sFragmentHash, packet);
|
||||
delete packet;
|
||||
@@ -503,7 +503,7 @@ reassemble_fragments(const ipv4_header &header, net_buffer **_buffer)
|
||||
key.protocol = header.protocol;
|
||||
|
||||
// TODO: Make locking finer grained.
|
||||
BenaphoreLocker locker(&sFragmentLock);
|
||||
MutexLocker locker(&sFragmentLock);
|
||||
|
||||
FragmentPacket *packet = (FragmentPacket *)hash_lookup(sFragmentHash, &key);
|
||||
if (packet == NULL) {
|
||||
@@ -643,7 +643,7 @@ deliver_multicast(net_protocol_module_info *module, net_buffer *buffer,
|
||||
if (module->deliver_data == NULL)
|
||||
return B_OK;
|
||||
|
||||
BenaphoreLocker _(sMulticastGroupsLock);
|
||||
MutexLocker _(sMulticastGroupsLock);
|
||||
|
||||
sockaddr_in *multicastAddr = (sockaddr_in *)buffer->destination;
|
||||
|
||||
@@ -678,7 +678,7 @@ deliver_multicast(net_protocol_module_info *module, net_buffer *buffer,
|
||||
static void
|
||||
raw_receive_data(net_buffer *buffer)
|
||||
{
|
||||
BenaphoreLocker locker(sRawSocketsLock);
|
||||
MutexLocker locker(sRawSocketsLock);
|
||||
|
||||
if (sRawSockets.IsEmpty())
|
||||
return;
|
||||
@@ -718,7 +718,7 @@ fill_sockaddr_in(sockaddr_in *destination, const in_addr &source)
|
||||
status_t
|
||||
IPv4Multicast::JoinGroup(IPv4GroupInterface *state)
|
||||
{
|
||||
BenaphoreLocker _(sMulticastGroupsLock);
|
||||
MutexLocker _(sMulticastGroupsLock);
|
||||
|
||||
sockaddr_in groupAddr;
|
||||
net_interface *intf = state->Interface();
|
||||
@@ -736,7 +736,7 @@ IPv4Multicast::JoinGroup(IPv4GroupInterface *state)
|
||||
status_t
|
||||
IPv4Multicast::LeaveGroup(IPv4GroupInterface *state)
|
||||
{
|
||||
BenaphoreLocker _(sMulticastGroupsLock);
|
||||
MutexLocker _(sMulticastGroupsLock);
|
||||
|
||||
sMulticastState->Remove(state);
|
||||
|
||||
@@ -755,7 +755,7 @@ receiving_protocol(uint8 protocol)
|
||||
if (module != NULL)
|
||||
return module;
|
||||
|
||||
BenaphoreLocker locker(sReceivingProtocolLock);
|
||||
MutexLocker locker(sReceivingProtocolLock);
|
||||
|
||||
module = sReceivingProtocol[protocol];
|
||||
if (module != NULL)
|
||||
@@ -983,7 +983,7 @@ ipv4_open(net_protocol *_protocol)
|
||||
|
||||
protocol->raw = raw;
|
||||
|
||||
BenaphoreLocker locker(sRawSocketsLock);
|
||||
MutexLocker locker(sRawSocketsLock);
|
||||
sRawSockets.Add(raw);
|
||||
return B_OK;
|
||||
}
|
||||
@@ -999,7 +999,7 @@ ipv4_close(net_protocol *_protocol)
|
||||
|
||||
TRACE_SK(protocol, "Close()");
|
||||
|
||||
BenaphoreLocker locker(sRawSocketsLock);
|
||||
MutexLocker locker(sRawSocketsLock);
|
||||
sRawSockets.Remove(raw);
|
||||
delete raw;
|
||||
protocol->raw = NULL;
|
||||
@@ -1584,25 +1584,18 @@ init_ipv4()
|
||||
{
|
||||
sPacketID = (int32)system_time();
|
||||
|
||||
status_t status = benaphore_init(&sRawSocketsLock, "raw sockets");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
mutex_init(&sRawSocketsLock, "raw sockets");
|
||||
mutex_init(&sFragmentLock, "IPv4 Fragments");
|
||||
mutex_init(&sMulticastGroupsLock, "IPv4 multicast groups");
|
||||
mutex_init(&sReceivingProtocolLock, "IPv4 receiving protocols");
|
||||
|
||||
status = benaphore_init(&sFragmentLock, "IPv4 Fragments");
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
|
||||
status = benaphore_init(&sMulticastGroupsLock, "IPv4 multicast groups");
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
status = benaphore_init(&sReceivingProtocolLock, "IPv4 receiving protocols");
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
status_t status;
|
||||
|
||||
sMulticastState = new MulticastState();
|
||||
if (sMulticastState == NULL)
|
||||
if (sMulticastState == NULL) {
|
||||
status = B_NO_MEMORY;
|
||||
goto err4;
|
||||
}
|
||||
|
||||
status = sMulticastState->InitCheck();
|
||||
if (status < B_OK)
|
||||
@@ -1638,13 +1631,10 @@ err6:
|
||||
err5:
|
||||
delete sMulticastState;
|
||||
err4:
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
err3:
|
||||
benaphore_destroy(&sMulticastGroupsLock);
|
||||
err2:
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
err1:
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
mutex_destroy(&sReceivingProtocolLock);
|
||||
mutex_destroy(&sMulticastGroupsLock);
|
||||
mutex_destroy(&sFragmentLock);
|
||||
mutex_destroy(&sRawSocketsLock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1652,7 +1642,7 @@ err1:
|
||||
status_t
|
||||
uninit_ipv4()
|
||||
{
|
||||
benaphore_lock(&sReceivingProtocolLock);
|
||||
mutex_lock(&sReceivingProtocolLock);
|
||||
|
||||
remove_debugger_command("ipv4_multicast", dump_ipv4_multicast);
|
||||
|
||||
@@ -1663,15 +1653,15 @@ uninit_ipv4()
|
||||
}
|
||||
|
||||
gStackModule->unregister_domain(sDomain);
|
||||
benaphore_unlock(&sReceivingProtocolLock);
|
||||
mutex_unlock(&sReceivingProtocolLock);
|
||||
|
||||
delete sMulticastState;
|
||||
hash_uninit(sFragmentHash);
|
||||
|
||||
benaphore_destroy(&sMulticastGroupsLock);
|
||||
benaphore_destroy(&sFragmentLock);
|
||||
benaphore_destroy(&sRawSocketsLock);
|
||||
benaphore_destroy(&sReceivingProtocolLock);
|
||||
mutex_destroy(&sMulticastGroupsLock);
|
||||
mutex_destroy(&sFragmentLock);
|
||||
mutex_destroy(&sRawSocketsLock);
|
||||
mutex_destroy(&sReceivingProtocolLock);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ private:
|
||||
|
||||
typedef OpenHashTable<UdpHashDefinition, false> EndpointTable;
|
||||
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
net_domain *fDomain;
|
||||
uint16 fLastUsedEphemeral;
|
||||
EndpointTable fActiveEndpoints;
|
||||
@@ -226,7 +226,7 @@ public:
|
||||
private:
|
||||
UdpDomainSupport *_GetDomain(net_domain *domain, bool create);
|
||||
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
status_t fStatus;
|
||||
UdpDomainList fDomains;
|
||||
};
|
||||
@@ -248,7 +248,7 @@ UdpDomainSupport::UdpDomainSupport(net_domain *domain)
|
||||
fActiveEndpoints(domain->address_module, kNumHashBuckets),
|
||||
fEndpointCount(0)
|
||||
{
|
||||
benaphore_init(&fLock, "udp domain");
|
||||
mutex_init(&fLock, "udp domain");
|
||||
|
||||
fLastUsedEphemeral = kFirst + rand() % (kLast - kFirst);
|
||||
}
|
||||
@@ -256,16 +256,13 @@ UdpDomainSupport::UdpDomainSupport(net_domain *domain)
|
||||
|
||||
UdpDomainSupport::~UdpDomainSupport()
|
||||
{
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
UdpDomainSupport::InitCheck() const
|
||||
{
|
||||
if (fLock.sem < B_OK)
|
||||
return fLock.sem;
|
||||
|
||||
return fActiveEndpoints.InitCheck();
|
||||
}
|
||||
|
||||
@@ -275,7 +272,7 @@ UdpDomainSupport::DemuxIncomingBuffer(net_buffer *buffer)
|
||||
{
|
||||
// NOTE multicast is delivered directly to the endpoint
|
||||
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (buffer->flags & MSG_BCAST)
|
||||
return _DemuxBroadcast(buffer);
|
||||
@@ -290,7 +287,7 @@ status_t
|
||||
UdpDomainSupport::BindEndpoint(UdpEndpoint *endpoint,
|
||||
const sockaddr *address)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (endpoint->IsActive())
|
||||
return EINVAL;
|
||||
@@ -303,7 +300,7 @@ status_t
|
||||
UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint,
|
||||
const sockaddr *address)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (endpoint->IsActive()) {
|
||||
fActiveEndpoints.Remove(endpoint);
|
||||
@@ -329,7 +326,7 @@ UdpDomainSupport::ConnectEndpoint(UdpEndpoint *endpoint,
|
||||
status_t
|
||||
UdpDomainSupport::UnbindEndpoint(UdpEndpoint *endpoint)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (endpoint->IsActive())
|
||||
fActiveEndpoints.Remove(endpoint);
|
||||
@@ -587,13 +584,14 @@ UdpDomainSupport::_EndpointWithPort(uint16 port) const
|
||||
|
||||
UdpEndpointManager::UdpEndpointManager()
|
||||
{
|
||||
fStatus = benaphore_init(&fLock, "UDP endpoints");
|
||||
mutex_init(&fLock, "UDP endpoints");
|
||||
fStatus = B_OK;
|
||||
}
|
||||
|
||||
|
||||
UdpEndpointManager::~UdpEndpointManager()
|
||||
{
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -633,7 +631,7 @@ UdpEndpointManager::ReceiveData(net_buffer *buffer)
|
||||
UdpDomainSupport *domainSupport = NULL;
|
||||
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
domainSupport = _GetDomain(domain, false);
|
||||
// TODO we don't want to hold to the manager's lock
|
||||
// during the whole RX path, we may not hold an
|
||||
@@ -720,7 +718,7 @@ UdpEndpointManager::Deframe(net_buffer *buffer)
|
||||
UdpDomainSupport *
|
||||
UdpEndpointManager::OpenEndpoint(UdpEndpoint *endpoint)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
UdpDomainSupport *domain = _GetDomain(endpoint->Domain(), true);
|
||||
if (domain)
|
||||
@@ -732,7 +730,7 @@ UdpEndpointManager::OpenEndpoint(UdpEndpoint *endpoint)
|
||||
status_t
|
||||
UdpEndpointManager::FreeEndpoint(UdpDomainSupport *domain)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (domain->Put()) {
|
||||
fDomains.Remove(domain);
|
||||
|
||||
@@ -42,13 +42,12 @@ class UnixAddressManager {
|
||||
public:
|
||||
UnixAddressManager()
|
||||
{
|
||||
fLock.sem = -1;
|
||||
mutex_init(&fLock, "unix address manager");
|
||||
}
|
||||
|
||||
~UnixAddressManager()
|
||||
{
|
||||
if (fLock.sem >= 0)
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
status_t Init()
|
||||
@@ -57,17 +56,17 @@ public:
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return benaphore_init(&fLock, "unix address manager");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
return benaphore_lock(&fLock) == B_OK;
|
||||
return mutex_lock(&fLock) == B_OK;
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
benaphore_unlock(&fLock);
|
||||
mutex_unlock(&fLock);
|
||||
}
|
||||
|
||||
UnixEndpoint* Lookup(const UnixAddress& address) const
|
||||
@@ -107,7 +106,7 @@ public:
|
||||
private:
|
||||
typedef OpenHashTable<UnixAddressHashDefinition, false> EndpointTable;
|
||||
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
EndpointTable fBoundEndpoints;
|
||||
int32 fNextInternalID;
|
||||
};
|
||||
|
||||
@@ -51,7 +51,7 @@ UnixEndpoint::UnixEndpoint(net_socket* socket)
|
||||
{
|
||||
TRACE("[%ld] %p->UnixEndpoint::UnixEndpoint()\n", find_thread(NULL), this);
|
||||
|
||||
fLock.sem = -1;
|
||||
mutex_init(&fLock, "unix endpoint");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@ UnixEndpoint::~UnixEndpoint()
|
||||
{
|
||||
TRACE("[%ld] %p->UnixEndpoint::~UnixEndpoint()\n", find_thread(NULL), this);
|
||||
|
||||
if (fLock.sem >= 0)
|
||||
benaphore_destroy(&fLock);
|
||||
mutex_destroy(&fLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +68,6 @@ UnixEndpoint::Init()
|
||||
{
|
||||
TRACE("[%ld] %p->UnixEndpoint::Init()\n", find_thread(NULL), this);
|
||||
|
||||
status_t error = benaphore_init(&fLock, "unix endpoint");
|
||||
if (error != B_OK)
|
||||
RETURN_ERROR(ENOBUFS);
|
||||
|
||||
RETURN_ERROR(B_OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ public:
|
||||
|
||||
bool Lock()
|
||||
{
|
||||
return benaphore_lock(&fLock) == B_OK;
|
||||
return mutex_lock(&fLock) == B_OK;
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
{
|
||||
benaphore_unlock(&fLock);
|
||||
mutex_unlock(&fLock);
|
||||
}
|
||||
|
||||
status_t Bind(const struct sockaddr *_address);
|
||||
@@ -110,7 +110,7 @@ private:
|
||||
void _StopListening();
|
||||
|
||||
private:
|
||||
benaphore fLock;
|
||||
mutex fLock;
|
||||
UnixAddress fAddress;
|
||||
::HashTableLink<UnixEndpoint> fAddressHashLink;
|
||||
UnixEndpoint* fPeerEndpoint;
|
||||
|
||||
@@ -197,7 +197,7 @@ datalink_control_interface(net_domain_private *domain, int32 option,
|
||||
if (user_memcpy(&request, value, expected) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
BenaphoreLocker _(domain->lock);
|
||||
MutexLocker _(domain->lock);
|
||||
net_interface *interface = NULL;
|
||||
|
||||
if (getByName)
|
||||
@@ -322,7 +322,7 @@ datalink_control(net_domain *_domain, int32 option, void *value,
|
||||
if (user_memcpy(&request, value, sizeof(struct ifreq)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
BenaphoreLocker _(domain->lock);
|
||||
MutexLocker _(domain->lock);
|
||||
|
||||
net_interface *interface = find_interface(domain,
|
||||
request.ifr_name);
|
||||
@@ -410,7 +410,7 @@ datalink_is_local_address(net_domain *_domain, const struct sockaddr *address,
|
||||
if (domain == NULL || address == NULL)
|
||||
return false;
|
||||
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
net_interface *interface = NULL;
|
||||
net_interface *fallback = NULL;
|
||||
@@ -461,7 +461,7 @@ datalink_get_interface_with_address(net_domain *_domain,
|
||||
if (domain == NULL)
|
||||
return NULL;
|
||||
|
||||
BenaphoreLocker _(domain->lock);
|
||||
MutexLocker _(domain->lock);
|
||||
|
||||
net_interface *interface = NULL;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
# define TRACE(x) ;
|
||||
#endif
|
||||
|
||||
static benaphore sDomainLock;
|
||||
static mutex sDomainLock;
|
||||
static list sDomains;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ lookup_domain(int family)
|
||||
net_domain *
|
||||
get_domain(int family)
|
||||
{
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
return lookup_domain(family);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ get_domain(int family)
|
||||
uint32
|
||||
count_domain_interfaces()
|
||||
{
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
|
||||
net_domain_private *domain = NULL;
|
||||
uint32 count = 0;
|
||||
@@ -107,7 +107,7 @@ count_domain_interfaces()
|
||||
status_t
|
||||
list_domain_interfaces(void *_buffer, size_t *bufferSize)
|
||||
{
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
|
||||
UserBuffer buffer(_buffer, *bufferSize);
|
||||
net_domain_private *domain = NULL;
|
||||
@@ -117,7 +117,7 @@ list_domain_interfaces(void *_buffer, size_t *bufferSize)
|
||||
if (domain == NULL)
|
||||
break;
|
||||
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
net_interface *interface = NULL;
|
||||
while (true) {
|
||||
@@ -163,7 +163,7 @@ add_interface_to_domain(net_domain *_domain,
|
||||
if (deviceInterface == NULL)
|
||||
return ENODEV;
|
||||
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
net_interface_private *interface = NULL;
|
||||
status_t status;
|
||||
@@ -214,7 +214,7 @@ domain_interface_control(net_domain_private *domain, int32 option,
|
||||
// lock before the domain lock. This order MUST NOT ever
|
||||
// be reversed under the penalty of deadlock.
|
||||
RecursiveLocker _1(device->rx_lock);
|
||||
BenaphoreLocker _2(domain->lock);
|
||||
MutexLocker _2(domain->lock);
|
||||
|
||||
net_interface *interface = find_interface(domain, name);
|
||||
if (interface != NULL) {
|
||||
@@ -280,7 +280,7 @@ domain_interface_went_down(net_interface *interface)
|
||||
void
|
||||
domain_removed_device_interface(net_device_interface *interface)
|
||||
{
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
|
||||
net_domain_private *domain = NULL;
|
||||
while (true) {
|
||||
@@ -288,7 +288,7 @@ domain_removed_device_interface(net_device_interface *interface)
|
||||
if (domain == NULL)
|
||||
break;
|
||||
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
net_interface_private *priv = find_interface(domain,
|
||||
interface->device->name);
|
||||
@@ -307,7 +307,7 @@ register_domain(int family, const char *name,
|
||||
net_domain **_domain)
|
||||
{
|
||||
TRACE(("register_domain(%d, %s)\n", family, name));
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
|
||||
struct net_domain_private *domain = lookup_domain(family);
|
||||
if (domain != NULL)
|
||||
@@ -317,11 +317,7 @@ register_domain(int family, const char *name,
|
||||
if (domain == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
status_t status = benaphore_init(&domain->lock, name);
|
||||
if (status < B_OK) {
|
||||
delete domain;
|
||||
return status;
|
||||
}
|
||||
mutex_init_etc(&domain->lock, name, MUTEX_FLAG_CLONE_NAME);
|
||||
|
||||
domain->family = family;
|
||||
domain->name = name;
|
||||
@@ -343,7 +339,7 @@ unregister_domain(net_domain *_domain)
|
||||
TRACE(("unregister_domain(%p, %d, %s)\n", _domain, _domain->family, _domain->name));
|
||||
|
||||
net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(sDomainLock);
|
||||
MutexLocker locker(sDomainLock);
|
||||
|
||||
list_remove_item(&sDomains, domain);
|
||||
|
||||
@@ -356,7 +352,7 @@ unregister_domain(net_domain *_domain)
|
||||
delete_interface(interface);
|
||||
}
|
||||
|
||||
benaphore_destroy(&domain->lock);
|
||||
mutex_destroy(&domain->lock);
|
||||
delete domain;
|
||||
return B_OK;
|
||||
}
|
||||
@@ -365,8 +361,7 @@ unregister_domain(net_domain *_domain)
|
||||
status_t
|
||||
init_domains()
|
||||
{
|
||||
if (benaphore_init(&sDomainLock, "net domains") < B_OK)
|
||||
return B_ERROR;
|
||||
mutex_init(&sDomainLock, "net domains");
|
||||
|
||||
list_init_etc(&sDomains, offsetof(struct net_domain_private, link));
|
||||
return B_OK;
|
||||
@@ -376,7 +371,7 @@ init_domains()
|
||||
status_t
|
||||
uninit_domains()
|
||||
{
|
||||
benaphore_destroy(&sDomainLock);
|
||||
mutex_destroy(&sDomainLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ struct net_device_interface;
|
||||
struct net_domain_private : net_domain {
|
||||
struct list_link link;
|
||||
|
||||
benaphore lock;
|
||||
mutex lock;
|
||||
|
||||
RouteList routes;
|
||||
RouteInfoList route_infos;
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
static benaphore sInterfaceLock;
|
||||
static mutex sInterfaceLock;
|
||||
static DeviceInterfaceList sInterfaces;
|
||||
static uint32 sInterfaceIndex;
|
||||
static uint32 sDeviceIndex;
|
||||
@@ -326,7 +326,7 @@ put_interface(struct net_interface_private *interface)
|
||||
{
|
||||
// TODO: reference counting
|
||||
// TODO: better locking scheme
|
||||
benaphore_unlock(&((net_domain_private *)interface->domain)->lock);
|
||||
mutex_unlock(&((net_domain_private *)interface->domain)->lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ struct net_interface_private *
|
||||
get_interface(net_domain *_domain, const char *name)
|
||||
{
|
||||
net_domain_private *domain = (net_domain_private *)_domain;
|
||||
benaphore_lock(&domain->lock);
|
||||
mutex_lock(&domain->lock);
|
||||
|
||||
net_interface_private *interface = NULL;
|
||||
while (true) {
|
||||
@@ -347,7 +347,7 @@ get_interface(net_domain *_domain, const char *name)
|
||||
return interface;
|
||||
}
|
||||
|
||||
benaphore_unlock(&domain->lock);
|
||||
mutex_unlock(&domain->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ get_device_interface_address(net_device_interface *interface, sockaddr *_address
|
||||
uint32
|
||||
count_device_interfaces()
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
DeviceInterfaceList::Iterator iterator = sInterfaces.GetIterator();
|
||||
uint32 count = 0;
|
||||
@@ -400,7 +400,7 @@ count_device_interfaces()
|
||||
status_t
|
||||
list_device_interfaces(void *_buffer, size_t *bufferSize)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
DeviceInterfaceList::Iterator iterator = sInterfaces.GetIterator();
|
||||
UserBuffer buffer(_buffer, *bufferSize);
|
||||
@@ -433,7 +433,7 @@ put_device_interface(struct net_device_interface *interface)
|
||||
return;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
sInterfaces.Remove(interface);
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ put_device_interface(struct net_device_interface *interface)
|
||||
struct net_device_interface *
|
||||
get_device_interface(uint32 index)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
DeviceInterfaceList::Iterator iterator = sInterfaces.GetIterator();
|
||||
|
||||
while (iterator.HasNext()) {
|
||||
@@ -479,7 +479,7 @@ get_device_interface(uint32 index)
|
||||
struct net_device_interface *
|
||||
get_device_interface(const char *name, bool create)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
net_device_interface *interface = find_device_interface(name);
|
||||
if (interface != NULL) {
|
||||
@@ -574,7 +574,7 @@ down_device_interface(net_device_interface *interface)
|
||||
status_t
|
||||
unregister_device_deframer(net_device *device)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -603,7 +603,7 @@ unregister_device_deframer(net_device *device)
|
||||
status_t
|
||||
register_device_deframer(net_device *device, net_deframe_func deframeFunc)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -637,7 +637,7 @@ status_t
|
||||
register_device_handler(struct net_device *device, int32 type,
|
||||
net_receive_func receiveFunc, void *cookie)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -673,7 +673,7 @@ register_device_handler(struct net_device *device, int32 type,
|
||||
status_t
|
||||
unregister_device_handler(struct net_device *device, int32 type)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -706,7 +706,7 @@ register_device_monitor(net_device *device, net_device_monitor *monitor)
|
||||
if (monitor->receive == NULL || monitor->event == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -722,7 +722,7 @@ register_device_monitor(net_device *device, net_device_monitor *monitor)
|
||||
status_t
|
||||
unregister_device_monitor(net_device *device, net_device_monitor *monitor)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// find device interface for this device
|
||||
net_device_interface *interface = find_device_interface(device->name);
|
||||
@@ -765,7 +765,7 @@ device_link_changed(net_device *device)
|
||||
status_t
|
||||
device_removed(net_device *device)
|
||||
{
|
||||
BenaphoreLocker locker(sInterfaceLock);
|
||||
MutexLocker locker(sInterfaceLock);
|
||||
|
||||
// hold a reference to the device interface being removed
|
||||
// so our put_() will (eventually) do the final cleanup
|
||||
@@ -822,8 +822,7 @@ device_enqueue_buffer(net_device *device, net_buffer *buffer)
|
||||
status_t
|
||||
init_interfaces()
|
||||
{
|
||||
if (benaphore_init(&sInterfaceLock, "net interfaces") < B_OK)
|
||||
return B_ERROR;
|
||||
mutex_init(&sInterfaceLock, "net interfaces");
|
||||
|
||||
new (&sInterfaces) DeviceInterfaceList;
|
||||
// static C++ objects are not initialized in the module startup
|
||||
@@ -834,7 +833,7 @@ init_interfaces()
|
||||
status_t
|
||||
uninit_interfaces()
|
||||
{
|
||||
benaphore_destroy(&sInterfaceLock);
|
||||
mutex_destroy(&sInterfaceLock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
static net_buffer_module_info *Buffer() { return &gNetBufferModule; }
|
||||
};
|
||||
|
||||
typedef DatagramSocket<BenaphoreLocking, LocalStackBundle> LocalDatagramSocket;
|
||||
typedef DatagramSocket<MutexLocking, LocalStackBundle> LocalDatagramSocket;
|
||||
|
||||
class LinkProtocol : public net_protocol, public LocalDatagramSocket {
|
||||
public:
|
||||
@@ -82,7 +82,7 @@ LinkProtocol::~LinkProtocol()
|
||||
status_t
|
||||
LinkProtocol::StartMonitoring(const char *deviceName)
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
if (fMonitoredDevice)
|
||||
return B_BUSY;
|
||||
@@ -105,7 +105,7 @@ LinkProtocol::StartMonitoring(const char *deviceName)
|
||||
status_t
|
||||
LinkProtocol::StopMonitoring()
|
||||
{
|
||||
BenaphoreLocker _(fLock);
|
||||
MutexLocker _(fLock);
|
||||
|
||||
// TODO compare our device with the supplied device name?
|
||||
return _Unregister();
|
||||
@@ -148,7 +148,7 @@ LinkProtocol::_MonitorEvent(net_device_monitor *monitor, int32 event)
|
||||
LinkProtocol *protocol = (LinkProtocol *)monitor->cookie;
|
||||
|
||||
if (event == B_DEVICE_GOING_DOWN) {
|
||||
BenaphoreLocker _(protocol->fLock);
|
||||
MutexLocker _(protocol->fLock);
|
||||
|
||||
protocol->_Unregister();
|
||||
if (protocol->_IsEmpty()) {
|
||||
|
||||
@@ -44,7 +44,7 @@ struct net_socket_private : net_socket {
|
||||
struct list connected_children;
|
||||
|
||||
struct select_sync_pool *select_pool;
|
||||
benaphore lock;
|
||||
mutex lock;
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ int socket_setsockopt(net_socket *socket, int level, int option,
|
||||
|
||||
|
||||
struct list sSocketList;
|
||||
benaphore sSocketLock;
|
||||
mutex sSocketLock;
|
||||
|
||||
|
||||
static size_t
|
||||
@@ -103,9 +103,7 @@ create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
||||
socket->type = type;
|
||||
socket->protocol = protocol;
|
||||
|
||||
status_t status = benaphore_init(&socket->lock, "socket");
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
mutex_init(&socket->lock, "socket");
|
||||
|
||||
// set defaults (may be overridden by the protocols)
|
||||
socket->send.buffer_size = 65535;
|
||||
@@ -120,7 +118,7 @@ create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
||||
list_init_etc(&socket->connected_children, offsetof(net_socket_private,
|
||||
link));
|
||||
|
||||
status = get_domain_protocols(socket);
|
||||
status_t status = get_domain_protocols(socket);
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
@@ -128,8 +126,7 @@ create_socket(int family, int type, int protocol, net_socket_private **_socket)
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
benaphore_destroy(&socket->lock);
|
||||
err1:
|
||||
mutex_destroy(&socket->lock);
|
||||
delete socket;
|
||||
return status;
|
||||
}
|
||||
@@ -247,9 +244,9 @@ socket_open(int family, int type, int protocol, net_socket **_socket)
|
||||
|
||||
socket->owner = team_get_current_team_id();
|
||||
|
||||
benaphore_lock(&sSocketLock);
|
||||
mutex_lock(&sSocketLock);
|
||||
list_add_item(&sSocketList, socket);
|
||||
benaphore_unlock(&sSocketLock);
|
||||
mutex_unlock(&sSocketLock);
|
||||
|
||||
*_socket = socket;
|
||||
return B_OK;
|
||||
@@ -413,7 +410,7 @@ socket_receive_data(net_socket *socket, size_t length, uint32 flags,
|
||||
status_t
|
||||
socket_get_next_stat(uint32 *_cookie, int family, struct net_stat *stat)
|
||||
{
|
||||
BenaphoreLocker locker(sSocketLock);
|
||||
MutexLocker locker(sSocketLock);
|
||||
|
||||
net_socket_private *socket = NULL;
|
||||
uint32 cookie = *_cookie;
|
||||
@@ -460,7 +457,7 @@ socket_spawn_pending(net_socket *_parent, net_socket **_socket)
|
||||
{
|
||||
net_socket_private *parent = (net_socket_private *)_parent;
|
||||
|
||||
BenaphoreLocker locker(parent->lock);
|
||||
MutexLocker locker(parent->lock);
|
||||
|
||||
// We actually accept more pending connections to compensate for those
|
||||
// that never complete, and also make sure at least a single connection
|
||||
@@ -501,16 +498,16 @@ socket_delete(net_socket *_socket)
|
||||
if (socket->parent != NULL)
|
||||
panic("socket still has a parent!");
|
||||
|
||||
benaphore_lock(&sSocketLock);
|
||||
mutex_lock(&sSocketLock);
|
||||
list_remove_item(&sSocketList, socket);
|
||||
benaphore_unlock(&sSocketLock);
|
||||
mutex_unlock(&sSocketLock);
|
||||
|
||||
// also delete all children of this socket
|
||||
delete_children(&socket->pending_children);
|
||||
delete_children(&socket->connected_children);
|
||||
|
||||
put_domain_protocols(socket);
|
||||
benaphore_destroy(&socket->lock);
|
||||
mutex_destroy(&socket->lock);
|
||||
delete socket;
|
||||
}
|
||||
|
||||
@@ -520,7 +517,7 @@ socket_dequeue_connected(net_socket *_parent, net_socket **_socket)
|
||||
{
|
||||
net_socket_private *parent = (net_socket_private *)_parent;
|
||||
|
||||
benaphore_lock(&parent->lock);
|
||||
mutex_lock(&parent->lock);
|
||||
|
||||
net_socket_private *socket = (net_socket_private *)list_remove_head_item(
|
||||
&parent->connected_children);
|
||||
@@ -530,14 +527,14 @@ socket_dequeue_connected(net_socket *_parent, net_socket **_socket)
|
||||
*_socket = socket;
|
||||
}
|
||||
|
||||
benaphore_unlock(&parent->lock);
|
||||
mutex_unlock(&parent->lock);
|
||||
|
||||
if (socket == NULL)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
|
||||
benaphore_lock(&sSocketLock);
|
||||
mutex_lock(&sSocketLock);
|
||||
list_add_item(&sSocketList, socket);
|
||||
benaphore_unlock(&sSocketLock);
|
||||
mutex_unlock(&sSocketLock);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -548,7 +545,7 @@ socket_count_connected(net_socket *_parent)
|
||||
{
|
||||
net_socket_private *parent = (net_socket_private *)_parent;
|
||||
|
||||
BenaphoreLocker _(parent->lock);
|
||||
MutexLocker _(parent->lock);
|
||||
|
||||
ssize_t count = 0;
|
||||
void *item = NULL;
|
||||
@@ -570,7 +567,7 @@ socket_set_max_backlog(net_socket *_socket, uint32 backlog)
|
||||
if (backlog > 256)
|
||||
backlog = 256;
|
||||
|
||||
benaphore_lock(&socket->lock);
|
||||
mutex_lock(&socket->lock);
|
||||
|
||||
// first remove the pending connections, then the already connected
|
||||
// ones as needed
|
||||
@@ -590,7 +587,7 @@ socket_set_max_backlog(net_socket *_socket, uint32 backlog)
|
||||
}
|
||||
|
||||
socket->max_backlog = backlog;
|
||||
benaphore_unlock(&socket->lock);
|
||||
mutex_unlock(&socket->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -606,7 +603,7 @@ socket_connected(net_socket *socket)
|
||||
if (parent == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
benaphore_lock(&parent->lock);
|
||||
mutex_lock(&parent->lock);
|
||||
|
||||
list_remove_item(&parent->pending_children, socket);
|
||||
list_add_item(&parent->connected_children, socket);
|
||||
@@ -615,7 +612,7 @@ socket_connected(net_socket *socket)
|
||||
if (parent->select_pool)
|
||||
notify_select_event_pool(parent->select_pool, B_SELECT_READ);
|
||||
|
||||
benaphore_unlock(&parent->lock);
|
||||
mutex_unlock(&parent->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -628,12 +625,12 @@ socket_request_notification(net_socket *_socket, uint8 event, selectsync *sync)
|
||||
{
|
||||
net_socket_private *socket = (net_socket_private *)_socket;
|
||||
|
||||
benaphore_lock(&socket->lock);
|
||||
mutex_lock(&socket->lock);
|
||||
|
||||
status_t status = add_select_sync_pool_entry(&socket->select_pool, sync,
|
||||
event);
|
||||
|
||||
benaphore_unlock(&socket->lock);
|
||||
mutex_unlock(&socket->lock);
|
||||
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
@@ -672,12 +669,12 @@ socket_cancel_notification(net_socket *_socket, uint8 event, selectsync *sync)
|
||||
{
|
||||
net_socket_private *socket = (net_socket_private *)_socket;
|
||||
|
||||
benaphore_lock(&socket->lock);
|
||||
mutex_lock(&socket->lock);
|
||||
|
||||
status_t status = remove_select_sync_pool_entry(&socket->select_pool,
|
||||
sync, event);
|
||||
|
||||
benaphore_unlock(&socket->lock);
|
||||
mutex_unlock(&socket->lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -706,12 +703,12 @@ socket_notify(net_socket *_socket, uint8 event, int32 value)
|
||||
break;
|
||||
}
|
||||
|
||||
benaphore_lock(&socket->lock);
|
||||
mutex_lock(&socket->lock);
|
||||
|
||||
if (notify && socket->select_pool)
|
||||
notify_select_event_pool(socket->select_pool, event);
|
||||
|
||||
benaphore_unlock(&socket->lock);
|
||||
mutex_unlock(&socket->lock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -1421,11 +1418,12 @@ socket_std_ops(int32 op, ...)
|
||||
//module_info *module;
|
||||
//return get_module(NET_STARTER_MODULE_NAME, &module);
|
||||
list_init_etc(&sSocketList, offsetof(net_socket_private, link));
|
||||
return benaphore_init(&sSocketLock, "socket list");
|
||||
mutex_init(&sSocketLock, "socket list");
|
||||
return B_OK;
|
||||
}
|
||||
case B_MODULE_UNINIT:
|
||||
//return put_module(NET_STARTER_MODULE_NAME);
|
||||
benaphore_destroy(&sSocketLock);
|
||||
mutex_destroy(&sSocketLock);
|
||||
return B_OK;
|
||||
|
||||
default:
|
||||
|
||||
@@ -299,7 +299,7 @@ fill_route_entry(route_entry *target, void *_buffer, size_t bufferSize,
|
||||
uint32
|
||||
route_table_size(net_domain_private *domain)
|
||||
{
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
uint32 size = 0;
|
||||
|
||||
RouteList::Iterator iterator = domain->routes.GetIterator();
|
||||
@@ -477,7 +477,7 @@ add_route(struct net_domain *_domain, const struct net_route *newRoute)
|
||||
route->ref_count = 1;
|
||||
|
||||
// TODO: for now...
|
||||
//BenaphoreLocker locker(domain->lock);
|
||||
//MutexLocker locker(domain->lock);
|
||||
|
||||
// Insert the route sorted by completeness of its mask
|
||||
|
||||
@@ -521,7 +521,7 @@ remove_route(struct net_domain *_domain, const struct net_route *removeRoute)
|
||||
removeRoute->flags));
|
||||
|
||||
// TODO: for now...
|
||||
//BenaphoreLocker locker(domain->lock);
|
||||
//MutexLocker locker(domain->lock);
|
||||
|
||||
net_route_private *route = find_route(domain, removeRoute);
|
||||
if (route == NULL)
|
||||
@@ -551,7 +551,7 @@ get_route_information(struct net_domain *_domain, void *value, size_t length)
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
net_route_private *route = find_route(domain, (sockaddr *)&destination);
|
||||
if (route == NULL)
|
||||
@@ -601,7 +601,7 @@ struct net_route *
|
||||
get_route(struct net_domain *_domain, const struct sockaddr *address)
|
||||
{
|
||||
struct net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
return get_route_internal(domain, address);
|
||||
}
|
||||
@@ -612,7 +612,7 @@ get_buffer_route(net_domain *_domain, net_buffer *buffer, net_route **_route)
|
||||
{
|
||||
net_domain_private *domain = (net_domain_private *)_domain;
|
||||
|
||||
BenaphoreLocker _(domain->lock);
|
||||
MutexLocker _(domain->lock);
|
||||
|
||||
net_route *route = get_route_internal(domain, buffer->destination);
|
||||
if (route == NULL)
|
||||
@@ -647,7 +647,7 @@ void
|
||||
put_route(struct net_domain *_domain, net_route *route)
|
||||
{
|
||||
struct net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
put_route_internal(domain, (net_route *)route);
|
||||
}
|
||||
@@ -657,7 +657,7 @@ status_t
|
||||
register_route_info(struct net_domain *_domain, struct net_route_info *info)
|
||||
{
|
||||
struct net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
domain->route_infos.Add(info);
|
||||
info->route = get_route_internal(domain, &info->address);
|
||||
@@ -670,7 +670,7 @@ status_t
|
||||
unregister_route_info(struct net_domain *_domain, struct net_route_info *info)
|
||||
{
|
||||
struct net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
domain->route_infos.Remove(info);
|
||||
if (info->route != NULL)
|
||||
@@ -684,7 +684,7 @@ status_t
|
||||
update_route_info(struct net_domain *_domain, struct net_route_info *info)
|
||||
{
|
||||
struct net_domain_private *domain = (net_domain_private *)_domain;
|
||||
BenaphoreLocker locker(domain->lock);
|
||||
MutexLocker locker(domain->lock);
|
||||
|
||||
put_route_internal(domain, info->route);
|
||||
info->route = get_route_internal(domain, &info->address);
|
||||
|
||||
@@ -99,8 +99,8 @@ struct chain {
|
||||
#define CHAIN_MISSING_MODULE 0x02
|
||||
#define CHAIN_INITIALIZED 0x01
|
||||
|
||||
static benaphore sChainLock;
|
||||
static benaphore sInitializeChainLock;
|
||||
static mutex sChainLock;
|
||||
static mutex sInitializeChainLock;
|
||||
static hash_table *sProtocolChains;
|
||||
static hash_table *sDatalinkProtocolChains;
|
||||
static hash_table *sReceivingProtocolChains;
|
||||
@@ -131,7 +131,7 @@ family::Release()
|
||||
return;
|
||||
|
||||
TRACE(("family %d unused, uninit chains\n", type));
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
struct chain *chain = NULL;
|
||||
while (true) {
|
||||
@@ -233,8 +233,8 @@ chain::Acquire()
|
||||
}
|
||||
|
||||
while ((flags & CHAIN_INITIALIZED) == 0) {
|
||||
benaphore_lock(&sInitializeChainLock);
|
||||
benaphore_unlock(&sInitializeChainLock);
|
||||
mutex_lock(&sInitializeChainLock);
|
||||
mutex_unlock(&sInitializeChainLock);
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ chain::Acquire()
|
||||
return B_OK;
|
||||
|
||||
TRACE(("initializing chain %d.%d.%d\n", family, type, protocol));
|
||||
BenaphoreLocker locker(&sInitializeChainLock);
|
||||
MutexLocker locker(&sInitializeChainLock);
|
||||
|
||||
for (int32 i = 0; modules[i] != NULL; i++) {
|
||||
if (get_module(modules[i], &infos[i]) < B_OK) {
|
||||
@@ -282,7 +282,7 @@ chain::Uninitialize()
|
||||
return;
|
||||
|
||||
TRACE(("uninit chain %d.%d.%d\n", family, type, protocol));
|
||||
BenaphoreLocker locker(sInitializeChainLock);
|
||||
MutexLocker locker(sInitializeChainLock);
|
||||
|
||||
for (int32 i = 0; modules[i] != NULL; i++) {
|
||||
put_module(modules[i]);
|
||||
@@ -431,7 +431,7 @@ get_domain_protocols(net_socket *socket)
|
||||
struct chain *chain;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sProtocolChains, socket->family, socket->type,
|
||||
socket->type == SOCK_RAW ? 0 : socket->protocol);
|
||||
@@ -484,7 +484,7 @@ put_domain_protocols(net_socket *socket)
|
||||
struct chain *chain;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sProtocolChains, socket->family, socket->type,
|
||||
socket->protocol);
|
||||
@@ -521,7 +521,7 @@ get_domain_datalink_protocols(net_interface *_interface)
|
||||
struct chain *chain;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sDatalinkProtocolChains, interface->domain->family,
|
||||
interface->device_interface->device->type, 0);
|
||||
@@ -572,7 +572,7 @@ put_domain_datalink_protocols(net_interface *_interface)
|
||||
struct chain *chain;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sDatalinkProtocolChains, interface->domain->family,
|
||||
interface->device_interface->device->type, 0);
|
||||
@@ -595,7 +595,7 @@ get_domain_receiving_protocol(net_domain *_domain, uint32 type,
|
||||
|
||||
TRACE(("get_domain_receiving_protocol(family %d, type %lu)\n", domain->family, type));
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sReceivingProtocolChains, domain->family,
|
||||
type, 0);
|
||||
@@ -619,7 +619,7 @@ put_domain_receiving_protocol(net_domain *_domain, uint32 type)
|
||||
struct chain *chain;
|
||||
|
||||
{
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
chain = chain::Lookup(sReceivingProtocolChains, domain->family,
|
||||
type, 0);
|
||||
@@ -640,7 +640,7 @@ register_domain_protocols(int family, int type, int protocol, ...)
|
||||
protocol = 0;
|
||||
}
|
||||
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
struct chain *chain = chain::Lookup(sProtocolChains, family, type, protocol);
|
||||
if (chain != NULL)
|
||||
@@ -664,7 +664,7 @@ status_t
|
||||
register_domain_datalink_protocols(int family, int type, ...)
|
||||
{
|
||||
TRACE(("register_domain_datalink_protocol(%d.%d)\n", family, type));
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
struct chain *chain = chain::Lookup(sDatalinkProtocolChains, family, type, 0);
|
||||
if (chain != NULL)
|
||||
@@ -699,7 +699,7 @@ register_domain_receiving_protocol(int family, int type, const char *moduleName)
|
||||
TRACE(("register_domain_receiving_protocol(%d.%d, %s)\n", family, type,
|
||||
moduleName));
|
||||
|
||||
BenaphoreLocker locker(&sChainLock);
|
||||
MutexLocker locker(&sChainLock);
|
||||
|
||||
struct chain *chain = chain::Lookup(sReceivingProtocolChains, family, type, 0);
|
||||
if (chain != NULL)
|
||||
@@ -753,10 +753,8 @@ init_stack()
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
if (benaphore_init(&sChainLock, "net chains") < B_OK)
|
||||
goto err3;
|
||||
if (benaphore_init(&sInitializeChainLock, "net intialize chains") < B_OK)
|
||||
goto err4;
|
||||
mutex_init(&sChainLock, "net chains");
|
||||
mutex_init(&sInitializeChainLock, "net intialize chains");
|
||||
|
||||
sFamilies = hash_init(10, offsetof(struct family, next),
|
||||
&family::Compare, &family::Hash);
|
||||
@@ -810,10 +808,8 @@ err7:
|
||||
err6:
|
||||
hash_uninit(sFamilies);
|
||||
err5:
|
||||
benaphore_destroy(&sInitializeChainLock);
|
||||
err4:
|
||||
benaphore_destroy(&sChainLock);
|
||||
err3:
|
||||
mutex_destroy(&sInitializeChainLock);
|
||||
mutex_destroy(&sChainLock);
|
||||
uninit_timers();
|
||||
err2:
|
||||
uninit_interfaces();
|
||||
@@ -832,8 +828,8 @@ uninit_stack()
|
||||
uninit_interfaces();
|
||||
uninit_domains();
|
||||
|
||||
benaphore_destroy(&sChainLock);
|
||||
benaphore_destroy(&sInitializeChainLock);
|
||||
mutex_destroy(&sChainLock);
|
||||
mutex_destroy(&sInitializeChainLock);
|
||||
|
||||
// remove chains and families
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
static struct list sTimers;
|
||||
static benaphore sTimerLock;
|
||||
static mutex sTimerLock;
|
||||
static sem_id sTimerWaitSem;
|
||||
static thread_id sTimerThread;
|
||||
static bigtime_t sTimerTimeout;
|
||||
@@ -207,13 +207,13 @@ Fifo::EnqueueAndNotify(net_buffer *_buffer, net_socket *socket, uint8 event)
|
||||
|
||||
|
||||
status_t
|
||||
Fifo::Wait(benaphore *lock, bigtime_t timeout)
|
||||
Fifo::Wait(mutex *lock, bigtime_t timeout)
|
||||
{
|
||||
waiting++;
|
||||
benaphore_unlock(lock);
|
||||
mutex_unlock(lock);
|
||||
status_t status = acquire_sem_etc(notify, 1,
|
||||
B_CAN_INTERRUPT | B_ABSOLUTE_TIMEOUT, timeout);
|
||||
benaphore_lock(lock);
|
||||
mutex_lock(lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -258,13 +258,11 @@ Fifo::WakeAll()
|
||||
status_t
|
||||
init_fifo(net_fifo *fifo, const char *name, size_t maxBytes)
|
||||
{
|
||||
status_t status = benaphore_init(&fifo->lock, name);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
mutex_init_etc(&fifo->lock, name, MUTEX_FLAG_CLONE_NAME);
|
||||
|
||||
status = base_fifo_init(fifo, name, maxBytes);
|
||||
status_t status = base_fifo_init(fifo, name, maxBytes);
|
||||
if (status < B_OK)
|
||||
benaphore_destroy(&fifo->lock);
|
||||
mutex_destroy(&fifo->lock);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -275,7 +273,7 @@ uninit_fifo(net_fifo *fifo)
|
||||
{
|
||||
clear_fifo(fifo);
|
||||
|
||||
benaphore_destroy(&fifo->lock);
|
||||
mutex_destroy(&fifo->lock);
|
||||
delete_sem(fifo->notify);
|
||||
}
|
||||
|
||||
@@ -283,7 +281,7 @@ uninit_fifo(net_fifo *fifo)
|
||||
status_t
|
||||
fifo_enqueue_buffer(net_fifo *fifo, net_buffer *buffer)
|
||||
{
|
||||
BenaphoreLocker locker(fifo->lock);
|
||||
MutexLocker locker(fifo->lock);
|
||||
return base_fifo_enqueue_buffer(fifo, buffer);
|
||||
}
|
||||
|
||||
@@ -302,7 +300,7 @@ ssize_t
|
||||
fifo_dequeue_buffer(net_fifo *fifo, uint32 flags, bigtime_t timeout,
|
||||
net_buffer **_buffer)
|
||||
{
|
||||
BenaphoreLocker locker(fifo->lock);
|
||||
MutexLocker locker(fifo->lock);
|
||||
bool dontWait = (flags & MSG_DONTWAIT) != 0 || timeout == 0;
|
||||
status_t status;
|
||||
|
||||
@@ -356,7 +354,7 @@ fifo_dequeue_buffer(net_fifo *fifo, uint32 flags, bigtime_t timeout,
|
||||
status_t
|
||||
clear_fifo(net_fifo *fifo)
|
||||
{
|
||||
BenaphoreLocker locker(fifo->lock);
|
||||
MutexLocker locker(fifo->lock);
|
||||
return base_fifo_clear(fifo);
|
||||
}
|
||||
|
||||
@@ -369,7 +367,7 @@ fifo_socket_enqueue_buffer(net_fifo *fifo, net_socket *socket, uint8 event,
|
||||
if (buffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
BenaphoreLocker locker(fifo->lock);
|
||||
MutexLocker locker(fifo->lock);
|
||||
|
||||
status_t status = base_fifo_enqueue_buffer(fifo, buffer);
|
||||
if (status < B_OK)
|
||||
@@ -394,7 +392,7 @@ timer_thread(void * /*data*/)
|
||||
|
||||
if (status == B_TIMED_OUT || status == B_OK) {
|
||||
// scan timers for new timeout and/or execute a timer
|
||||
if (benaphore_lock(&sTimerLock) < B_OK)
|
||||
if (mutex_lock(&sTimerLock) < B_OK)
|
||||
return B_OK;
|
||||
|
||||
struct net_timer *timer = NULL;
|
||||
@@ -408,9 +406,9 @@ timer_thread(void * /*data*/)
|
||||
list_remove_item(&sTimers, timer);
|
||||
timer->due = -1;
|
||||
|
||||
benaphore_unlock(&sTimerLock);
|
||||
mutex_unlock(&sTimerLock);
|
||||
timer->hook(timer, timer->data);
|
||||
benaphore_lock(&sTimerLock);
|
||||
mutex_lock(&sTimerLock);
|
||||
|
||||
timer = NULL;
|
||||
// restart scanning as we unlocked the list
|
||||
@@ -422,7 +420,7 @@ timer_thread(void * /*data*/)
|
||||
}
|
||||
|
||||
sTimerTimeout = timeout;
|
||||
benaphore_unlock(&sTimerLock);
|
||||
mutex_unlock(&sTimerLock);
|
||||
}
|
||||
|
||||
status = acquire_sem_etc(sTimerWaitSem, 1, B_ABSOLUTE_TIMEOUT, timeout);
|
||||
@@ -462,7 +460,7 @@ init_timer(net_timer *timer, net_timer_func hook, void *data)
|
||||
void
|
||||
set_timer(net_timer *timer, bigtime_t delay)
|
||||
{
|
||||
BenaphoreLocker locker(sTimerLock);
|
||||
MutexLocker locker(sTimerLock);
|
||||
|
||||
if (timer->due > 0 && delay < 0) {
|
||||
// this timer is scheduled, cancel it
|
||||
@@ -487,7 +485,7 @@ set_timer(net_timer *timer, bigtime_t delay)
|
||||
bool
|
||||
cancel_timer(struct net_timer *timer)
|
||||
{
|
||||
BenaphoreLocker locker(sTimerLock);
|
||||
MutexLocker locker(sTimerLock);
|
||||
|
||||
if (timer->due <= 0)
|
||||
return false;
|
||||
@@ -531,9 +529,8 @@ init_timers(void)
|
||||
list_init(&sTimers);
|
||||
sTimerTimeout = B_INFINITE_TIMEOUT;
|
||||
|
||||
status_t status = benaphore_init(&sTimerLock, "net timer");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
status_t status = B_OK;
|
||||
mutex_init(&sTimerLock, "net timer");
|
||||
|
||||
sTimerWaitSem = create_sem(0, "net timer wait");
|
||||
if (sTimerWaitSem < B_OK) {
|
||||
@@ -554,7 +551,7 @@ init_timers(void)
|
||||
return resume_thread(sTimerThread);
|
||||
|
||||
err1:
|
||||
benaphore_destroy(&sTimerLock);
|
||||
mutex_destroy(&sTimerLock);
|
||||
err2:
|
||||
delete_sem(sTimerWaitSem);
|
||||
return status;
|
||||
@@ -564,7 +561,7 @@ err2:
|
||||
void
|
||||
uninit_timers(void)
|
||||
{
|
||||
benaphore_destroy(&sTimerLock);
|
||||
mutex_destroy(&sTimerLock);
|
||||
delete_sem(sTimerWaitSem);
|
||||
|
||||
status_t status;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
status_t Enqueue(net_buffer *buffer);
|
||||
status_t EnqueueAndNotify(net_buffer *_buffer, net_socket *socket, uint8 event);
|
||||
status_t Wait(benaphore *lock, bigtime_t timeout);
|
||||
status_t Wait(mutex *lock, bigtime_t timeout);
|
||||
net_buffer *Dequeue(bool clone);
|
||||
status_t Clear();
|
||||
|
||||
|
||||
@@ -348,17 +348,17 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
if (user_memcpy(&cookie, buffer, sizeof(uint32)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
benaphore_lock(&gNodeLock);
|
||||
mutex_lock(&gNodeLock);
|
||||
node = device_manager_find_device(gRootNode, cookie);
|
||||
if (!node) {
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
child = (device_node_info *)list_get_next_item(&node->children, NULL);
|
||||
if (child)
|
||||
cookie = child->internal_id;
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
|
||||
if (!child)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
@@ -383,16 +383,16 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
if (user_memcpy(&cookie, buffer, sizeof(uint32)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
benaphore_lock(&gNodeLock);
|
||||
mutex_lock(&gNodeLock);
|
||||
node = device_manager_find_device(gRootNode, cookie);
|
||||
if (!node) {
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
child = (device_node_info *)list_get_next_item(&node->parent->children, node);
|
||||
if (child)
|
||||
cookie = child->internal_id;
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
|
||||
if (!child)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
@@ -416,10 +416,10 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
if (user_memcpy(&attr, buffer, sizeof(struct dev_attr)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
benaphore_lock(&gNodeLock);
|
||||
mutex_lock(&gNodeLock);
|
||||
node = device_manager_find_device(gRootNode, attr.node_cookie);
|
||||
if (!node) {
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
for (attr_info = node->attributes; attr.cookie > i && attr_info != NULL; attr_info = attr_info->next) {
|
||||
@@ -427,7 +427,7 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
}
|
||||
|
||||
if (!attr_info) {
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ control_device_manager(const char* subsystem, uint32 function, void* buffer,
|
||||
break;*/
|
||||
}
|
||||
|
||||
benaphore_unlock(&gNodeLock);
|
||||
mutex_unlock(&gNodeLock);
|
||||
|
||||
// copy back to user space
|
||||
return user_memcpy(buffer, &attr, sizeof(struct dev_attr));
|
||||
|
||||
@@ -126,36 +126,6 @@ recursive_lock_unlock(recursive_lock *lock)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
benaphore_init(benaphore *ben, const char *name)
|
||||
{
|
||||
if (ben == NULL || name == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
ben->count = 1;
|
||||
#ifdef KDEBUG
|
||||
ben->sem = create_sem(1, name);
|
||||
#else
|
||||
ben->sem = create_sem(0, name);
|
||||
#endif
|
||||
if (ben->sem >= B_OK)
|
||||
return B_OK;
|
||||
|
||||
return ben->sem;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
benaphore_destroy(benaphore *ben)
|
||||
{
|
||||
delete_sem(ben->sem);
|
||||
ben->sem = -1;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
static status_t
|
||||
rw_lock_wait(rw_lock* lock, bool writer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user