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