Skip to content

Commit

Permalink
usb: trigger the explore thread when a bus is added
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Commit checker robot <[email protected]>
  • Loading branch information
korli authored and waddlesplash committed Oct 3, 2022
1 parent 547ddb9 commit 3f7abfc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/add-ons/kernel/bus_managers/usb/Stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Stack::Stack()
: fExploreThread(-1),
fFirstExploreDone(false),
fStopThreads(false),
fExploreSem(-1),
fAllocator(NULL),
fObjectIndex(1),
fObjectMaxCount(1024),
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down Expand Up @@ -508,3 +520,10 @@ Stack::UninstallNotify(const char *driverName)

return B_NAME_NOT_FOUND;
}


void
Stack::TriggerExplore()
{
release_sem(fExploreSem);
}
2 changes: 1 addition & 1 deletion src/add-ons/kernel/bus_managers/usb/usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/add-ons/kernel/bus_managers/usb/usb_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ class Stack {
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;
Expand Down

0 comments on commit 3f7abfc

Please sign in to comment.