Improve/fix lazy pipe creation introduced in 19032 based on suggestions by Michael and Marcus.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19034 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Niels Sascha Reedijk 2006-10-09 12:55:10 +00:00
parent ffffd44b12
commit 6177d112d4
2 changed files with 16 additions and 13 deletions

View File

@ -29,7 +29,7 @@ BusManager::BusManager(Stack *stack)
// Set the default pipes to NULL (these will be created when needed)
for (int32 i = 0; i <= USB_SPEED_MAX; i++)
fDefaultPipes[i] = 0;
fDefaultPipes[i] = NULL;
fInitOK = true;
}
@ -40,8 +40,7 @@ BusManager::~BusManager()
Lock();
benaphore_destroy(&fLock);
for (int32 i = 0; i <= USB_SPEED_MAX; i++)
if (fDefaultPipes[i] != 0)
delete fDefaultPipes[i];
delete fDefaultPipes[i];
}
@ -100,7 +99,7 @@ BusManager::AllocateNewDevice(Hub *parent, usb_speed speed)
}
TRACE(("usb BusManager::AllocateNewDevice(): setting device address to %d\n", deviceAddress));
ControlPipe *defaultPipe = GetDefaultPipe(speed);
ControlPipe *defaultPipe = _GetDefaultPipe(speed);
if (!defaultPipe) {
TRACE(("usb BusManager::AllocateNewDevice(): Error getting the default pipe for speed %d\n", (int)speed));
@ -236,16 +235,20 @@ BusManager::NotifyPipeChange(Pipe *pipe, usb_change change)
}
ControlPipe *
BusManager::GetDefaultPipe(usb_speed speed)
BusManager::_GetDefaultPipe(usb_speed speed)
{
if (fDefaultPipes[(int)speed] == 0) {
fDefaultPipes[(int)speed] = new(std::nothrow) ControlPipe(fRootObject,
0, 0, (usb_speed)speed, 8);
if (!fDefaultPipes[(int)speed]) {
if (!Lock())
return NULL;
if (fDefaultPipes[speed] == NULL) {
fDefaultPipes[speed] = new(std::nothrow) ControlPipe(fRootObject,
0, 0, speed, 8);
if (!fDefaultPipes[speed]) {
TRACE_ERROR(("usb BusManager: failed to allocate default pipe\n"));
return 0;
return NULL;
}
}
return fDefaultPipes[(int)speed];
return fDefaultPipes[speed];
}

View File

@ -15,7 +15,7 @@
#include "BeOSCompatibility.h"
#define TRACE_USB
//#define TRACE_USB
#ifdef TRACE_USB
#define TRACE(x) dprintf x
#define TRACE_ERROR(x) dprintf x
@ -182,7 +182,7 @@ protected:
bool fInitOK;
private:
ControlPipe *GetDefaultPipe(usb_speed);
ControlPipe *_GetDefaultPipe(usb_speed);
benaphore fLock;
bool fDeviceMap[128];