usb: trigger the explore thread when a bus is added

this helps to find the boot disk, otherwise it can happen that the usb disk driver
misses a bus to explore.

Change-Id: I6983b42cf66f946b4ba9763ec09b6e4a848f2e9a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5712
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jérôme Duval 2022-10-03 18:48:59 +02:00 committed by waddlesplash
parent 547ddb9090
commit 3f7abfc9b5
3 changed files with 27 additions and 6 deletions

View File

@ -20,7 +20,7 @@
Stack::Stack()
: fExploreThread(-1),
fFirstExploreDone(false),
fStopThreads(false),
fExploreSem(-1),
fAllocator(NULL),
fObjectIndex(1),
fObjectMaxCount(1024),
@ -31,6 +31,12 @@ Stack::Stack()
mutex_init(&fStackLock, "usb stack lock");
mutex_init(&fExploreLock, "usb explore lock");
fExploreSem = create_sem(0, "usb explore sem");
if (fExploreSem < B_OK) {
TRACE_ERROR("failed to create semaphore\n");
return;
}
size_t objectArraySize = fObjectMaxCount * sizeof(Object *);
fObjectArray = (Object **)malloc(objectArraySize);
@ -65,7 +71,8 @@ Stack::Stack()
Stack::~Stack()
{
int32 result;
fStopThreads = true;
delete_sem(fExploreSem);
fExploreSem = -1;
wait_for_thread(fExploreThread, &result);
mutex_lock(&fStackLock);
@ -202,10 +209,16 @@ Stack::ExploreThread(void *data)
{
Stack *stack = (Stack *)data;
while (!stack->fStopThreads) {
while (acquire_sem_etc(stack->fExploreSem, 1, B_RELATIVE_TIMEOUT,
USB_DELAY_HUB_EXPLORE) != B_BAD_SEM_ID) {
if (mutex_lock(&stack->fExploreLock) != B_OK)
break;
int32 semCount = 0;
get_sem_count(stack->fExploreSem, &semCount);
if (semCount > 0)
acquire_sem_etc(stack->fExploreSem, semCount, B_RELATIVE_TIMEOUT, 0);
rescan_item *rescanList = NULL;
change_item *changeItem = NULL;
for (int32 i = 0; i < stack->fBusManagers.Count(); i++) {
@ -230,7 +243,6 @@ Stack::ExploreThread(void *data)
stack->fFirstExploreDone = true;
mutex_unlock(&stack->fExploreLock);
stack->RescanDrivers(rescanList);
snooze(USB_DELAY_HUB_EXPLORE);
}
return B_OK;
@ -508,3 +520,10 @@ Stack::UninstallNotify(const char *driverName)
return B_NAME_NOT_FOUND;
}
void
Stack::TriggerExplore()
{
release_sem(fExploreSem);
}

View File

@ -898,7 +898,7 @@ struct usb_module_info_v2 gModuleInfoV2 = {
status_t
usb_added_device(device_node *parent)
{
dprintf("usb_added_device\n");
gUSBStack->TriggerExplore();
return B_OK;
}

View File

@ -165,13 +165,15 @@ public:
usb_id USBID() const { return 0; }
const char * TypeName() const { return "stack"; }
void TriggerExplore();
private:
static int32 ExploreThread(void *data);
Vector<BusManager *> fBusManagers;
thread_id fExploreThread;
bool fFirstExploreDone;
bool fStopThreads;
sem_id fExploreSem;
mutex fStackLock;
mutex fExploreLock;